OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "mojo/public/cpp/bindings/bindings_export.h" | 10 #include "mojo/public/cpp/bindings/bindings_export.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace leveldb { | 26 namespace leveldb { |
27 class LevelDBMojoProxy; | 27 class LevelDBMojoProxy; |
28 } | 28 } |
29 | 29 |
30 namespace prefs { | 30 namespace prefs { |
31 class PersistentPrefStoreClient; | 31 class PersistentPrefStoreClient; |
32 } | 32 } |
33 | 33 |
34 namespace ui { | 34 namespace ui { |
35 class Gpu; | 35 class Gpu; |
| 36 class ServerGpuMemoryBufferManager; |
36 } | 37 } |
37 | 38 |
38 namespace views { | 39 namespace views { |
39 class ClipboardMus; | 40 class ClipboardMus; |
40 } | 41 } |
41 | 42 |
42 namespace mojo { | 43 namespace mojo { |
43 | 44 |
44 // In some processes, sync calls are disallowed. For example, in the browser | 45 // In some processes, sync calls are disallowed. For example, in the browser |
45 // process we don't want any sync calls to child processes for performance, | 46 // process we don't want any sync calls to child processes for performance, |
46 // security and stability reasons. SyncCallRestrictions helps to enforce such | 47 // security and stability reasons. SyncCallRestrictions helps to enforce such |
47 // rules. | 48 // rules. |
48 // | 49 // |
49 // Before processing a sync call, the bindings call | 50 // Before processing a sync call, the bindings call |
50 // SyncCallRestrictions::AssertSyncCallAllowed() to check whether sync calls are | 51 // SyncCallRestrictions::AssertSyncCallAllowed() to check whether sync calls are |
51 // allowed. By default, it is determined by the mojo system property | 52 // allowed. By default, it is determined by the mojo system property |
52 // MOJO_PROPERTY_SYNC_CALL_ALLOWED. If the default setting says no but you have | 53 // MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED. If the default setting says no but you |
53 // a very compelling reason to disregard that (which should be very very rare), | 54 // have a very compelling reason to disregard that (which should be very very |
54 // you can override it by constructing a ScopedAllowSyncCall object, which | 55 // rare), you can override it by constructing a ScopedAllowSyncCall object, |
55 // allows making sync calls on the current thread during its lifetime. | 56 // which allows making sync calls on the current thread during its lifetime. |
56 class MOJO_CPP_BINDINGS_EXPORT SyncCallRestrictions { | 57 class MOJO_CPP_BINDINGS_EXPORT SyncCallRestrictions { |
57 public: | 58 public: |
58 #if ENABLE_SYNC_CALL_RESTRICTIONS | 59 #if ENABLE_SYNC_CALL_RESTRICTIONS |
59 // Checks whether the current thread is allowed to make sync calls, and causes | 60 // Checks whether the current thread is allowed to make sync calls, and causes |
60 // a DCHECK if not. | 61 // a DCHECK if not. |
61 static void AssertSyncCallAllowed(); | 62 static void AssertSyncCallAllowed(); |
62 #else | 63 #else |
63 // Inline the empty definitions of functions so that they can be compiled out. | 64 // Inline the empty dServerGpuMemoryBufferManagerefinitions of functions so |
| 65 // that they can be compiled out. |
64 static void AssertSyncCallAllowed() {} | 66 static void AssertSyncCallAllowed() {} |
65 #endif | 67 #endif |
66 | 68 |
67 private: | 69 private: |
68 // DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to mojo/OWNERS first. | 70 // DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to mojo/OWNERS first. |
69 // BEGIN ALLOWED USAGE. | 71 // BEGIN ALLOWED USAGE. |
70 friend class content::BrowserTestBase; // Test-only. | 72 friend class content::BrowserTestBase; // Test-only. |
71 friend class ui::Gpu; // http://crbug.com/620058 | 73 friend class ui::Gpu; // http://crbug.com/620058 |
| 74 friend class ui::ServerGpuMemoryBufferManager; |
72 // LevelDBMojoProxy makes same-process sync calls from the DB thread. | 75 // LevelDBMojoProxy makes same-process sync calls from the DB thread. |
73 friend class leveldb::LevelDBMojoProxy; | 76 friend class leveldb::LevelDBMojoProxy; |
74 // Pref service connection is sync at startup. | 77 // Pref service connection is sync at startup. |
75 friend class prefs::PersistentPrefStoreClient; | 78 friend class prefs::PersistentPrefStoreClient; |
76 | 79 |
77 // END ALLOWED USAGE. | 80 // END ALLOWED USAGE. |
78 | 81 |
79 // BEGIN USAGE THAT NEEDS TO BE FIXED. | 82 // BEGIN USAGE THAT NEEDS TO BE FIXED. |
80 // In the non-mus case, we called blocking OS functions in the ui::Clipboard | 83 // In the non-mus case, we called blocking OS functions in the ui::Clipboard |
81 // implementation which weren't caught by sync call restrictions. Our blocking | 84 // implementation which weren't caught by sync call restrictions. Our blocking |
(...skipping 30 matching lines...) Expand all Loading... |
112 | 115 |
113 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSyncCall); | 116 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSyncCall); |
114 }; | 117 }; |
115 | 118 |
116 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncCallRestrictions); | 119 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncCallRestrictions); |
117 }; | 120 }; |
118 | 121 |
119 } // namespace mojo | 122 } // namespace mojo |
120 | 123 |
121 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ | 124 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ |
OLD | NEW |