Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/task/cancelable_task_tracker.h" | 18 #include "base/task/cancelable_task_tracker.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
|
sdefresne
2014/12/04 17:21:12
This include can also be removed ;-)
nshaik
2014/12/07 09:34:49
:) Done
| |
| 22 #include "chrome/browser/extensions/activity_log/activity_log.h" | 22 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 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/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/extensions/api/history.h" | 27 #include "chrome/common/extensions/api/history.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "components/history/core/browser/history_types.h" | 29 #include "components/history/core/browser/history_types.h" |
| 30 #include "content/public/browser/notification_details.h" | |
| 31 #include "content/public/browser/notification_source.h" | |
| 32 #include "extensions/browser/event_router.h" | 30 #include "extensions/browser/event_router.h" |
| 33 #include "extensions/browser/extension_system_provider.h" | 31 #include "extensions/browser/extension_system_provider.h" |
| 34 #include "extensions/browser/extensions_browser_client.h" | 32 #include "extensions/browser/extensions_browser_client.h" |
| 35 | 33 |
| 36 namespace extensions { | 34 namespace extensions { |
| 37 | 35 |
| 38 using api::history::HistoryItem; | 36 using api::history::HistoryItem; |
| 39 using api::history::VisitItem; | 37 using api::history::VisitItem; |
| 40 using extensions::ActivityLog; | 38 using extensions::ActivityLog; |
| 41 | 39 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 126 |
| 129 return visit_item.Pass(); | 127 return visit_item.Pass(); |
| 130 } | 128 } |
| 131 | 129 |
| 132 } // namespace | 130 } // namespace |
| 133 | 131 |
| 134 HistoryEventRouter::HistoryEventRouter(Profile* profile, | 132 HistoryEventRouter::HistoryEventRouter(Profile* profile, |
| 135 HistoryService* history_service) | 133 HistoryService* history_service) |
| 136 : profile_(profile), history_service_observer_(this) { | 134 : profile_(profile), history_service_observer_(this) { |
| 137 DCHECK(profile); | 135 DCHECK(profile); |
| 138 registrar_.Add(this, | |
| 139 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
| 140 content::Source<Profile>(profile)); | |
| 141 history_service_observer_.Add(history_service); | 136 history_service_observer_.Add(history_service); |
| 142 } | 137 } |
| 143 | 138 |
| 144 HistoryEventRouter::~HistoryEventRouter() { | 139 HistoryEventRouter::~HistoryEventRouter() { |
| 145 } | 140 } |
| 146 | 141 |
| 147 void HistoryEventRouter::Observe(int type, | |
| 148 const content::NotificationSource& source, | |
| 149 const content::NotificationDetails& details) { | |
| 150 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED); | |
| 151 HistoryUrlsRemoved( | |
| 152 content::Source<Profile>(source).ptr(), | |
| 153 content::Details<const history::URLsDeletedDetails>(details).ptr()); | |
| 154 } | |
| 155 | |
| 156 void HistoryEventRouter::OnURLVisited(HistoryService* history_service, | 142 void HistoryEventRouter::OnURLVisited(HistoryService* history_service, |
| 157 ui::PageTransition transition, | 143 ui::PageTransition transition, |
| 158 const history::URLRow& row, | 144 const history::URLRow& row, |
| 159 const history::RedirectList& redirects, | 145 const history::RedirectList& redirects, |
| 160 base::Time visit_time) { | 146 base::Time visit_time) { |
| 161 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); | 147 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); |
| 162 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); | 148 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); |
| 163 DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass()); | 149 DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass()); |
| 164 } | 150 } |
| 165 | 151 |
| 152 void HistoryEventRouter::OnURLsDeleted( | |
| 153 HistoryService* history_service, | |
| 154 const history::URLsDeletedDetails& deleted_details) { | |
| 155 HistoryUrlsRemoved(history_service->profile(), &deleted_details); | |
|
sdefresne
2014/12/04 17:21:12
Remove HistoryUrlsRemoved() method and inline the
nshaik
2014/12/07 09:34:49
Done.
| |
| 156 } | |
| 157 | |
| 166 void HistoryEventRouter::HistoryUrlsRemoved( | 158 void HistoryEventRouter::HistoryUrlsRemoved( |
| 167 Profile* profile, | 159 Profile* profile, |
| 168 const history::URLsDeletedDetails* details) { | 160 const history::URLsDeletedDetails* details) { |
| 169 OnVisitRemoved::Removed removed; | 161 OnVisitRemoved::Removed removed; |
| 170 removed.all_history = details->all_history; | 162 removed.all_history = details->all_history; |
| 171 | 163 |
| 172 std::vector<std::string>* urls = new std::vector<std::string>(); | 164 std::vector<std::string>* urls = new std::vector<std::string>(); |
| 173 for (history::URLRows::const_iterator iterator = details->rows.begin(); | 165 for (history::URLRows::const_iterator iterator = details->rows.begin(); |
| 174 iterator != details->rows.end(); ++iterator) { | 166 iterator != details->rows.end(); ++iterator) { |
| 175 urls->push_back(iterator->url().spec()); | 167 urls->push_back(iterator->url().spec()); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 } | 461 } |
| 470 | 462 |
| 471 return true; | 463 return true; |
| 472 } | 464 } |
| 473 | 465 |
| 474 void HistoryDeleteAllFunction::DeleteComplete() { | 466 void HistoryDeleteAllFunction::DeleteComplete() { |
| 475 SendAsyncResponse(); | 467 SendAsyncResponse(); |
| 476 } | 468 } |
| 477 | 469 |
| 478 } // namespace extensions | 470 } // namespace extensions |
| OLD | NEW |