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() { | 67 ExtensionHistoryEventRouter::ExtensionHistoryEventRouter(Profile* profile) |
68 return Singleton<ExtensionHistoryEventRouter>::get(); | 68 : profile_(profile) {} |
69 } | |
70 | 69 |
71 void ExtensionHistoryEventRouter::ObserveProfile(Profile* profile) { | 70 ExtensionHistoryEventRouter::~ExtensionHistoryEventRouter() {} |
72 NotificationSource source = Source<Profile>(profile); | |
73 if (profiles_.find(source.map_key()) == profiles_.end()) | |
74 profiles_[source.map_key()] = profile; | |
75 | 71 |
| 72 void ExtensionHistoryEventRouter::Init() { |
| 73 NotificationSource source = Source<Profile>(profile_); |
76 if (registrar_.IsEmpty()) { | 74 if (registrar_.IsEmpty()) { |
77 registrar_.Add(this, | 75 registrar_.Add(this, |
78 NotificationType::HISTORY_URL_VISITED, | 76 NotificationType::HISTORY_URL_VISITED, |
79 NotificationService::AllSources()); | 77 source); |
80 registrar_.Add(this, | 78 registrar_.Add(this, |
81 NotificationType::HISTORY_URLS_DELETED, | 79 NotificationType::HISTORY_URLS_DELETED, |
82 NotificationService::AllSources()); | 80 source); |
83 } | 81 } |
84 } | 82 } |
85 | 83 |
86 ExtensionHistoryEventRouter::ExtensionHistoryEventRouter() {} | |
87 | |
88 ExtensionHistoryEventRouter::~ExtensionHistoryEventRouter() {} | |
89 | |
90 void ExtensionHistoryEventRouter::Observe(NotificationType type, | 84 void ExtensionHistoryEventRouter::Observe(NotificationType type, |
91 const NotificationSource& source, | 85 const NotificationSource& source, |
92 const NotificationDetails& details) { | 86 const NotificationDetails& details) { |
93 ProfileMap::iterator it = profiles_.find(source.map_key()); | 87 switch (type.value) { |
94 if (it != profiles_.end()) { | 88 case NotificationType::HISTORY_URL_VISITED: |
95 Profile* profile = it->second; | 89 HistoryUrlVisited( |
96 switch (type.value) { | 90 profile_, |
97 case NotificationType::HISTORY_URL_VISITED: | 91 Details<const history::URLVisitedDetails>(details).ptr()); |
98 HistoryUrlVisited( | 92 break; |
99 profile, | 93 case NotificationType::HISTORY_URLS_DELETED: |
100 Details<const history::URLVisitedDetails>(details).ptr()); | 94 HistoryUrlsRemoved( |
101 break; | 95 profile_, |
102 case NotificationType::HISTORY_URLS_DELETED: | 96 Details<const history::URLsDeletedDetails>(details).ptr()); |
103 HistoryUrlsRemoved( | 97 break; |
104 profile, | 98 default: |
105 Details<const history::URLsDeletedDetails>(details).ptr()); | 99 NOTREACHED(); |
106 break; | |
107 default: | |
108 NOTREACHED(); | |
109 } | |
110 } | 100 } |
111 } | 101 } |
112 | 102 |
113 void ExtensionHistoryEventRouter::HistoryUrlVisited( | 103 void ExtensionHistoryEventRouter::HistoryUrlVisited( |
114 Profile* profile, | 104 Profile* profile, |
115 const history::URLVisitedDetails* details) { | 105 const history::URLVisitedDetails* details) { |
116 ListValue args; | 106 ListValue args; |
117 DictionaryValue* dict = new DictionaryValue(); | 107 DictionaryValue* dict = new DictionaryValue(); |
118 GetHistoryItemDictionary(details->row, dict); | 108 GetHistoryItemDictionary(details->row, dict); |
119 args.Append(dict); | 109 args.Append(dict); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 base::Time::Now(), // To the current time. | 366 base::Time::Now(), // To the current time. |
377 &cancelable_consumer_, | 367 &cancelable_consumer_, |
378 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); | 368 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); |
379 | 369 |
380 return true; | 370 return true; |
381 } | 371 } |
382 | 372 |
383 void DeleteAllHistoryFunction::DeleteComplete() { | 373 void DeleteAllHistoryFunction::DeleteComplete() { |
384 SendAsyncResponse(); | 374 SendAsyncResponse(); |
385 } | 375 } |
OLD | NEW |