OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/event_router_forwarder.h" | 5 #include "chrome/browser/extensions/event_router_forwarder.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 EventRouterForwarder::EventRouterForwarder() { | 23 EventRouterForwarder::EventRouterForwarder() { |
24 } | 24 } |
25 | 25 |
26 EventRouterForwarder::~EventRouterForwarder() { | 26 EventRouterForwarder::~EventRouterForwarder() { |
27 } | 27 } |
28 | 28 |
29 void EventRouterForwarder::BroadcastEventToRenderers( | 29 void EventRouterForwarder::BroadcastEventToRenderers( |
30 events::HistogramValue histogram_value, | 30 events::HistogramValue histogram_value, |
31 const std::string& event_name, | 31 const std::string& event_name, |
32 scoped_ptr<base::ListValue> event_args, | 32 std::unique_ptr<base::ListValue> event_args, |
33 const GURL& event_url) { | 33 const GURL& event_url) { |
34 HandleEvent(std::string(), histogram_value, event_name, std::move(event_args), | 34 HandleEvent(std::string(), histogram_value, event_name, std::move(event_args), |
35 0, true, event_url); | 35 0, true, event_url); |
36 } | 36 } |
37 | 37 |
38 void EventRouterForwarder::DispatchEventToRenderers( | 38 void EventRouterForwarder::DispatchEventToRenderers( |
39 events::HistogramValue histogram_value, | 39 events::HistogramValue histogram_value, |
40 const std::string& event_name, | 40 const std::string& event_name, |
41 scoped_ptr<base::ListValue> event_args, | 41 std::unique_ptr<base::ListValue> event_args, |
42 void* profile, | 42 void* profile, |
43 bool use_profile_to_restrict_events, | 43 bool use_profile_to_restrict_events, |
44 const GURL& event_url) { | 44 const GURL& event_url) { |
45 if (!profile) | 45 if (!profile) |
46 return; | 46 return; |
47 HandleEvent(std::string(), histogram_value, event_name, std::move(event_args), | 47 HandleEvent(std::string(), histogram_value, event_name, std::move(event_args), |
48 profile, use_profile_to_restrict_events, event_url); | 48 profile, use_profile_to_restrict_events, event_url); |
49 } | 49 } |
50 | 50 |
51 void EventRouterForwarder::BroadcastEventToExtension( | 51 void EventRouterForwarder::BroadcastEventToExtension( |
52 const std::string& extension_id, | 52 const std::string& extension_id, |
53 events::HistogramValue histogram_value, | 53 events::HistogramValue histogram_value, |
54 const std::string& event_name, | 54 const std::string& event_name, |
55 scoped_ptr<base::ListValue> event_args, | 55 std::unique_ptr<base::ListValue> event_args, |
56 const GURL& event_url) { | 56 const GURL& event_url) { |
57 HandleEvent(extension_id, histogram_value, event_name, std::move(event_args), | 57 HandleEvent(extension_id, histogram_value, event_name, std::move(event_args), |
58 0, true, event_url); | 58 0, true, event_url); |
59 } | 59 } |
60 | 60 |
61 void EventRouterForwarder::DispatchEventToExtension( | 61 void EventRouterForwarder::DispatchEventToExtension( |
62 const std::string& extension_id, | 62 const std::string& extension_id, |
63 events::HistogramValue histogram_value, | 63 events::HistogramValue histogram_value, |
64 const std::string& event_name, | 64 const std::string& event_name, |
65 scoped_ptr<base::ListValue> event_args, | 65 std::unique_ptr<base::ListValue> event_args, |
66 void* profile, | 66 void* profile, |
67 bool use_profile_to_restrict_events, | 67 bool use_profile_to_restrict_events, |
68 const GURL& event_url) { | 68 const GURL& event_url) { |
69 if (!profile) | 69 if (!profile) |
70 return; | 70 return; |
71 HandleEvent(extension_id, histogram_value, event_name, std::move(event_args), | 71 HandleEvent(extension_id, histogram_value, event_name, std::move(event_args), |
72 profile, use_profile_to_restrict_events, event_url); | 72 profile, use_profile_to_restrict_events, event_url); |
73 } | 73 } |
74 | 74 |
75 void EventRouterForwarder::HandleEvent(const std::string& extension_id, | 75 void EventRouterForwarder::HandleEvent( |
76 events::HistogramValue histogram_value, | 76 const std::string& extension_id, |
77 const std::string& event_name, | 77 events::HistogramValue histogram_value, |
78 scoped_ptr<base::ListValue> event_args, | 78 const std::string& event_name, |
79 void* profile_ptr, | 79 std::unique_ptr<base::ListValue> event_args, |
80 bool use_profile_to_restrict_events, | 80 void* profile_ptr, |
81 const GURL& event_url) { | 81 bool use_profile_to_restrict_events, |
| 82 const GURL& event_url) { |
82 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 83 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
83 BrowserThread::PostTask( | 84 BrowserThread::PostTask( |
84 BrowserThread::UI, FROM_HERE, | 85 BrowserThread::UI, FROM_HERE, |
85 base::Bind(&EventRouterForwarder::HandleEvent, this, extension_id, | 86 base::Bind(&EventRouterForwarder::HandleEvent, this, extension_id, |
86 histogram_value, event_name, base::Passed(&event_args), | 87 histogram_value, event_name, base::Passed(&event_args), |
87 profile_ptr, use_profile_to_restrict_events, event_url)); | 88 profile_ptr, use_profile_to_restrict_events, event_url)); |
88 return; | 89 return; |
89 } | 90 } |
90 | 91 |
91 if (!g_browser_process || !g_browser_process->profile_manager()) | 92 if (!g_browser_process || !g_browser_process->profile_manager()) |
92 return; | 93 return; |
93 | 94 |
94 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 95 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
95 Profile* profile = NULL; | 96 Profile* profile = NULL; |
96 if (profile_ptr) { | 97 if (profile_ptr) { |
97 if (!profile_manager->IsValidProfile(profile_ptr)) | 98 if (!profile_manager->IsValidProfile(profile_ptr)) |
98 return; | 99 return; |
99 profile = reinterpret_cast<Profile*>(profile_ptr); | 100 profile = reinterpret_cast<Profile*>(profile_ptr); |
100 } | 101 } |
101 if (profile) { | 102 if (profile) { |
102 CallEventRouter(profile, extension_id, histogram_value, event_name, | 103 CallEventRouter(profile, extension_id, histogram_value, event_name, |
103 std::move(event_args), | 104 std::move(event_args), |
104 use_profile_to_restrict_events ? profile : NULL, event_url); | 105 use_profile_to_restrict_events ? profile : NULL, event_url); |
105 } else { | 106 } else { |
106 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 107 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
107 for (size_t i = 0; i < profiles.size(); ++i) { | 108 for (size_t i = 0; i < profiles.size(); ++i) { |
108 scoped_ptr<base::ListValue> per_profile_event_args( | 109 std::unique_ptr<base::ListValue> per_profile_event_args( |
109 event_args->DeepCopy()); | 110 event_args->DeepCopy()); |
110 CallEventRouter(profiles[i], extension_id, histogram_value, event_name, | 111 CallEventRouter(profiles[i], extension_id, histogram_value, event_name, |
111 std::move(per_profile_event_args), | 112 std::move(per_profile_event_args), |
112 use_profile_to_restrict_events ? profiles[i] : NULL, | 113 use_profile_to_restrict_events ? profiles[i] : NULL, |
113 event_url); | 114 event_url); |
114 } | 115 } |
115 } | 116 } |
116 } | 117 } |
117 | 118 |
118 void EventRouterForwarder::CallEventRouter( | 119 void EventRouterForwarder::CallEventRouter( |
119 Profile* profile, | 120 Profile* profile, |
120 const std::string& extension_id, | 121 const std::string& extension_id, |
121 events::HistogramValue histogram_value, | 122 events::HistogramValue histogram_value, |
122 const std::string& event_name, | 123 const std::string& event_name, |
123 scoped_ptr<base::ListValue> event_args, | 124 std::unique_ptr<base::ListValue> event_args, |
124 Profile* restrict_to_profile, | 125 Profile* restrict_to_profile, |
125 const GURL& event_url) { | 126 const GURL& event_url) { |
126 #if defined(OS_CHROMEOS) | 127 #if defined(OS_CHROMEOS) |
127 // Extension does not exist for chromeos login. This needs to be | 128 // Extension does not exist for chromeos login. This needs to be |
128 // removed once we have an extension service for login screen. | 129 // removed once we have an extension service for login screen. |
129 // crosbug.com/12856. | 130 // crosbug.com/12856. |
130 if (!extensions::EventRouter::Get(profile)) | 131 if (!extensions::EventRouter::Get(profile)) |
131 return; | 132 return; |
132 #endif | 133 #endif |
133 | 134 |
134 scoped_ptr<Event> event( | 135 std::unique_ptr<Event> event( |
135 new Event(histogram_value, event_name, std::move(event_args))); | 136 new Event(histogram_value, event_name, std::move(event_args))); |
136 event->restrict_to_browser_context = restrict_to_profile; | 137 event->restrict_to_browser_context = restrict_to_profile; |
137 event->event_url = event_url; | 138 event->event_url = event_url; |
138 if (extension_id.empty()) { | 139 if (extension_id.empty()) { |
139 extensions::EventRouter::Get(profile)->BroadcastEvent(std::move(event)); | 140 extensions::EventRouter::Get(profile)->BroadcastEvent(std::move(event)); |
140 } else { | 141 } else { |
141 extensions::EventRouter::Get(profile) | 142 extensions::EventRouter::Get(profile) |
142 ->DispatchEventToExtension(extension_id, std::move(event)); | 143 ->DispatchEventToExtension(extension_id, std::move(event)); |
143 } | 144 } |
144 } | 145 } |
145 | 146 |
146 } // namespace extensions | 147 } // namespace extensions |
OLD | NEW |