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

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

Issue 7243012: Change many extension event routers to not be singletons and to be more profile-aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bookmark remove observer Created 9 years, 6 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() {
68 return Singleton<ExtensionHistoryEventRouter>::get();
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()) {
77 registrar_.Add(this,
78 NotificationType::HISTORY_URL_VISITED,
79 NotificationService::AllSources());
80 registrar_.Add(this,
81 NotificationType::HISTORY_URLS_DELETED,
82 NotificationService::AllSources());
83 }
84 }
85
86 ExtensionHistoryEventRouter::ExtensionHistoryEventRouter() {} 67 ExtensionHistoryEventRouter::ExtensionHistoryEventRouter() {}
87 68
88 ExtensionHistoryEventRouter::~ExtensionHistoryEventRouter() {} 69 ExtensionHistoryEventRouter::~ExtensionHistoryEventRouter() {}
89 70
71 void ExtensionHistoryEventRouter::ObserveProfile(Profile* profile) {
72 NotificationSource source = Source<Profile>(profile);
73 CHECK(registrar_.IsEmpty());
74 registrar_.Add(this,
75 NotificationType::HISTORY_URL_VISITED,
76 source);
77 registrar_.Add(this,
78 NotificationType::HISTORY_URLS_DELETED,
79 source);
80 }
81
90 void ExtensionHistoryEventRouter::Observe(NotificationType type, 82 void ExtensionHistoryEventRouter::Observe(NotificationType type,
91 const NotificationSource& source, 83 const NotificationSource& source,
92 const NotificationDetails& details) { 84 const NotificationDetails& details) {
93 ProfileMap::iterator it = profiles_.find(source.map_key()); 85 switch (type.value) {
94 if (it != profiles_.end()) { 86 case NotificationType::HISTORY_URL_VISITED:
95 Profile* profile = it->second; 87 HistoryUrlVisited(
96 switch (type.value) { 88 Source<Profile>(source).ptr(),
97 case NotificationType::HISTORY_URL_VISITED: 89 Details<const history::URLVisitedDetails>(details).ptr());
98 HistoryUrlVisited( 90 break;
99 profile, 91 case NotificationType::HISTORY_URLS_DELETED:
100 Details<const history::URLVisitedDetails>(details).ptr()); 92 HistoryUrlsRemoved(
101 break; 93 Source<Profile>(source).ptr(),
102 case NotificationType::HISTORY_URLS_DELETED: 94 Details<const history::URLsDeletedDetails>(details).ptr());
103 HistoryUrlsRemoved( 95 break;
104 profile, 96 default:
105 Details<const history::URLsDeletedDetails>(details).ptr()); 97 NOTREACHED();
106 break;
107 default:
108 NOTREACHED();
109 }
110 } 98 }
111 } 99 }
112 100
113 void ExtensionHistoryEventRouter::HistoryUrlVisited( 101 void ExtensionHistoryEventRouter::HistoryUrlVisited(
114 Profile* profile, 102 Profile* profile,
115 const history::URLVisitedDetails* details) { 103 const history::URLVisitedDetails* details) {
116 ListValue args; 104 ListValue args;
117 DictionaryValue* dict = new DictionaryValue(); 105 DictionaryValue* dict = new DictionaryValue();
118 GetHistoryItemDictionary(details->row, dict); 106 GetHistoryItemDictionary(details->row, dict);
119 args.Append(dict); 107 args.Append(dict);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 base::Time::Now(), // To the current time. 364 base::Time::Now(), // To the current time.
377 &cancelable_consumer_, 365 &cancelable_consumer_,
378 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); 366 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete));
379 367
380 return true; 368 return true;
381 } 369 }
382 370
383 void DeleteAllHistoryFunction::DeleteComplete() { 371 void DeleteAllHistoryFunction::DeleteComplete() {
384 SendAsyncResponse(); 372 SendAsyncResponse();
385 } 373 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_history_api.h ('k') | chrome/browser/extensions/extension_management_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698