Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 if (registrar_.IsEmpty()) { | |
|
asargent_no_longer_on_chrome
2011/06/23 22:18:38
since you removed the "this is safe to call multip
Yoyo Zhou
2011/06/24 17:21:38
Ok. (I don't know why we went to the effort of mak
asargent_no_longer_on_chrome
2011/06/24 18:56:39
Me neither. =)
| |
| 74 registrar_.Add(this, | |
| 75 NotificationType::HISTORY_URL_VISITED, | |
| 76 source); | |
| 77 registrar_.Add(this, | |
| 78 NotificationType::HISTORY_URLS_DELETED, | |
| 79 source); | |
| 80 } | |
| 81 } | |
| 82 | |
| 90 void ExtensionHistoryEventRouter::Observe(NotificationType type, | 83 void ExtensionHistoryEventRouter::Observe(NotificationType type, |
| 91 const NotificationSource& source, | 84 const NotificationSource& source, |
| 92 const NotificationDetails& details) { | 85 const NotificationDetails& details) { |
| 93 ProfileMap::iterator it = profiles_.find(source.map_key()); | 86 switch (type.value) { |
| 94 if (it != profiles_.end()) { | 87 case NotificationType::HISTORY_URL_VISITED: |
| 95 Profile* profile = it->second; | 88 HistoryUrlVisited( |
| 96 switch (type.value) { | 89 Source<Profile>(source).ptr(), |
| 97 case NotificationType::HISTORY_URL_VISITED: | 90 Details<const history::URLVisitedDetails>(details).ptr()); |
| 98 HistoryUrlVisited( | 91 break; |
| 99 profile, | 92 case NotificationType::HISTORY_URLS_DELETED: |
| 100 Details<const history::URLVisitedDetails>(details).ptr()); | 93 HistoryUrlsRemoved( |
| 101 break; | 94 Source<Profile>(source).ptr(), |
| 102 case NotificationType::HISTORY_URLS_DELETED: | 95 Details<const history::URLsDeletedDetails>(details).ptr()); |
| 103 HistoryUrlsRemoved( | 96 break; |
| 104 profile, | 97 default: |
| 105 Details<const history::URLsDeletedDetails>(details).ptr()); | 98 NOTREACHED(); |
| 106 break; | |
| 107 default: | |
| 108 NOTREACHED(); | |
| 109 } | |
| 110 } | 99 } |
| 111 } | 100 } |
| 112 | 101 |
| 113 void ExtensionHistoryEventRouter::HistoryUrlVisited( | 102 void ExtensionHistoryEventRouter::HistoryUrlVisited( |
| 114 Profile* profile, | 103 Profile* profile, |
| 115 const history::URLVisitedDetails* details) { | 104 const history::URLVisitedDetails* details) { |
| 116 ListValue args; | 105 ListValue args; |
| 117 DictionaryValue* dict = new DictionaryValue(); | 106 DictionaryValue* dict = new DictionaryValue(); |
| 118 GetHistoryItemDictionary(details->row, dict); | 107 GetHistoryItemDictionary(details->row, dict); |
| 119 args.Append(dict); | 108 args.Append(dict); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 base::Time::Now(), // To the current time. | 365 base::Time::Now(), // To the current time. |
| 377 &cancelable_consumer_, | 366 &cancelable_consumer_, |
| 378 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); | 367 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); |
| 379 | 368 |
| 380 return true; | 369 return true; |
| 381 } | 370 } |
| 382 | 371 |
| 383 void DeleteAllHistoryFunction::DeleteComplete() { | 372 void DeleteAllHistoryFunction::DeleteComplete() { |
| 384 SendAsyncResponse(); | 373 SendAsyncResponse(); |
| 385 } | 374 } |
| OLD | NEW |