Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/extensions/event_router_forwarder.cc

Issue 10696208: Move ExtensionEventRouter and related into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed bug + latest master Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_event_router_forwarder.h" 5 #include "chrome/browser/extensions/event_router_forwarder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_event_router.h" 9 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
12 12
13 using content::BrowserThread; 13 using content::BrowserThread;
14 14
15 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { 15 namespace extensions {
16
17 EventRouterForwarder::EventRouterForwarder() {
16 } 18 }
17 19
18 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { 20 EventRouterForwarder::~EventRouterForwarder() {
19 } 21 }
20 22
21 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( 23 void EventRouterForwarder::BroadcastEventToRenderers(
22 const std::string& event_name, 24 const std::string& event_name,
23 const std::string& event_args, 25 const std::string& event_args,
24 const GURL& event_url) { 26 const GURL& event_url) {
25 HandleEvent("", event_name, event_args, 0, true, event_url); 27 HandleEvent("", event_name, event_args, 0, true, event_url);
26 } 28 }
27 29
28 void ExtensionEventRouterForwarder::DispatchEventToRenderers( 30 void EventRouterForwarder::DispatchEventToRenderers(
29 const std::string& event_name, 31 const std::string& event_name,
30 const std::string& event_args, 32 const std::string& event_args,
31 void* profile, 33 void* profile,
32 bool use_profile_to_restrict_events, 34 bool use_profile_to_restrict_events,
33 const GURL& event_url) { 35 const GURL& event_url) {
34 if (!profile) 36 if (!profile)
35 return; 37 return;
36 HandleEvent("", event_name, event_args, profile, 38 HandleEvent("", event_name, event_args, profile,
37 use_profile_to_restrict_events, event_url); 39 use_profile_to_restrict_events, event_url);
38 } 40 }
39 41
40 void ExtensionEventRouterForwarder::BroadcastEventToExtension( 42 void EventRouterForwarder::BroadcastEventToExtension(
41 const std::string& extension_id, 43 const std::string& extension_id,
42 const std::string& event_name, 44 const std::string& event_name,
43 const std::string& event_args, 45 const std::string& event_args,
44 const GURL& event_url) { 46 const GURL& event_url) {
45 HandleEvent(extension_id, event_name, event_args, 0, true, event_url); 47 HandleEvent(extension_id, event_name, event_args, 0, true, event_url);
46 } 48 }
47 49
48 void ExtensionEventRouterForwarder::DispatchEventToExtension( 50 void EventRouterForwarder::DispatchEventToExtension(
49 const std::string& extension_id, 51 const std::string& extension_id,
50 const std::string& event_name, 52 const std::string& event_name,
51 const std::string& event_args, 53 const std::string& event_args,
52 void* profile, 54 void* profile,
53 bool use_profile_to_restrict_events, 55 bool use_profile_to_restrict_events,
54 const GURL& event_url) { 56 const GURL& event_url) {
55 if (!profile) 57 if (!profile)
56 return; 58 return;
57 HandleEvent(extension_id, event_name, event_args, profile, 59 HandleEvent(extension_id, event_name, event_args, profile,
58 use_profile_to_restrict_events, event_url); 60 use_profile_to_restrict_events, event_url);
59 } 61 }
60 62
61 void ExtensionEventRouterForwarder::HandleEvent( 63 void EventRouterForwarder::HandleEvent(const std::string& extension_id,
62 const std::string& extension_id, 64 const std::string& event_name,
63 const std::string& event_name, 65 const std::string& event_args,
64 const std::string& event_args, 66 void* profile_ptr,
65 void* profile_ptr, 67 bool use_profile_to_restrict_events,
66 bool use_profile_to_restrict_events, 68 const GURL& event_url) {
67 const GURL& event_url) {
68 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 69 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
69 BrowserThread::PostTask( 70 BrowserThread::PostTask(
70 BrowserThread::UI, FROM_HERE, 71 BrowserThread::UI, FROM_HERE,
71 base::Bind(&ExtensionEventRouterForwarder::HandleEvent, this, 72 base::Bind(&EventRouterForwarder::HandleEvent, this,
72 extension_id, event_name, event_args, profile_ptr, 73 extension_id, event_name, event_args, profile_ptr,
73 use_profile_to_restrict_events, event_url)); 74 use_profile_to_restrict_events, event_url));
74 return; 75 return;
75 } 76 }
76 77
77 if (!g_browser_process || !g_browser_process->profile_manager()) 78 if (!g_browser_process || !g_browser_process->profile_manager())
78 return; 79 return;
79 80
80 ProfileManager* profile_manager = g_browser_process->profile_manager(); 81 ProfileManager* profile_manager = g_browser_process->profile_manager();
81 Profile* profile = NULL; 82 Profile* profile = NULL;
82 if (profile_ptr) { 83 if (profile_ptr) {
83 profile = reinterpret_cast<Profile*>(profile_ptr); 84 profile = reinterpret_cast<Profile*>(profile_ptr);
84 if (!profile_manager->IsValidProfile(profile)) 85 if (!profile_manager->IsValidProfile(profile))
85 return; 86 return;
86 } 87 }
87 if (profile) { 88 if (profile) {
88 CallExtensionEventRouter( 89 CallEventRouter(profile, extension_id, event_name, event_args,
89 profile, extension_id, event_name, event_args, 90 use_profile_to_restrict_events ? profile : NULL, event_url);
90 use_profile_to_restrict_events ? profile : NULL, event_url);
91 } else { 91 } else {
92 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); 92 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
93 for (size_t i = 0; i < profiles.size(); ++i) { 93 for (size_t i = 0; i < profiles.size(); ++i) {
94 CallExtensionEventRouter( 94 CallEventRouter(
95 profiles[i], extension_id, event_name, event_args, 95 profiles[i], extension_id, event_name, event_args,
96 use_profile_to_restrict_events ? profiles[i] : NULL, event_url); 96 use_profile_to_restrict_events ? profiles[i] : NULL, event_url);
97 } 97 }
98 } 98 }
99 } 99 }
100 100
101 void ExtensionEventRouterForwarder::CallExtensionEventRouter( 101 void EventRouterForwarder::CallEventRouter(Profile* profile,
102 Profile* profile, 102 const std::string& extension_id,
103 const std::string& extension_id, 103 const std::string& event_name,
104 const std::string& event_name, 104 const std::string& event_args,
105 const std::string& event_args, 105 Profile* restrict_to_profile,
106 Profile* restrict_to_profile, 106 const GURL& event_url) {
107 const GURL& event_url) {
108 // We may not have an extension in cases like chromeos login 107 // We may not have an extension in cases like chromeos login
109 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome 108 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome
110 // browser single process framework. 109 // browser single process framework.
111 if (!profile->GetExtensionEventRouter()) 110 if (!profile->GetExtensionEventRouter())
112 return; 111 return;
113 112
114 if (extension_id.empty()) { 113 if (extension_id.empty()) {
115 profile->GetExtensionEventRouter()-> 114 profile->GetExtensionEventRouter()->
116 DispatchEventToRenderers( 115 DispatchEventToRenderers(
117 event_name, event_args, restrict_to_profile, event_url, 116 event_name, event_args, restrict_to_profile, event_url,
118 extensions::EventFilteringInfo()); 117 EventFilteringInfo());
119 } else { 118 } else {
120 profile->GetExtensionEventRouter()-> 119 profile->GetExtensionEventRouter()->
121 DispatchEventToExtension( 120 DispatchEventToExtension(
122 extension_id, 121 extension_id,
123 event_name, event_args, restrict_to_profile, event_url); 122 event_name, event_args, restrict_to_profile, event_url);
124 } 123 }
125 } 124 }
125
126 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/event_router_forwarder.h ('k') | chrome/browser/extensions/event_router_forwarder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698