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

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

Issue 6961027: Change event routers from singletons to being owned by the ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asargent and dmazzoni's comments Created 9 years, 7 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_history_api.h" 5 #include "chrome/browser/extensions/extension_history_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 57 }
58 58
59 void AddVisitNode(const history::VisitRow& row, ListValue* list) { 59 void AddVisitNode(const history::VisitRow& row, ListValue* list) {
60 DictionaryValue* dict = new DictionaryValue(); 60 DictionaryValue* dict = new DictionaryValue();
61 GetVisitInfoDictionary(row, dict); 61 GetVisitInfoDictionary(row, dict);
62 list->Append(dict); 62 list->Append(dict);
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 ExtensionHistoryEventRouter* ExtensionHistoryEventRouter::GetInstance() { 67 void ExtensionHistoryEventRouter::Init() {
68 return Singleton<ExtensionHistoryEventRouter>::get(); 68 NotificationSource source = Source<Profile>(profile_);
69 }
70
71 void ExtensionHistoryEventRouter::ObserveProfile(Profile* profile) {
72 NotificationSource source = Source<Profile>(profile);
73 if (profiles_.find(source.map_key()) == profiles_.end())
74 profiles_[source.map_key()] = profile;
75
76 if (registrar_.IsEmpty()) { 69 if (registrar_.IsEmpty()) {
77 registrar_.Add(this, 70 registrar_.Add(this,
78 NotificationType::HISTORY_URL_VISITED, 71 NotificationType::HISTORY_URL_VISITED,
79 NotificationService::AllSources()); 72 source);
80 registrar_.Add(this, 73 registrar_.Add(this,
81 NotificationType::HISTORY_URLS_DELETED, 74 NotificationType::HISTORY_URLS_DELETED,
82 NotificationService::AllSources()); 75 source);
83 } 76 }
84 } 77 }
85 78
86 ExtensionHistoryEventRouter::ExtensionHistoryEventRouter() {}
87
88 ExtensionHistoryEventRouter::~ExtensionHistoryEventRouter() {}
89
90 void ExtensionHistoryEventRouter::Observe(NotificationType type, 79 void ExtensionHistoryEventRouter::Observe(NotificationType type,
91 const NotificationSource& source, 80 const NotificationSource& source,
92 const NotificationDetails& details) { 81 const NotificationDetails& details) {
93 ProfileMap::iterator it = profiles_.find(source.map_key()); 82 switch (type.value) {
94 if (it != profiles_.end()) { 83 case NotificationType::HISTORY_URL_VISITED:
95 Profile* profile = it->second; 84 HistoryUrlVisited(
96 switch (type.value) { 85 profile_,
97 case NotificationType::HISTORY_URL_VISITED: 86 Details<const history::URLVisitedDetails>(details).ptr());
98 HistoryUrlVisited( 87 break;
99 profile, 88 case NotificationType::HISTORY_URLS_DELETED:
100 Details<const history::URLVisitedDetails>(details).ptr()); 89 HistoryUrlsRemoved(
101 break; 90 profile_,
102 case NotificationType::HISTORY_URLS_DELETED: 91 Details<const history::URLsDeletedDetails>(details).ptr());
103 HistoryUrlsRemoved( 92 break;
104 profile, 93 default:
105 Details<const history::URLsDeletedDetails>(details).ptr()); 94 NOTREACHED();
106 break;
107 default:
108 NOTREACHED();
109 }
110 } 95 }
111 } 96 }
112 97
113 void ExtensionHistoryEventRouter::HistoryUrlVisited( 98 void ExtensionHistoryEventRouter::HistoryUrlVisited(
114 Profile* profile, 99 Profile* profile,
115 const history::URLVisitedDetails* details) { 100 const history::URLVisitedDetails* details) {
116 ListValue args; 101 ListValue args;
117 DictionaryValue* dict = new DictionaryValue(); 102 DictionaryValue* dict = new DictionaryValue();
118 GetHistoryItemDictionary(details->row, dict); 103 GetHistoryItemDictionary(details->row, dict);
119 args.Append(dict); 104 args.Append(dict);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 base::Time::Now(), // To the current time. 361 base::Time::Now(), // To the current time.
377 &cancelable_consumer_, 362 &cancelable_consumer_,
378 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); 363 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete));
379 364
380 return true; 365 return true;
381 } 366 }
382 367
383 void DeleteAllHistoryFunction::DeleteComplete() { 368 void DeleteAllHistoryFunction::DeleteComplete() {
384 SendAsyncResponse(); 369 SendAsyncResponse();
385 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698