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

Side by Side Diff: chrome/browser/extensions/api/history/history_api.cc

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed local variables in tests Created 6 years 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
OLDNEW
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"
22 #include "chrome/browser/extensions/activity_log/activity_log.h" 21 #include "chrome/browser/extensions/activity_log/activity_log.h"
23 #include "chrome/browser/history/history_service.h" 22 #include "chrome/browser/history/history_service.h"
24 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
25 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/extensions/api/history.h" 26 #include "chrome/common/extensions/api/history.h"
28 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
29 #include "components/history/core/browser/history_types.h" 28 #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" 29 #include "extensions/browser/event_router.h"
33 #include "extensions/browser/extension_system_provider.h" 30 #include "extensions/browser/extension_system_provider.h"
34 #include "extensions/browser/extensions_browser_client.h" 31 #include "extensions/browser/extensions_browser_client.h"
35 32
36 namespace extensions { 33 namespace extensions {
37 34
38 using api::history::HistoryItem; 35 using api::history::HistoryItem;
39 using api::history::VisitItem; 36 using api::history::VisitItem;
40 using extensions::ActivityLog; 37 using extensions::ActivityLog;
41 38
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 125
129 return visit_item.Pass(); 126 return visit_item.Pass();
130 } 127 }
131 128
132 } // namespace 129 } // namespace
133 130
134 HistoryEventRouter::HistoryEventRouter(Profile* profile, 131 HistoryEventRouter::HistoryEventRouter(Profile* profile,
135 HistoryService* history_service) 132 HistoryService* history_service)
136 : profile_(profile), history_service_observer_(this) { 133 : profile_(profile), history_service_observer_(this) {
137 DCHECK(profile); 134 DCHECK(profile);
138 registrar_.Add(this,
139 chrome::NOTIFICATION_HISTORY_URLS_DELETED,
140 content::Source<Profile>(profile));
141 history_service_observer_.Add(history_service); 135 history_service_observer_.Add(history_service);
142 } 136 }
143 137
144 HistoryEventRouter::~HistoryEventRouter() { 138 HistoryEventRouter::~HistoryEventRouter() {
145 } 139 }
146 140
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, 141 void HistoryEventRouter::OnURLVisited(HistoryService* history_service,
157 ui::PageTransition transition, 142 ui::PageTransition transition,
158 const history::URLRow& row, 143 const history::URLRow& row,
159 const history::RedirectList& redirects, 144 const history::RedirectList& redirects,
160 base::Time visit_time) { 145 base::Time visit_time) {
161 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row); 146 scoped_ptr<HistoryItem> history_item = GetHistoryItem(row);
162 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item); 147 scoped_ptr<base::ListValue> args = OnVisited::Create(*history_item);
163 DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass()); 148 DispatchEvent(profile_, api::history::OnVisited::kEventName, args.Pass());
164 } 149 }
165 150
166 void HistoryEventRouter::HistoryUrlsRemoved( 151 void HistoryEventRouter::OnURLsDeleted(HistoryService* history_service,
167 Profile* profile, 152 bool all_history,
168 const history::URLsDeletedDetails* details) { 153 bool expired,
154 const history::URLRows& deleted_rows,
155 const std::set<GURL>& favicon_urls) {
156 DCHECK_EQ(HistoryServiceFactory::GetForProfileIfExists(
157 profile_, Profile::EXPLICIT_ACCESS),
158 history_service);
169 OnVisitRemoved::Removed removed; 159 OnVisitRemoved::Removed removed;
170 removed.all_history = details->all_history; 160 removed.all_history = all_history;
171 161
172 std::vector<std::string>* urls = new std::vector<std::string>(); 162 std::vector<std::string>* urls = new std::vector<std::string>();
173 for (history::URLRows::const_iterator iterator = details->rows.begin(); 163 for (const auto& row : deleted_rows)
174 iterator != details->rows.end(); ++iterator) { 164 urls->push_back(row.url().spec());
175 urls->push_back(iterator->url().spec());
176 }
177 removed.urls.reset(urls); 165 removed.urls.reset(urls);
178 166
179 scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed); 167 scoped_ptr<base::ListValue> args = OnVisitRemoved::Create(removed);
180 DispatchEvent(profile, api::history::OnVisitRemoved::kEventName, args.Pass()); 168 DispatchEvent(profile_, api::history::OnVisitRemoved::kEventName,
169 args.Pass());
181 } 170 }
182 171
183 void HistoryEventRouter::DispatchEvent( 172 void HistoryEventRouter::DispatchEvent(
184 Profile* profile, 173 Profile* profile,
185 const std::string& event_name, 174 const std::string& event_name,
186 scoped_ptr<base::ListValue> event_args) { 175 scoped_ptr<base::ListValue> event_args) {
187 if (profile && extensions::EventRouter::Get(profile)) { 176 if (profile && extensions::EventRouter::Get(profile)) {
188 scoped_ptr<extensions::Event> event(new extensions::Event( 177 scoped_ptr<extensions::Event> event(new extensions::Event(
189 event_name, event_args.Pass())); 178 event_name, event_args.Pass()));
190 event->restrict_to_browser_context = profile; 179 event->restrict_to_browser_context = profile;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 458 }
470 459
471 return true; 460 return true;
472 } 461 }
473 462
474 void HistoryDeleteAllFunction::DeleteComplete() { 463 void HistoryDeleteAllFunction::DeleteComplete() {
475 SendAsyncResponse(); 464 SendAsyncResponse();
476 } 465 }
477 466
478 } // namespace extensions 467 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698