OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/proxy/resource_reply_thread_registrar.h" | |
6 | |
7 #include "base/message_loop/message_loop_proxy.h" | |
8 #include "ppapi/shared_impl/proxy_lock.h" | |
9 | |
10 namespace ppapi { | |
11 namespace proxy { | |
12 | |
13 ResourceReplyThreadRegistrar::ResourceReplyThreadRegistrar( | |
14 scoped_refptr<base::MessageLoopProxy> default_thread) | |
15 : default_thread_(default_thread) { | |
16 } | |
17 | |
18 ResourceReplyThreadRegistrar::~ResourceReplyThreadRegistrar() { | |
19 } | |
20 | |
21 void ResourceReplyThreadRegistrar::Register( | |
22 PP_Resource resource, | |
23 int32_t sequence_number, | |
24 scoped_refptr<TrackedCallback> reply_thread_hint) { | |
25 ProxyLock::AssertAcquiredDebugOnly(); | |
26 | |
27 // TODO(yzshen): add comments. | |
dmichael (off chromium)
2013/12/11 21:30:36
Would be good to add the comments before checking
yzshen1
2013/12/11 22:22:07
This is an old patchset. Please see the latest one
| |
28 if (!reply_thread_hint || reply_thread_hint->is_blocking()) | |
29 return; | |
30 | |
31 DCHECK(reply_thread_hint->target_loop()); | |
32 scoped_refptr<base::MessageLoopProxy> reply_thread( | |
33 reply_thread_hint->target_loop()->GetMessageLoopProxy()); | |
34 { | |
35 base::AutoLock auto_lock(lock_); | |
36 | |
37 if (reply_thread == default_thread_) | |
38 return; | |
39 | |
40 map_[resource][sequence_number] = reply_thread; | |
41 } | |
42 } | |
43 | |
44 void ResourceReplyThreadRegistrar::Unregister(PP_Resource resource) { | |
45 base::AutoLock auto_lock(lock_); | |
46 map_.erase(resource); | |
47 } | |
48 | |
49 scoped_refptr<base::MessageLoopProxy> | |
50 ResourceReplyThreadRegistrar::GetTargetThread( | |
51 PP_Resource resource, | |
52 int32_t sequence_number) { | |
53 base::AutoLock auto_lock(lock_); | |
54 ResourceMap::iterator resource_iter = map_.find(resource); | |
55 if (resource_iter == map_.end()) | |
56 return default_thread_; | |
57 | |
58 SequenceNumberMap::iterator sequence_number_iter = | |
59 resource_iter->second.find(sequence_number); | |
60 if (sequence_number_iter == resource_iter->second.end()) | |
61 return default_thread_; | |
62 | |
63 scoped_refptr<base::MessageLoopProxy> target = sequence_number_iter->second; | |
64 resource_iter->second.erase(sequence_number_iter); | |
65 return target; | |
66 } | |
67 | |
68 } // namespace proxy | |
69 } // namespace ppapi | |
OLD | NEW |