tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

LayerTreeOwnerTracker.h (2130B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_layers_LayerTreeOwnerTracker_h
      8 #define mozilla_layers_LayerTreeOwnerTracker_h
      9 
     10 #include "base/process.h"   // for base::ProcessId
     11 #include "LayersTypes.h"    // for LayersId
     12 #include "mozilla/Mutex.h"  // for mozilla::Mutex
     13 
     14 #include <functional>
     15 #include <map>
     16 
     17 namespace mozilla {
     18 
     19 namespace dom {
     20 class ContentParent;
     21 }
     22 
     23 namespace layers {
     24 
     25 /**
     26 * A utility class for tracking which content processes should be allowed
     27 * to access which layer trees.
     28 *
     29 * ProcessId's are used to track which content process can access the layer
     30 * tree, and in the case of nested browser's we use the top level content
     31 * processes' ProcessId.
     32 *
     33 * This class is only available in the main process and gpu process. Mappings
     34 * are synced from main process to the gpu process. The actual syncing happens
     35 * in GPUProcessManager, and so this class should not be used directly.
     36 */
     37 class LayerTreeOwnerTracker final {
     38 public:
     39  static void Initialize();
     40  static void Shutdown();
     41  static LayerTreeOwnerTracker* Get();
     42 
     43  /**
     44   * Map aLayersId and aProcessId together so that that process
     45   * can access that layer tree.
     46   */
     47  void Map(LayersId aLayersId, base::ProcessId aProcessId);
     48 
     49  /**
     50   * Remove an existing mapping.
     51   */
     52  void Unmap(LayersId aLayersId, base::ProcessId aProcessId);
     53 
     54  /**
     55   * Checks whether it is okay for aProcessId to access aLayersId.
     56   */
     57  bool IsMapped(LayersId aLayersId, base::ProcessId aProcessId);
     58 
     59  void Iterate(
     60      const std::function<void(LayersId aLayersId, base::ProcessId aProcessId)>&
     61          aCallback);
     62 
     63 private:
     64  LayerTreeOwnerTracker();
     65 
     66  mozilla::Mutex mLayerIdsLock MOZ_UNANNOTATED;
     67  std::map<LayersId, base::ProcessId> mLayerIds;
     68 };
     69 
     70 }  // namespace layers
     71 }  // namespace mozilla
     72 
     73 #endif  // mozilla_layers_LayerTreeOwnerTracker_h