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

Side by Side Diff: chrome/browser/extensions/api/history/history_api.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for chromeos build. Created 6 years, 8 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/api/history/history_api.h" 5 #include "chrome/browser/extensions/api/history/history_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/history/history_service.h" 23 #include "chrome/browser/history/history_service.h"
24 #include "chrome/browser/history/history_service_factory.h" 24 #include "chrome/browser/history/history_service_factory.h"
25 #include "chrome/browser/history/history_types.h" 25 #include "chrome/browser/history/history_types.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/extensions/api/history.h" 28 #include "chrome/common/extensions/api/history.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
32 #include "extensions/browser/event_router.h" 32 #include "extensions/browser/event_router.h"
33 #include "extensions/browser/extension_system.h"
34 #include "extensions/browser/extension_system_provider.h" 33 #include "extensions/browser/extension_system_provider.h"
35 #include "extensions/browser/extensions_browser_client.h" 34 #include "extensions/browser/extensions_browser_client.h"
36 35
37 namespace extensions { 36 namespace extensions {
38 37
39 using api::history::HistoryItem; 38 using api::history::HistoryItem;
40 using api::history::VisitItem; 39 using api::history::VisitItem;
41 using extensions::ActivityLog; 40 using extensions::ActivityLog;
42 41
43 typedef std::vector<linked_ptr<api::history::HistoryItem> > 42 typedef std::vector<linked_ptr<api::history::HistoryItem> >
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 removed.urls.reset(urls); 185 removed.urls.reset(urls);
187 186
188 scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed); 187 scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed);
189 DispatchEvent(profile, api::history::OnVisitRemoved::kEventName, args.Pass()); 188 DispatchEvent(profile, api::history::OnVisitRemoved::kEventName, args.Pass());
190 } 189 }
191 190
192 void HistoryEventRouter::DispatchEvent( 191 void HistoryEventRouter::DispatchEvent(
193 Profile* profile, 192 Profile* profile,
194 const std::string& event_name, 193 const std::string& event_name,
195 scoped_ptr<base::ListValue> event_args) { 194 scoped_ptr<base::ListValue> event_args) {
196 if (profile && extensions::ExtensionSystem::Get(profile)->event_router()) { 195 if (profile && extensions::EventRouter::Get(profile)) {
197 scoped_ptr<extensions::Event> event(new extensions::Event( 196 scoped_ptr<extensions::Event> event(new extensions::Event(
198 event_name, event_args.Pass())); 197 event_name, event_args.Pass()));
199 event->restrict_to_browser_context = profile; 198 event->restrict_to_browser_context = profile;
200 extensions::ExtensionSystem::Get(profile)->event_router()-> 199 extensions::EventRouter::Get(profile)->BroadcastEvent(event.Pass());
201 BroadcastEvent(event.Pass());
202 } 200 }
203 } 201 }
204 202
205 HistoryAPI::HistoryAPI(content::BrowserContext* context) 203 HistoryAPI::HistoryAPI(content::BrowserContext* context)
206 : browser_context_(context) { 204 : browser_context_(context) {
207 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( 205 EventRouter* event_router = EventRouter::Get(browser_context_);
208 this, api::history::OnVisited::kEventName); 206 event_router->RegisterObserver(this, api::history::OnVisited::kEventName);
209 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( 207 event_router->RegisterObserver(this,
210 this, api::history::OnVisitRemoved::kEventName); 208 api::history::OnVisitRemoved::kEventName);
211 } 209 }
212 210
213 HistoryAPI::~HistoryAPI() { 211 HistoryAPI::~HistoryAPI() {
214 } 212 }
215 213
216 void HistoryAPI::Shutdown() { 214 void HistoryAPI::Shutdown() {
217 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( 215 EventRouter::Get(browser_context_)->UnregisterObserver(this);
218 this);
219 } 216 }
220 217
221 static base::LazyInstance<BrowserContextKeyedAPIFactory<HistoryAPI> > 218 static base::LazyInstance<BrowserContextKeyedAPIFactory<HistoryAPI> >
222 g_factory = LAZY_INSTANCE_INITIALIZER; 219 g_factory = LAZY_INSTANCE_INITIALIZER;
223 220
224 // static 221 // static
225 BrowserContextKeyedAPIFactory<HistoryAPI>* HistoryAPI::GetFactoryInstance() { 222 BrowserContextKeyedAPIFactory<HistoryAPI>* HistoryAPI::GetFactoryInstance() {
226 return g_factory.Pointer(); 223 return g_factory.Pointer();
227 } 224 }
228 225
229 template <> 226 template <>
230 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() { 227 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() {
231 DependsOn(ActivityLog::GetFactoryInstance()); 228 DependsOn(ActivityLog::GetFactoryInstance());
232 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 229 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
233 } 230 }
234 231
235 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { 232 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) {
236 history_event_router_.reset( 233 history_event_router_.reset(
237 new HistoryEventRouter(Profile::FromBrowserContext(browser_context_))); 234 new HistoryEventRouter(Profile::FromBrowserContext(browser_context_)));
238 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( 235 EventRouter::Get(browser_context_)->UnregisterObserver(this);
239 this);
240 } 236 }
241 237
242 void HistoryFunction::Run() { 238 void HistoryFunction::Run() {
243 if (!RunImpl()) { 239 if (!RunImpl()) {
244 SendResponse(false); 240 SendResponse(false);
245 } 241 }
246 } 242 }
247 243
248 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { 244 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) {
249 GURL temp_url(url_string); 245 GURL temp_url(url_string);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 481 }
486 482
487 return true; 483 return true;
488 } 484 }
489 485
490 void HistoryDeleteAllFunction::DeleteComplete() { 486 void HistoryDeleteAllFunction::DeleteComplete() {
491 SendAsyncResponse(); 487 SendAsyncResponse();
492 } 488 }
493 489
494 } // namespace extensions 490 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/gcm/gcm_api.cc ('k') | chrome/browser/extensions/api/hotword_private/hotword_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698