Chromium Code Reviews| Index: mojo/edk/system/request_context.cc |
| diff --git a/mojo/edk/system/request_context.cc b/mojo/edk/system/request_context.cc |
| index c30d8bb821c501af2d424baac908ef6130b742d4..d3afb569ce885b29e82e33d573eb35358d631529 100644 |
| --- a/mojo/edk/system/request_context.cc |
| +++ b/mojo/edk/system/request_context.cc |
| @@ -18,26 +18,44 @@ base::LazyInstance<base::ThreadLocalPointer<RequestContext>>::Leaky |
| } // namespace |
| -RequestContext::RequestContext() : tls_context_(g_current_context.Pointer()){ |
| +RequestContext::RequestContext(Source source) |
| + : source_(source), tls_context_(g_current_context.Pointer()) { |
| // We allow nested RequestContexts to exist as long as they aren't actually |
| // used for anything. |
| if (!tls_context_->Get()) |
|
yzshen1
2016/03/16 21:53:52
nit: it seems the two tls_context_->Get() (line 25
Ken Rockot(use gerrit already)
2016/03/17 00:15:33
Done
|
| tls_context_->Set(this); |
| + |
| + RequestContext* current_context = tls_context_->Get(); |
|
Anand Mistry (off Chromium)
2016/03/16 23:04:14
There's something very fishy about this code. Why
Ken Rockot(use gerrit already)
2016/03/17 00:15:33
I don't really know how I convinced myself that #4
|
| + outer_source_ = current_context->source_; |
| + if (source != outer_source_) { |
| + // This should only be possible if the outer context is from an external |
| + // request and the inner context is from an API call. |
| + CHECK(source == Source::LOCAL_API_CALL && |
| + outer_source_ == Source::EXTERNAL_PROCESS); |
| + current_context->source_ = source; |
| + } |
| } |
| RequestContext::~RequestContext() { |
| // NOTE: Callbacks invoked by this destructor are allowed to initiate new |
| // EDK requests on this thread, so we need to reset the thread-local context |
| // pointer before calling them. |
| + RequestContext::Source notification_source = outer_source_; |
| if (IsCurrent()) |
| tls_context_->Set(nullptr); |
| + else |
| + tls_context_->Get()->source_ = outer_source_; |
| + |
| + MojoWatchNotificationFlags flags = MOJO_WATCH_NOTIFICATION_FLAG_NONE; |
| + if (notification_source == Source::EXTERNAL_PROCESS) |
| + flags |= MOJO_WATCH_NOTIFICATION_FLAG_EXTERNAL_PROCESS; |
| for (const WatchNotifyFinalizer& watch : |
| watch_notify_finalizers_.container()) { |
| // Establish a new request context for the extent of each callback to ensure |
| // that they don't themselves invoke callbacks while holding a watcher lock. |
| - RequestContext request_context; |
| - watch.watcher->MaybeInvokeCallback(watch.result, watch.state); |
| + RequestContext request_context(notification_source); |
| + watch.watcher->MaybeInvokeCallback(watch.result, watch.state, flags); |
| } |
| for (const scoped_refptr<Watcher>& watcher : |