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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix. 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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/extension_event_router_forwarder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h"
8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_event_router.h" 10 #include "chrome/browser/extensions/extension_event_router.h"
10 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
12 13
13 using content::BrowserThread; 14 using content::BrowserThread;
14 15
15 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() { 16 ExtensionEventRouterForwarder::ExtensionEventRouterForwarder() {
16 } 17 }
17 18
18 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() { 19 ExtensionEventRouterForwarder::~ExtensionEventRouterForwarder() {
19 } 20 }
20 21
21 void ExtensionEventRouterForwarder::BroadcastEventToRenderers( 22 void ExtensionEventRouterForwarder::BroadcastEventToRenderers(
22 const std::string& event_name, 23 const std::string& event_name,
23 const std::string& event_args, 24 base::ListValue* event_args,
24 const GURL& event_url) { 25 const GURL& event_url) {
25 HandleEvent("", event_name, event_args, 0, true, event_url); 26 HandleEvent("", event_name, event_args, 0, true, event_url);
26 } 27 }
27 28
28 void ExtensionEventRouterForwarder::DispatchEventToRenderers( 29 void ExtensionEventRouterForwarder::DispatchEventToRenderers(
29 const std::string& event_name, 30 const std::string& event_name,
30 const std::string& event_args, 31 base::ListValue* event_args,
31 void* profile, 32 void* profile,
32 bool use_profile_to_restrict_events, 33 bool use_profile_to_restrict_events,
33 const GURL& event_url) { 34 const GURL& event_url) {
34 if (!profile) 35 if (!profile)
35 return; 36 return;
36 HandleEvent("", event_name, event_args, profile, 37 HandleEvent("", event_name, event_args, profile,
37 use_profile_to_restrict_events, event_url); 38 use_profile_to_restrict_events, event_url);
38 } 39 }
39 40
40 void ExtensionEventRouterForwarder::BroadcastEventToExtension( 41 void ExtensionEventRouterForwarder::BroadcastEventToExtension(
41 const std::string& extension_id, 42 const std::string& extension_id,
42 const std::string& event_name, 43 const std::string& event_name,
43 const std::string& event_args, 44 base::ListValue* event_args,
44 const GURL& event_url) { 45 const GURL& event_url) {
45 HandleEvent(extension_id, event_name, event_args, 0, true, event_url); 46 HandleEvent(extension_id, event_name, event_args, 0, true, event_url);
46 } 47 }
47 48
48 void ExtensionEventRouterForwarder::DispatchEventToExtension( 49 void ExtensionEventRouterForwarder::DispatchEventToExtension(
49 const std::string& extension_id, 50 const std::string& extension_id,
50 const std::string& event_name, 51 const std::string& event_name,
51 const std::string& event_args, 52 base::ListValue* event_args,
52 void* profile, 53 void* profile,
53 bool use_profile_to_restrict_events, 54 bool use_profile_to_restrict_events,
54 const GURL& event_url) { 55 const GURL& event_url) {
55 if (!profile) 56 if (!profile)
56 return; 57 return;
57 HandleEvent(extension_id, event_name, event_args, profile, 58 HandleEvent(extension_id, event_name, event_args, profile,
58 use_profile_to_restrict_events, event_url); 59 use_profile_to_restrict_events, event_url);
59 } 60 }
60 61
61 void ExtensionEventRouterForwarder::HandleEvent( 62 void ExtensionEventRouterForwarder::HandleEvent(
62 const std::string& extension_id, 63 const std::string& extension_id,
63 const std::string& event_name, 64 const std::string& event_name,
64 const std::string& event_args, 65 base::ListValue* event_args,
65 void* profile_ptr, 66 void* profile_ptr,
66 bool use_profile_to_restrict_events, 67 bool use_profile_to_restrict_events,
67 const GURL& event_url) { 68 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(&ExtensionEventRouterForwarder::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;
(...skipping 20 matching lines...) Expand all
95 profiles[i], extension_id, event_name, event_args, 96 profiles[i], extension_id, event_name, event_args,
96 use_profile_to_restrict_events ? profiles[i] : NULL, event_url); 97 use_profile_to_restrict_events ? profiles[i] : NULL, event_url);
97 } 98 }
98 } 99 }
99 } 100 }
100 101
101 void ExtensionEventRouterForwarder::CallExtensionEventRouter( 102 void ExtensionEventRouterForwarder::CallExtensionEventRouter(
102 Profile* profile, 103 Profile* profile,
103 const std::string& extension_id, 104 const std::string& extension_id,
104 const std::string& event_name, 105 const std::string& event_name,
105 const std::string& event_args, 106 base::ListValue* event_args,
106 Profile* restrict_to_profile, 107 Profile* restrict_to_profile,
107 const GURL& event_url) { 108 const GURL& event_url) {
108 // We may not have an extension in cases like chromeos login 109 // We may not have an extension in cases like chromeos login
109 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome 110 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome
110 // browser single process framework. 111 // browser single process framework.
111 if (!profile->GetExtensionEventRouter()) 112 if (!profile->GetExtensionEventRouter())
112 return; 113 return;
113 114
114 if (extension_id.empty()) { 115 if (extension_id.empty()) {
115 profile->GetExtensionEventRouter()-> 116 profile->GetExtensionEventRouter()->
116 DispatchEventToRenderers( 117 DispatchEventToRenderers(
117 event_name, event_args, restrict_to_profile, event_url); 118 event_name, event_args, restrict_to_profile, event_url);
118 } else { 119 } else {
119 profile->GetExtensionEventRouter()-> 120 profile->GetExtensionEventRouter()->
120 DispatchEventToExtension( 121 DispatchEventToExtension(
121 extension_id, 122 extension_id,
122 event_name, event_args, restrict_to_profile, event_url); 123 event_name, event_args, restrict_to_profile, event_url);
123 } 124 }
124 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698