| 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 | 11 |
| 11 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) | 12 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) |
| 12 #define ENABLE_SYNC_CALL_RESTRICTIONS 1 | 13 #define ENABLE_SYNC_CALL_RESTRICTIONS 1 |
| 13 #else | 14 #else |
| 14 #define ENABLE_SYNC_CALL_RESTRICTIONS 0 | 15 #define ENABLE_SYNC_CALL_RESTRICTIONS 0 |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 class GpuService; | 19 class GpuService; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace views { | 22 namespace views { |
| 22 class ClipboardMus; | 23 class ClipboardMus; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace mojo { | 26 namespace mojo { |
| 26 | 27 |
| 27 // In some processes, sync calls are disallowed. For example, in the browser | 28 // In some processes, sync calls are disallowed. For example, in the browser |
| 28 // process we don't want any sync calls to child processes for performance, | 29 // process we don't want any sync calls to child processes for performance, |
| 29 // security and stability reasons. SyncCallRestrictions helps to enforce such | 30 // security and stability reasons. SyncCallRestrictions helps to enforce such |
| 30 // rules. | 31 // rules. |
| 31 // | 32 // |
| 32 // Before processing a sync call, the bindings call | 33 // Before processing a sync call, the bindings call |
| 33 // SyncCallRestrictions::AssertSyncCallAllowed() to check whether sync calls are | 34 // SyncCallRestrictions::AssertSyncCallAllowed() to check whether sync calls are |
| 34 // allowed. By default, it is determined by the mojo system property | 35 // allowed. By default, it is determined by the mojo system property |
| 35 // MOJO_PROPERTY_SYNC_CALL_ALLOWED. If the default setting says no but you have | 36 // MOJO_PROPERTY_SYNC_CALL_ALLOWED. If the default setting says no but you have |
| 36 // a very compelling reason to disregard that (which should be very very rare), | 37 // a very compelling reason to disregard that (which should be very very rare), |
| 37 // you can override it by constructing a ScopedAllowSyncCall object, which | 38 // you can override it by constructing a ScopedAllowSyncCall object, which |
| 38 // allows making sync calls on the current thread during its lifetime. | 39 // allows making sync calls on the current thread during its lifetime. |
| 39 class SyncCallRestrictions { | 40 class MOJO_CPP_BINDINGS_EXPORT SyncCallRestrictions { |
| 40 public: | 41 public: |
| 41 #if ENABLE_SYNC_CALL_RESTRICTIONS | 42 #if ENABLE_SYNC_CALL_RESTRICTIONS |
| 42 // Checks whether the current thread is allowed to make sync calls, and causes | 43 // Checks whether the current thread is allowed to make sync calls, and causes |
| 43 // a DCHECK if not. | 44 // a DCHECK if not. |
| 44 static void AssertSyncCallAllowed(); | 45 static void AssertSyncCallAllowed(); |
| 45 #else | 46 #else |
| 46 // Inline the empty definitions of functions so that they can be compiled out. | 47 // Inline the empty definitions of functions so that they can be compiled out. |
| 47 static void AssertSyncCallAllowed() {} | 48 static void AssertSyncCallAllowed() {} |
| 48 #endif | 49 #endif |
| 49 | 50 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 86 |
| 86 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSyncCall); | 87 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSyncCall); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncCallRestrictions); | 90 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncCallRestrictions); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 } // namespace mojo | 93 } // namespace mojo |
| 93 | 94 |
| 94 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ | 95 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_CALL_RESTRICTIONS_H_ |
| OLD | NEW |