Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=4 ts=8 et 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 "mozilla/Mutex.h" // for mozilla::Mutex
12 :
13 : #include <functional>
14 : #include <map>
15 :
16 : namespace mozilla {
17 :
18 : namespace dom {
19 : class ContentParent;
20 : }
21 :
22 : namespace layers {
23 :
24 : /**
25 : * A utility class for tracking which content processes should be allowed
26 : * to access which layer trees.
27 : *
28 : * ProcessId's are used to track which content process can access the layer
29 : * tree, and in the case of nested browser's we use the top level content
30 : * processes' ProcessId.
31 : *
32 : * This class is only available in the main process and gpu process. Mappings
33 : * are synced from main process to the gpu process. The actual syncing happens
34 : * in GPUProcessManager, and so this class should not be used directly.
35 : */
36 0 : class LayerTreeOwnerTracker final
37 : {
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(uint64_t aLayersId, base::ProcessId aProcessId);
48 :
49 : /**
50 : * Remove an existing mapping.
51 : */
52 : void Unmap(uint64_t aLayersId, base::ProcessId aProcessId);
53 :
54 : /**
55 : * Checks whether it is okay for aProcessId to access aLayersId.
56 : */
57 : bool IsMapped(uint64_t aLayersId, base::ProcessId aProcessId);
58 :
59 : void Iterate(const std::function<void(uint64_t aLayersId, base::ProcessId aProcessId)>& aCallback);
60 :
61 : private:
62 : LayerTreeOwnerTracker();
63 :
64 : mozilla::Mutex mLayerIdsLock;
65 : std::map<uint64_t, base::ProcessId> mLayerIds;
66 : };
67 :
68 : } // namespace layers
69 : } // namespace mozilla
70 :
71 : #endif // mozilla_layers_LayerTreeOwnerTracker_h
|