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 #include "mojo/edk/system/request_context.h" | 5 #include "mojo/edk/system/request_context.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace edk { | 12 namespace edk { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 base::LazyInstance<base::ThreadLocalPointer<RequestContext>>::Leaky | 16 base::LazyInstance<base::ThreadLocalPointer<RequestContext>>::Leaky |
17 g_current_context = LAZY_INSTANCE_INITIALIZER; | 17 g_current_context = LAZY_INSTANCE_INITIALIZER; |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 RequestContext::RequestContext() : tls_context_(g_current_context.Pointer()){ | 21 RequestContext::RequestContext() : RequestContext(Source::LOCAL_API_CALL) {} |
22 | |
23 RequestContext::RequestContext(Source source) | |
24 : source_(source), tls_context_(g_current_context.Pointer()) { | |
22 // We allow nested RequestContexts to exist as long as they aren't actually | 25 // We allow nested RequestContexts to exist as long as they aren't actually |
23 // used for anything. | 26 // used for anything. |
24 if (!tls_context_->Get()) | 27 if (!tls_context_->Get()) |
25 tls_context_->Set(this); | 28 tls_context_->Set(this); |
26 } | 29 } |
27 | 30 |
28 RequestContext::~RequestContext() { | 31 RequestContext::~RequestContext() { |
29 // NOTE: Callbacks invoked by this destructor are allowed to initiate new | 32 // NOTE: Callbacks invoked by this destructor are allowed to initiate new |
30 // EDK requests on this thread, so we need to reset the thread-local context | 33 // EDK requests on this thread, so we need to reset the thread-local context |
31 // pointer before calling them. | 34 // pointer before calling them. |
35 RequestContext::Source notification_source = tls_context_->Get()->source(); | |
Anand Mistry (off Chromium)
2016/03/17 01:53:09
I don't think this is what we want. Consider a sta
Ken Rockot(use gerrit already)
2016/03/17 01:56:36
That was the intent. I thought that's what you wer
Ken Rockot(use gerrit already)
2016/03/17 15:44:29
I've updated the destructor.
Do you agree that al
| |
32 if (IsCurrent()) | 36 if (IsCurrent()) |
33 tls_context_->Set(nullptr); | 37 tls_context_->Set(nullptr); |
34 | 38 |
39 MojoWatchNotificationFlags flags = MOJO_WATCH_NOTIFICATION_FLAG_NONE; | |
40 if (notification_source == Source::SYSTEM) | |
41 flags |= MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM; | |
42 | |
35 for (const WatchNotifyFinalizer& watch : | 43 for (const WatchNotifyFinalizer& watch : |
36 watch_notify_finalizers_.container()) { | 44 watch_notify_finalizers_.container()) { |
37 // Establish a new request context for the extent of each callback to ensure | 45 // Establish a new request context for the extent of each callback to ensure |
38 // that they don't themselves invoke callbacks while holding a watcher lock. | 46 // that they don't themselves invoke callbacks while holding a watcher lock. |
39 RequestContext request_context; | 47 RequestContext request_context(notification_source); |
40 watch.watcher->MaybeInvokeCallback(watch.result, watch.state); | 48 watch.watcher->MaybeInvokeCallback(watch.result, watch.state, flags); |
41 } | 49 } |
42 | 50 |
43 for (const scoped_refptr<Watcher>& watcher : | 51 for (const scoped_refptr<Watcher>& watcher : |
44 watch_cancel_finalizers_.container()) | 52 watch_cancel_finalizers_.container()) |
45 watcher->Cancel(); | 53 watcher->Cancel(); |
46 } | 54 } |
47 | 55 |
48 // static | 56 // static |
49 RequestContext* RequestContext::current() { | 57 RequestContext* RequestContext::current() { |
50 DCHECK(g_current_context.Pointer()->Get()); | 58 DCHECK(g_current_context.Pointer()->Get()); |
(...skipping 22 matching lines...) Expand all Loading... | |
73 scoped_refptr<Watcher> watcher, | 81 scoped_refptr<Watcher> watcher, |
74 MojoResult result, | 82 MojoResult result, |
75 const HandleSignalsState& state) | 83 const HandleSignalsState& state) |
76 : watcher(watcher), result(result), state(state) { | 84 : watcher(watcher), result(result), state(state) { |
77 } | 85 } |
78 | 86 |
79 RequestContext::WatchNotifyFinalizer::~WatchNotifyFinalizer() {} | 87 RequestContext::WatchNotifyFinalizer::~WatchNotifyFinalizer() {} |
80 | 88 |
81 } // namespace edk | 89 } // namespace edk |
82 } // namespace mojo | 90 } // namespace mojo |
OLD | NEW |