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

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

Issue 6598002: Make the ChromeNetworkDelegate use the ExtensionEventRouterForwarder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_event_router_forwarder.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/extension_event_router.h" 8 #include "chrome/browser/extensions/extension_event_router.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
11 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
12 11
13 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { 12 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() {
14 } 13 }
15 14
16 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { 15 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() {
17 } 16 }
18 17
19 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( 18 void ExtensionEventRouterForwarder::BroadcastEventToRenderers(
20 const std::string& event_name, const std::string& event_args, 19 const std::string& event_name, const std::string& event_args,
21 const GURL& event_url) { 20 const GURL& event_url) {
22 HandleEvent("", event_name, event_args, NULL, true, event_url); 21 HandleEvent("", event_name, event_args, 0, true, event_url);
23 } 22 }
24 23
25 void ExtensionEventRouterForwarder::DispatchEventToRenderers( 24 void ExtensionEventRouterForwarder::DispatchEventToRenderers(
26 const std::string& event_name, const std::string& event_args, 25 const std::string& event_name, const std::string& event_args,
27 Profile* profile, bool use_profile_to_restrict_events, 26 ProfileId profile_id, bool use_profile_to_restrict_events,
28 const GURL& event_url) { 27 const GURL& event_url) {
29 DCHECK(profile); 28 if (profile_id == Profile::kInvalidProfileId)
30 HandleEvent("", event_name, event_args, profile, 29 return;
30 HandleEvent("", event_name, event_args, profile_id,
31 use_profile_to_restrict_events, event_url); 31 use_profile_to_restrict_events, event_url);
32 } 32 }
33 33
34 void ExtensionEventRouterForwarder::BroadcastEventToExtension( 34 void ExtensionEventRouterForwarder::BroadcastEventToExtension(
35 const std::string& extension_id, 35 const std::string& extension_id,
36 const std::string& event_name, const std::string& event_args, 36 const std::string& event_name, const std::string& event_args,
37 const GURL& event_url) { 37 const GURL& event_url) {
38 HandleEvent(extension_id, event_name, event_args, NULL, true, event_url); 38 HandleEvent(extension_id, event_name, event_args, 0, true, event_url);
39 } 39 }
40 40
41 void ExtensionEventRouterForwarder::DispatchEventToExtension( 41 void ExtensionEventRouterForwarder::DispatchEventToExtension(
42 const std::string& extension_id, 42 const std::string& extension_id,
43 const std::string& event_name, const std::string& event_args, 43 const std::string& event_name, const std::string& event_args,
44 Profile* profile, bool use_profile_to_restrict_events, 44 ProfileId profile_id, bool use_profile_to_restrict_events,
45 const GURL& event_url) { 45 const GURL& event_url) {
46 DCHECK(profile); 46 if (profile_id == Profile::kInvalidProfileId)
47 HandleEvent(extension_id, event_name, event_args, profile, 47 return;
48 HandleEvent(extension_id, event_name, event_args, profile_id,
48 use_profile_to_restrict_events, event_url); 49 use_profile_to_restrict_events, event_url);
49 } 50 }
50 51
51 void ExtensionEventRouterForwarder::HandleEvent( 52 void ExtensionEventRouterForwarder::HandleEvent(
52 const std::string& extension_id, 53 const std::string& extension_id,
53 const std::string& event_name, const std::string& event_args, 54 const std::string& event_name, const std::string& event_args,
54 Profile* profile, bool use_profile_to_restrict_events, 55 ProfileId profile_id, bool use_profile_to_restrict_events,
55 const GURL& event_url) { 56 const GURL& event_url) {
56 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 57 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
57 BrowserThread::PostTask( 58 BrowserThread::PostTask(
58 BrowserThread::UI, FROM_HERE, 59 BrowserThread::UI, FROM_HERE,
59 NewRunnableMethod( 60 NewRunnableMethod(
60 this, 61 this,
61 &ExtensionEventRouterForwarder::HandleEvent, 62 &ExtensionEventRouterForwarder::HandleEvent,
62 extension_id, event_name, event_args, profile, 63 extension_id, event_name, event_args, profile_id,
63 use_profile_to_restrict_events, event_url)); 64 use_profile_to_restrict_events, event_url));
64 return; 65 return;
65 } 66 }
66 67
67 if (!g_browser_process || !g_browser_process->profile_manager()) 68 if (!g_browser_process || !g_browser_process->profile_manager())
68 return; 69 return;
69 70
70 ProfileManager* profile_manager = g_browser_process->profile_manager(); 71 ProfileManager* profile_manager = g_browser_process->profile_manager();
72 Profile* profile = NULL;
73 if (profile_id != Profile::kInvalidProfileId) {
74 profile = profile_manager->GetProfileWithId(profile_id);
75 if (!profile)
76 return;
77 }
71 if (profile) { 78 if (profile) {
72 if (!profile_manager->IsValidProfile(profile))
73 return;
74 CallExtensionEventRouter( 79 CallExtensionEventRouter(
75 profile, extension_id, event_name, event_args, 80 profile, extension_id, event_name, event_args,
76 use_profile_to_restrict_events ? profile : NULL, event_url); 81 use_profile_to_restrict_events ? profile : NULL, event_url);
77 } else { 82 } else {
78 ProfileManager::iterator i; 83 ProfileManager::iterator i;
79 for (i = profile_manager->begin(); i != profile_manager->end(); ++i) { 84 for (i = profile_manager->begin(); i != profile_manager->end(); ++i) {
80 CallExtensionEventRouter( 85 CallExtensionEventRouter(
81 *i, extension_id, event_name, event_args, 86 *i, extension_id, event_name, event_args,
82 use_profile_to_restrict_events ? (*i) : NULL, event_url); 87 use_profile_to_restrict_events ? (*i) : NULL, event_url);
83 } 88 }
84 } 89 }
85 } 90 }
86 91
87 void ExtensionEventRouterForwarder::CallExtensionEventRouter( 92 void ExtensionEventRouterForwarder::CallExtensionEventRouter(
88 Profile* profile, const std::string& extension_id, 93 Profile* profile, const std::string& extension_id,
89 const std::string& event_name, const std::string& event_args, 94 const std::string& event_name, const std::string& event_args,
90 Profile* restrict_to_profile, const GURL& event_url) { 95 Profile* restrict_to_profile, const GURL& event_url) {
91 if (extension_id.empty()) { 96 if (extension_id.empty()) {
92 profile->GetExtensionEventRouter()-> 97 profile->GetExtensionEventRouter()->
93 DispatchEventToRenderers( 98 DispatchEventToRenderers(
94 event_name, event_args, restrict_to_profile, event_url); 99 event_name, event_args, restrict_to_profile, event_url);
95 } else { 100 } else {
96 profile->GetExtensionEventRouter()-> 101 profile->GetExtensionEventRouter()->
97 DispatchEventToExtension( 102 DispatchEventToExtension(
98 extension_id, 103 extension_id,
99 event_name, event_args, restrict_to_profile, event_url); 104 event_name, event_args, restrict_to_profile, event_url);
100 } 105 }
101 } 106 }
102 107
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698