OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ppapi/proxy/resource_reply_thread_registrar.h" | 5 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "ppapi/shared_impl/proxy_lock.h" | 9 #include "ppapi/shared_impl/proxy_lock.h" |
10 #include "ppapi/shared_impl/tracked_callback.h" | 10 #include "ppapi/shared_impl/tracked_callback.h" |
11 | 11 |
12 namespace ppapi { | 12 namespace ppapi { |
13 namespace proxy { | 13 namespace proxy { |
14 | 14 |
15 ResourceReplyThreadRegistrar::ResourceReplyThreadRegistrar( | 15 ResourceReplyThreadRegistrar::ResourceReplyThreadRegistrar( |
16 scoped_refptr<base::MessageLoopProxy> default_thread) | 16 scoped_refptr<base::MessageLoopProxy> default_thread) |
17 : default_thread_(default_thread) { | 17 : default_thread_(default_thread) { |
18 } | 18 } |
19 | 19 |
20 ResourceReplyThreadRegistrar::~ResourceReplyThreadRegistrar() { | 20 ResourceReplyThreadRegistrar::~ResourceReplyThreadRegistrar() { |
21 } | 21 } |
22 | 22 |
23 void ResourceReplyThreadRegistrar::Register( | 23 void ResourceReplyThreadRegistrar::Register( |
24 PP_Resource resource, | 24 PP_Resource resource, |
25 int32_t sequence_number, | 25 int32_t sequence_number, |
26 scoped_refptr<TrackedCallback> reply_thread_hint) { | 26 scoped_refptr<TrackedCallback> reply_thread_hint) { |
27 ProxyLock::AssertAcquiredDebugOnly(); | 27 ProxyLock::AssertAcquiredDebugOnly(); |
28 | 28 |
29 // Use the default thread if |reply_thread_hint| is NULL or blocking. | 29 // Use the default thread if |reply_thread_hint| is NULL or blocking. |
30 if (!reply_thread_hint || reply_thread_hint->is_blocking()) | 30 if (!reply_thread_hint.get() || reply_thread_hint->is_blocking()) |
31 return; | 31 return; |
32 | 32 |
33 DCHECK(reply_thread_hint->target_loop()); | 33 DCHECK(reply_thread_hint->target_loop()); |
34 scoped_refptr<base::MessageLoopProxy> reply_thread( | 34 scoped_refptr<base::MessageLoopProxy> reply_thread( |
35 reply_thread_hint->target_loop()->GetMessageLoopProxy()); | 35 reply_thread_hint->target_loop()->GetMessageLoopProxy()); |
36 { | 36 { |
37 base::AutoLock auto_lock(lock_); | 37 base::AutoLock auto_lock(lock_); |
38 | 38 |
39 if (reply_thread == default_thread_) | 39 if (reply_thread.get() == default_thread_.get()) |
40 return; | 40 return; |
41 | 41 |
42 map_[resource][sequence_number] = reply_thread; | 42 map_[resource][sequence_number] = reply_thread; |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 void ResourceReplyThreadRegistrar::Unregister(PP_Resource resource) { | 46 void ResourceReplyThreadRegistrar::Unregister(PP_Resource resource) { |
47 base::AutoLock auto_lock(lock_); | 47 base::AutoLock auto_lock(lock_); |
48 map_.erase(resource); | 48 map_.erase(resource); |
49 } | 49 } |
(...skipping 12 matching lines...) Expand all Loading... |
62 if (sequence_number_iter == resource_iter->second.end()) | 62 if (sequence_number_iter == resource_iter->second.end()) |
63 return default_thread_; | 63 return default_thread_; |
64 | 64 |
65 scoped_refptr<base::MessageLoopProxy> target = sequence_number_iter->second; | 65 scoped_refptr<base::MessageLoopProxy> target = sequence_number_iter->second; |
66 resource_iter->second.erase(sequence_number_iter); | 66 resource_iter->second.erase(sequence_number_iter); |
67 return target; | 67 return target; |
68 } | 68 } |
69 | 69 |
70 } // namespace proxy | 70 } // namespace proxy |
71 } // namespace ppapi | 71 } // namespace ppapi |
OLD | NEW |