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

Side by Side Diff: chrome/browser/history/history_service.cc

Issue 642623004: Rename VisitDatabaseObserver to HistoryServiceObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@373326
Patch Set: Rebase Created 6 years, 2 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
« no previous file with comments | « chrome/browser/history/history_service.h ('k') | chrome/browser/history/history_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The history system runs on a background thread so that potentially slow 5 // The history system runs on a background thread so that potentially slow
6 // database operations don't delay the browser. This backend processing is 6 // database operations don't delay the browser. This backend processing is
7 // represented by HistoryBackend. The HistoryService's job is to dispatch to 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to
8 // that thread. 8 // that thread.
9 // 9 //
10 // Main thread History thread 10 // Main thread History thread
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/browser/history/web_history_service.h" 43 #include "chrome/browser/history/web_history_service.h"
44 #include "chrome/browser/history/web_history_service_factory.h" 44 #include "chrome/browser/history/web_history_service_factory.h"
45 #include "chrome/browser/profiles/profile.h" 45 #include "chrome/browser/profiles/profile.h"
46 #include "chrome/common/chrome_constants.h" 46 #include "chrome/common/chrome_constants.h"
47 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
48 #include "chrome/common/importer/imported_favicon_usage.h" 48 #include "chrome/common/importer/imported_favicon_usage.h"
49 #include "chrome/common/pref_names.h" 49 #include "chrome/common/pref_names.h"
50 #include "chrome/common/url_constants.h" 50 #include "chrome/common/url_constants.h"
51 #include "components/dom_distiller/core/url_constants.h" 51 #include "components/dom_distiller/core/url_constants.h"
52 #include "components/history/core/browser/history_client.h" 52 #include "components/history/core/browser/history_client.h"
53 #include "components/history/core/browser/history_service_observer.h"
53 #include "components/history/core/browser/history_types.h" 54 #include "components/history/core/browser/history_types.h"
54 #include "components/history/core/browser/in_memory_database.h" 55 #include "components/history/core/browser/in_memory_database.h"
55 #include "components/history/core/browser/keyword_search_term.h" 56 #include "components/history/core/browser/keyword_search_term.h"
56 #include "components/history/core/common/thumbnail_score.h" 57 #include "components/history/core/common/thumbnail_score.h"
57 #include "components/visitedlink/browser/visitedlink_master.h" 58 #include "components/visitedlink/browser/visitedlink_master.h"
58 #include "content/public/browser/browser_thread.h" 59 #include "content/public/browser/browser_thread.h"
59 #include "content/public/browser/download_item.h" 60 #include "content/public/browser/download_item.h"
60 #include "content/public/browser/notification_service.h" 61 #include "content/public/browser/notification_service.h"
61 #include "sync/api/sync_error_factory.h" 62 #include "sync/api/sync_error_factory.h"
62 #include "third_party/skia/include/core/SkBitmap.h" 63 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 152
152 virtual void SetInMemoryBackend( 153 virtual void SetInMemoryBackend(
153 scoped_ptr<history::InMemoryHistoryBackend> backend) override { 154 scoped_ptr<history::InMemoryHistoryBackend> backend) override {
154 // Send the backend to the history service on the main thread. 155 // Send the backend to the history service on the main thread.
155 service_task_runner_->PostTask( 156 service_task_runner_->PostTask(
156 FROM_HERE, 157 FROM_HERE,
157 base::Bind(&HistoryService::SetInMemoryBackend, history_service_, 158 base::Bind(&HistoryService::SetInMemoryBackend, history_service_,
158 base::Passed(&backend))); 159 base::Passed(&backend)));
159 } 160 }
160 161
162 virtual void NotifyAddVisit(const history::BriefVisitInfo& info) override {
163 service_task_runner_->PostTask(
164 FROM_HERE,
165 base::Bind(&HistoryService::NotifyAddVisit, history_service_, info));
166 }
167
161 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) override { 168 virtual void NotifyFaviconChanged(const std::set<GURL>& urls) override {
162 // Send the notification to the history service on the main thread. 169 // Send the notification to the history service on the main thread.
163 service_task_runner_->PostTask( 170 service_task_runner_->PostTask(
164 FROM_HERE, 171 FROM_HERE,
165 base::Bind( 172 base::Bind(
166 &HistoryService::NotifyFaviconChanged, history_service_, urls)); 173 &HistoryService::NotifyFaviconChanged, history_service_, urls));
167 } 174 }
168 175
169 virtual void BroadcastNotifications( 176 virtual void BroadcastNotifications(
170 int type, 177 int type,
(...skipping 10 matching lines...) Expand all
181 base::Bind(&HistoryService::BroadcastNotificationsHelper, 188 base::Bind(&HistoryService::BroadcastNotificationsHelper,
182 history_service_, type, base::Passed(&details))); 189 history_service_, type, base::Passed(&details)));
183 } 190 }
184 191
185 virtual void DBLoaded() override { 192 virtual void DBLoaded() override {
186 service_task_runner_->PostTask( 193 service_task_runner_->PostTask(
187 FROM_HERE, 194 FROM_HERE,
188 base::Bind(&HistoryService::OnDBLoaded, history_service_)); 195 base::Bind(&HistoryService::OnDBLoaded, history_service_));
189 } 196 }
190 197
191 virtual void NotifyVisitDBObserversOnAddVisit(
192 const history::BriefVisitInfo& info) override {
193 service_task_runner_->PostTask(
194 FROM_HERE,
195 base::Bind(&HistoryService::NotifyVisitDBObserversOnAddVisit,
196 history_service_, info));
197 }
198
199 private: 198 private:
200 const base::WeakPtr<HistoryService> history_service_; 199 const base::WeakPtr<HistoryService> history_service_;
201 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; 200 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_;
202 Profile* const profile_; 201 Profile* const profile_;
203 }; 202 };
204 203
205 // The history thread is intentionally not a BrowserThread because the 204 // The history thread is intentionally not a BrowserThread because the
206 // sync integration unit tests depend on being able to create more than one 205 // sync integration unit tests depend on being able to create more than one
207 // history thread. 206 // history thread.
208 HistoryService::HistoryService() 207 HistoryService::HistoryService()
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 keyword_id, term); 326 keyword_id, term);
328 } 327 }
329 328
330 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { 329 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) {
331 DCHECK(thread_) << "History service being called after cleanup"; 330 DCHECK(thread_) << "History service being called after cleanup";
332 DCHECK(thread_checker_.CalledOnValidThread()); 331 DCHECK(thread_checker_.CalledOnValidThread());
333 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::URLsNoLongerBookmarked, 332 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::URLsNoLongerBookmarked,
334 urls); 333 urls);
335 } 334 }
336 335
336 void HistoryService::AddObserver(history::HistoryServiceObserver* observer) {
blundell 2014/10/14 06:53:32 DCHECK called on valid thread in these?
sdefresne 2014/10/14 08:20:58 Done.
337 observers_.AddObserver(observer);
338 }
339
340 void HistoryService::RemoveObserver(history::HistoryServiceObserver* observer) {
341 observers_.RemoveObserver(observer);
342 }
343
337 void HistoryService::ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, 344 void HistoryService::ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task,
338 base::CancelableTaskTracker* tracker) { 345 base::CancelableTaskTracker* tracker) {
339 DCHECK(thread_) << "History service being called after cleanup"; 346 DCHECK(thread_) << "History service being called after cleanup";
340 DCHECK(thread_checker_.CalledOnValidThread()); 347 DCHECK(thread_checker_.CalledOnValidThread());
341 base::CancelableTaskTracker::IsCanceledCallback is_canceled; 348 base::CancelableTaskTracker::IsCanceledCallback is_canceled;
342 tracker->NewTrackedTaskId(&is_canceled); 349 tracker->NewTrackedTaskId(&is_canceled);
343 // Use base::ThreadTaskRunnerHandler::Get() to get a message loop proxy to 350 // Use base::ThreadTaskRunnerHandler::Get() to get a message loop proxy to
344 // the current message loop so that we can forward the call to the method 351 // the current message loop so that we can forward the call to the method
345 // HistoryDBTask::DoneRunOnMainThread in the correct thread. 352 // HistoryDBTask::DoneRunOnMainThread in the correct thread.
346 thread_->message_loop_proxy()->PostTask( 353 thread_->message_loop_proxy()->PostTask(
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 content::Source<Profile>(profile_), 1221 content::Source<Profile>(profile_),
1215 content::Details<HistoryService>(this)); 1222 content::Details<HistoryService>(this));
1216 } 1223 }
1217 1224
1218 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { 1225 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) {
1219 DCHECK(thread_checker_.CalledOnValidThread()); 1226 DCHECK(thread_checker_.CalledOnValidThread());
1220 history::URLDatabase* db = InMemoryDatabase(); 1227 history::URLDatabase* db = InMemoryDatabase();
1221 return db && (db->GetRowForURL(url, url_row) != 0); 1228 return db && (db->GetRowForURL(url, url_row) != 0);
1222 } 1229 }
1223 1230
1224 void HistoryService::AddVisitDatabaseObserver( 1231 void HistoryService::NotifyAddVisit(const history::BriefVisitInfo& info) {
1225 history::VisitDatabaseObserver* observer) {
1226 DCHECK(thread_checker_.CalledOnValidThread()); 1232 DCHECK(thread_checker_.CalledOnValidThread());
1227 visit_database_observers_.AddObserver(observer); 1233 FOR_EACH_OBSERVER(
1228 } 1234 history::HistoryServiceObserver, observers_, OnAddVisit(this, info));
1229
1230 void HistoryService::RemoveVisitDatabaseObserver(
1231 history::VisitDatabaseObserver* observer) {
1232 DCHECK(thread_checker_.CalledOnValidThread());
1233 visit_database_observers_.RemoveObserver(observer);
1234 }
1235
1236 void HistoryService::NotifyVisitDBObserversOnAddVisit(
1237 const history::BriefVisitInfo& info) {
1238 DCHECK(thread_checker_.CalledOnValidThread());
1239 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_,
1240 OnAddVisit(info));
1241 } 1235 }
1242 1236
1243 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> 1237 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription>
1244 HistoryService::AddFaviconChangedCallback( 1238 HistoryService::AddFaviconChangedCallback(
1245 const HistoryService::OnFaviconChangedCallback& callback) { 1239 const HistoryService::OnFaviconChangedCallback& callback) {
1246 DCHECK(thread_checker_.CalledOnValidThread()); 1240 DCHECK(thread_checker_.CalledOnValidThread());
1247 return favicon_changed_callback_list_.Add(callback); 1241 return favicon_changed_callback_list_.Add(callback);
1248 } 1242 }
1249 1243
1250 void HistoryService::NotifyFaviconChanged( 1244 void HistoryService::NotifyFaviconChanged(
1251 const std::set<GURL>& changed_favicons) { 1245 const std::set<GURL>& changed_favicons) {
1252 DCHECK(thread_checker_.CalledOnValidThread()); 1246 DCHECK(thread_checker_.CalledOnValidThread());
1253 favicon_changed_callback_list_.Notify(changed_favicons); 1247 favicon_changed_callback_list_.Notify(changed_favicons);
1254 } 1248 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_service.h ('k') | chrome/browser/history/history_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698