Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: mojo/edk/system/request_context.h

Issue 1811433002: [mojo-edk] Expose notification source to MojoWatch callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_EDK_SYSTEM_REQUEST_CONTEXT_H_ 5 #ifndef MOJO_EDK_SYSTEM_REQUEST_CONTEXT_H_
6 #define MOJO_EDK_SYSTEM_REQUEST_CONTEXT_H_ 6 #define MOJO_EDK_SYSTEM_REQUEST_CONTEXT_H_
7 7
8 #include "base/containers/stack_container.h" 8 #include "base/containers/stack_container.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "mojo/edk/system/handle_signals_state.h" 10 #include "mojo/edk/system/handle_signals_state.h"
11 #include "mojo/edk/system/system_impl_export.h"
11 #include "mojo/edk/system/watcher.h" 12 #include "mojo/edk/system/watcher.h"
12 13
13 namespace base { 14 namespace base {
14 template<typename T> class ThreadLocalPointer; 15 template<typename T> class ThreadLocalPointer;
15 } 16 }
16 17
17 namespace mojo { 18 namespace mojo {
18 namespace edk { 19 namespace edk {
19 20
20 // A RequestContext is a thread-local object which exists for the duration of 21 // A RequestContext is a thread-local object which exists for the duration of
21 // a single system API call. It is constructed immediately upon EDK entry and 22 // a single system API call. It is constructed immediately upon EDK entry and
22 // destructed immediately before returning to the caller, after any internal 23 // destructed immediately before returning to the caller, after any internal
23 // locks have been released. 24 // locks have been released.
24 // 25 //
25 // NOTE: It is legal to construct a RequestContext while another one already 26 // NOTE: It is legal to construct a RequestContext while another one already
26 // exists on the current thread, but it is not safe to use the nested context 27 // exists on the current thread, but it is not safe to use the nested context
27 // for any reason. Therefore it is important to always use 28 // for any reason. Therefore it is important to always use
28 // |RequestContext::current()| rather than referring to any local instance 29 // |RequestContext::current()| rather than referring to any local instance
29 // directly. 30 // directly.
30 class RequestContext { 31 class MOJO_SYSTEM_IMPL_EXPORT RequestContext {
31 public: 32 public:
33 // Identifies the source of the current stack frame's RequestContext.
34 enum class Source {
35 LOCAL_API_CALL,
36 SYSTEM,
37 };
38
39 // Constructs a RequestContext with a LOCAL_API_CALL Source.
32 RequestContext(); 40 RequestContext();
41
42 explicit RequestContext(Source source);
33 ~RequestContext(); 43 ~RequestContext();
34 44
35 // Returns the current thread-local RequestContext. 45 // Returns the current thread-local RequestContext.
36 static RequestContext* current(); 46 static RequestContext* current();
37 47
48 Source source() const { return source_; }
49
38 // Adds a finalizer to this RequestContext corresponding to a watch callback 50 // Adds a finalizer to this RequestContext corresponding to a watch callback
39 // which should be triggered in response to some handle state change. If 51 // which should be triggered in response to some handle state change. If
40 // the Watcher hasn't been cancelled by the time this RequestContext is 52 // the Watcher hasn't been cancelled by the time this RequestContext is
41 // destroyed, its WatchCallback will be invoked with |result| and |state| 53 // destroyed, its WatchCallback will be invoked with |result| and |state|
42 // arguments. 54 // arguments.
43 void AddWatchNotifyFinalizer(scoped_refptr<Watcher> watcher, 55 void AddWatchNotifyFinalizer(scoped_refptr<Watcher> watcher,
44 MojoResult result, 56 MojoResult result,
45 const HandleSignalsState& state); 57 const HandleSignalsState& state);
46 58
47 // Adds a finalizer to this RequestContext which cancels a watch. 59 // Adds a finalizer to this RequestContext which cancels a watch.
(...skipping 19 matching lines...) Expand all
67 // TODO: We should measure the distribution of # of finalizers typical to 79 // TODO: We should measure the distribution of # of finalizers typical to
68 // any RequestContext and adjust this number accordingly. It's probably 80 // any RequestContext and adjust this number accordingly. It's probably
69 // almost always 1, but 4 seems like a harmless upper bound for now. 81 // almost always 1, but 4 seems like a harmless upper bound for now.
70 static const size_t kStaticWatchFinalizersCapacity = 4; 82 static const size_t kStaticWatchFinalizersCapacity = 4;
71 83
72 using WatchNotifyFinalizerList = 84 using WatchNotifyFinalizerList =
73 base::StackVector<WatchNotifyFinalizer, kStaticWatchFinalizersCapacity>; 85 base::StackVector<WatchNotifyFinalizer, kStaticWatchFinalizersCapacity>;
74 using WatchCancelFinalizerList = 86 using WatchCancelFinalizerList =
75 base::StackVector<scoped_refptr<Watcher>, kStaticWatchFinalizersCapacity>; 87 base::StackVector<scoped_refptr<Watcher>, kStaticWatchFinalizersCapacity>;
76 88
89 Source source_;
Anand Mistry (off Chromium) 2016/03/17 01:53:09 nit: const
Ken Rockot(use gerrit already) 2016/03/17 15:44:29 done
90
77 WatchNotifyFinalizerList watch_notify_finalizers_; 91 WatchNotifyFinalizerList watch_notify_finalizers_;
78 WatchCancelFinalizerList watch_cancel_finalizers_; 92 WatchCancelFinalizerList watch_cancel_finalizers_;
79 93
80 // Pointer to the TLS context. Although this can easily be accessed via the 94 // Pointer to the TLS context. Although this can easily be accessed via the
81 // global LazyInstance, accessing a LazyInstance has a large cost relative to 95 // global LazyInstance, accessing a LazyInstance has a large cost relative to
82 // the rest of this class and its usages. 96 // the rest of this class and its usages.
83 base::ThreadLocalPointer<RequestContext>* tls_context_; 97 base::ThreadLocalPointer<RequestContext>* tls_context_;
84 98
85 DISALLOW_COPY_AND_ASSIGN(RequestContext); 99 DISALLOW_COPY_AND_ASSIGN(RequestContext);
86 }; 100 };
87 101
88 } // namespace edk 102 } // namespace edk
89 } // namespace mojo 103 } // namespace mojo
90 104
91 #endif // MOJO_EDK_SYSTEM_REQUEST_CONTEXT_H_ 105 #endif // MOJO_EDK_SYSTEM_REQUEST_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698