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 // 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 24 matching lines...) Expand all Loading... |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "components/dom_distiller/core/url_constants.h" | 36 #include "components/dom_distiller/core/url_constants.h" |
37 #include "components/history/core/browser/download_row.h" | 37 #include "components/history/core/browser/download_row.h" |
38 #include "components/history/core/browser/history_client.h" | 38 #include "components/history/core/browser/history_client.h" |
39 #include "components/history/core/browser/history_database_params.h" | 39 #include "components/history/core/browser/history_database_params.h" |
40 #include "components/history/core/browser/history_service_observer.h" | 40 #include "components/history/core/browser/history_service_observer.h" |
41 #include "components/history/core/browser/history_types.h" | 41 #include "components/history/core/browser/history_types.h" |
42 #include "components/history/core/browser/in_memory_database.h" | 42 #include "components/history/core/browser/in_memory_database.h" |
43 #include "components/history/core/browser/keyword_search_term.h" | 43 #include "components/history/core/browser/keyword_search_term.h" |
44 #include "components/history/core/browser/visit_database.h" | 44 #include "components/history/core/browser/visit_database.h" |
| 45 #include "components/history/core/browser/visit_delegate.h" |
45 #include "components/history/core/browser/visit_filter.h" | 46 #include "components/history/core/browser/visit_filter.h" |
46 #include "components/history/core/browser/web_history_service.h" | 47 #include "components/history/core/browser/web_history_service.h" |
47 #include "components/history/core/common/thumbnail_score.h" | 48 #include "components/history/core/common/thumbnail_score.h" |
48 #include "components/visitedlink/browser/visitedlink_master.h" | |
49 #include "content/public/browser/browser_thread.h" | |
50 #include "content/public/browser/download_item.h" | |
51 #include "sync/api/sync_error_factory.h" | 49 #include "sync/api/sync_error_factory.h" |
52 #include "third_party/skia/include/core/SkBitmap.h" | 50 #include "third_party/skia/include/core/SkBitmap.h" |
53 | 51 |
54 using base::Time; | 52 using base::Time; |
55 using history::HistoryBackend; | 53 using history::HistoryBackend; |
56 using history::KeywordID; | 54 using history::KeywordID; |
57 | 55 |
58 namespace { | 56 namespace { |
59 | 57 |
60 static const char* kHistoryThreadName = "Chrome_HistoryThread"; | 58 static const char* kHistoryThreadName = "Chrome_HistoryThread"; |
(...skipping 14 matching lines...) Expand all Loading... |
75 const history::QueryURLResult* result) { | 73 const history::QueryURLResult* result) { |
76 callback.Run(result->success, result->row, result->visits); | 74 callback.Run(result->success, result->row, result->visits); |
77 } | 75 } |
78 | 76 |
79 void RunWithVisibleVisitCountToHostResult( | 77 void RunWithVisibleVisitCountToHostResult( |
80 const HistoryService::GetVisibleVisitCountToHostCallback& callback, | 78 const HistoryService::GetVisibleVisitCountToHostCallback& callback, |
81 const history::VisibleVisitCountToHostResult* result) { | 79 const history::VisibleVisitCountToHostResult* result) { |
82 callback.Run(result->success, result->count, result->first_visit); | 80 callback.Run(result->success, result->count, result->first_visit); |
83 } | 81 } |
84 | 82 |
85 // Extract history::URLRows into GURLs for VisitedLinkMaster. | |
86 class URLIteratorFromURLRows | |
87 : public visitedlink::VisitedLinkMaster::URLIterator { | |
88 public: | |
89 explicit URLIteratorFromURLRows(const history::URLRows& url_rows) | |
90 : itr_(url_rows.begin()), | |
91 end_(url_rows.end()) { | |
92 } | |
93 | |
94 const GURL& NextURL() override { return (itr_++)->url(); } | |
95 | |
96 bool HasNextURL() const override { return itr_ != end_; } | |
97 | |
98 private: | |
99 history::URLRows::const_iterator itr_; | |
100 history::URLRows::const_iterator end_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLRows); | |
103 }; | |
104 | |
105 // Callback from WebHistoryService::ExpireWebHistory(). | 83 // Callback from WebHistoryService::ExpireWebHistory(). |
106 void ExpireWebHistoryComplete(bool success) { | 84 void ExpireWebHistoryComplete(bool success) { |
107 // Ignore the result. | 85 // Ignore the result. |
108 // | 86 // |
109 // TODO(davidben): ExpireLocalAndRemoteHistoryBetween callback should not fire | 87 // TODO(davidben): ExpireLocalAndRemoteHistoryBetween callback should not fire |
110 // until this completes. | 88 // until this completes. |
111 } | 89 } |
112 | 90 |
113 } // namespace | 91 } // namespace |
114 | 92 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 private: | 185 private: |
208 const base::WeakPtr<HistoryService> history_service_; | 186 const base::WeakPtr<HistoryService> history_service_; |
209 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 187 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
210 }; | 188 }; |
211 | 189 |
212 // The history thread is intentionally not a BrowserThread because the | 190 // The history thread is intentionally not a BrowserThread because the |
213 // sync integration unit tests depend on being able to create more than one | 191 // sync integration unit tests depend on being able to create more than one |
214 // history thread. | 192 // history thread. |
215 HistoryService::HistoryService() | 193 HistoryService::HistoryService() |
216 : thread_(new base::Thread(kHistoryThreadName)), | 194 : thread_(new base::Thread(kHistoryThreadName)), |
217 history_client_(NULL), | 195 history_client_(nullptr), |
218 backend_loaded_(false), | 196 backend_loaded_(false), |
219 no_db_(false), | 197 no_db_(false), |
220 weak_ptr_factory_(this) { | 198 weak_ptr_factory_(this) { |
221 } | 199 } |
222 | 200 |
223 HistoryService::HistoryService( | 201 HistoryService::HistoryService( |
224 history::HistoryClient* history_client, Profile* profile) | 202 history::HistoryClient* history_client, |
| 203 scoped_ptr<history::VisitDelegate> visit_delegate) |
225 : thread_(new base::Thread(kHistoryThreadName)), | 204 : thread_(new base::Thread(kHistoryThreadName)), |
| 205 visit_delegate_(visit_delegate.Pass()), |
226 history_client_(history_client), | 206 history_client_(history_client), |
227 visitedlink_master_(new visitedlink::VisitedLinkMaster( | |
228 profile, this, true)), | |
229 backend_loaded_(false), | 207 backend_loaded_(false), |
230 no_db_(false), | 208 no_db_(false), |
231 weak_ptr_factory_(this) { | 209 weak_ptr_factory_(this) { |
232 } | 210 } |
233 | 211 |
234 HistoryService::~HistoryService() { | 212 HistoryService::~HistoryService() { |
235 DCHECK(thread_checker_.CalledOnValidThread()); | 213 DCHECK(thread_checker_.CalledOnValidThread()); |
236 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 214 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
237 Cleanup(); | 215 Cleanup(); |
238 } | 216 } |
239 | 217 |
240 bool HistoryService::BackendLoaded() { | 218 bool HistoryService::BackendLoaded() { |
241 DCHECK(thread_checker_.CalledOnValidThread()); | 219 DCHECK(thread_checker_.CalledOnValidThread()); |
242 return backend_loaded_; | 220 return backend_loaded_; |
243 } | 221 } |
244 | 222 |
245 void HistoryService::ClearCachedDataForContextID( | 223 void HistoryService::ClearCachedDataForContextID( |
246 history::ContextID context_id) { | 224 history::ContextID context_id) { |
247 DCHECK(thread_) << "History service being called after cleanup"; | 225 DCHECK(thread_) << "History service being called after cleanup"; |
248 DCHECK(thread_checker_.CalledOnValidThread()); | 226 DCHECK(thread_checker_.CalledOnValidThread()); |
249 ScheduleTask(PRIORITY_NORMAL, | 227 ScheduleTask(PRIORITY_NORMAL, |
250 base::Bind(&HistoryBackend::ClearCachedDataForContextID, | 228 base::Bind(&HistoryBackend::ClearCachedDataForContextID, |
251 history_backend_.get(), context_id)); | 229 history_backend_.get(), context_id)); |
252 } | 230 } |
253 | 231 |
254 history::URLDatabase* HistoryService::InMemoryDatabase() { | 232 history::URLDatabase* HistoryService::InMemoryDatabase() { |
255 DCHECK(thread_checker_.CalledOnValidThread()); | 233 DCHECK(thread_checker_.CalledOnValidThread()); |
256 return in_memory_backend_ ? in_memory_backend_->db() : NULL; | 234 return in_memory_backend_ ? in_memory_backend_->db() : nullptr; |
257 } | 235 } |
258 | 236 |
259 bool HistoryService::GetTypedCountForURL(const GURL& url, int* typed_count) { | 237 bool HistoryService::GetTypedCountForURL(const GURL& url, int* typed_count) { |
260 DCHECK(thread_checker_.CalledOnValidThread()); | 238 DCHECK(thread_checker_.CalledOnValidThread()); |
261 history::URLRow url_row; | 239 history::URLRow url_row; |
262 if (!GetRowForURL(url, &url_row)) | 240 if (!GetRowForURL(url, &url_row)) |
263 return false; | 241 return false; |
264 *typed_count = url_row.typed_count(); | 242 *typed_count = url_row.typed_count(); |
265 return true; | 243 return true; |
266 } | 244 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 history::HistoryAddPageArgs(url, time, context_id, nav_entry_id, referrer, | 375 history::HistoryAddPageArgs(url, time, context_id, nav_entry_id, referrer, |
398 redirects, transition, visit_source, | 376 redirects, transition, visit_source, |
399 did_replace_entry)); | 377 did_replace_entry)); |
400 } | 378 } |
401 | 379 |
402 void HistoryService::AddPage(const GURL& url, | 380 void HistoryService::AddPage(const GURL& url, |
403 base::Time time, | 381 base::Time time, |
404 history::VisitSource visit_source) { | 382 history::VisitSource visit_source) { |
405 DCHECK(thread_checker_.CalledOnValidThread()); | 383 DCHECK(thread_checker_.CalledOnValidThread()); |
406 AddPage( | 384 AddPage( |
407 history::HistoryAddPageArgs(url, time, NULL, 0, GURL(), | 385 history::HistoryAddPageArgs(url, time, nullptr, 0, GURL(), |
408 history::RedirectList(), | 386 history::RedirectList(), |
409 ui::PAGE_TRANSITION_LINK, | 387 ui::PAGE_TRANSITION_LINK, |
410 visit_source, false)); | 388 visit_source, false)); |
411 } | 389 } |
412 | 390 |
413 void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { | 391 void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { |
414 DCHECK(thread_) << "History service being called after cleanup"; | 392 DCHECK(thread_) << "History service being called after cleanup"; |
415 DCHECK(thread_checker_.CalledOnValidThread()); | 393 DCHECK(thread_checker_.CalledOnValidThread()); |
416 | 394 |
417 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a | 395 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a |
418 // large part of history (think iframes for ads) and we never display them in | 396 // large part of history (think iframes for ads) and we never display them in |
419 // history UI. We will still add manual subframes, which are ones the user | 397 // history UI. We will still add manual subframes, which are ones the user |
420 // has clicked on to get. | 398 // has clicked on to get. |
421 if (!CanAddURL(add_page_args.url)) | 399 if (!CanAddURL(add_page_args.url)) |
422 return; | 400 return; |
423 | 401 |
424 // Add link & all redirects to visited link list. | 402 // Inform VisitedDelegate of all links and redirects. |
425 if (visitedlink_master_) { | 403 if (visit_delegate_) { |
426 visitedlink_master_->AddURL(add_page_args.url); | |
427 | |
428 if (!add_page_args.redirects.empty()) { | 404 if (!add_page_args.redirects.empty()) { |
429 // We should not be asked to add a page in the middle of a redirect chain. | 405 // We should not be asked to add a page in the middle of a redirect chain, |
430 DCHECK_EQ(add_page_args.url, | 406 // and thus add_page_args.url should be the last element in the array |
431 add_page_args.redirects[add_page_args.redirects.size() - 1]); | 407 // add_page_args.redirects which mean we can use VisitDelegate::AddURLs() |
432 | 408 // with the whole array. |
433 // We need the !redirects.empty() condition above since size_t is unsigned | 409 DCHECK_EQ(add_page_args.url, add_page_args.redirects.back()); |
434 // and will wrap around when we subtract one from a 0 size. | 410 visit_delegate_->AddURLs(add_page_args.redirects); |
435 for (size_t i = 0; i < add_page_args.redirects.size() - 1; i++) | 411 } else { |
436 visitedlink_master_->AddURL(add_page_args.redirects[i]); | 412 visit_delegate_->AddURL(add_page_args.url); |
437 } | 413 } |
438 } | 414 } |
439 | 415 |
440 ScheduleTask(PRIORITY_NORMAL, | 416 ScheduleTask(PRIORITY_NORMAL, |
441 base::Bind(&HistoryBackend::AddPage, history_backend_.get(), | 417 base::Bind(&HistoryBackend::AddPage, history_backend_.get(), |
442 add_page_args)); | 418 add_page_args)); |
443 } | 419 } |
444 | 420 |
445 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, | 421 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, |
446 const base::string16& title) { | 422 const base::string16& title) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 int typed_count, | 456 int typed_count, |
481 Time last_visit, | 457 Time last_visit, |
482 bool hidden, | 458 bool hidden, |
483 history::VisitSource visit_source) { | 459 history::VisitSource visit_source) { |
484 DCHECK(thread_) << "History service being called after cleanup"; | 460 DCHECK(thread_) << "History service being called after cleanup"; |
485 DCHECK(thread_checker_.CalledOnValidThread()); | 461 DCHECK(thread_checker_.CalledOnValidThread()); |
486 // Filter out unwanted URLs. | 462 // Filter out unwanted URLs. |
487 if (!CanAddURL(url)) | 463 if (!CanAddURL(url)) |
488 return; | 464 return; |
489 | 465 |
490 // Add to the visited links system. | 466 // Inform VisitDelegate of the URL. |
491 if (visitedlink_master_) | 467 if (visit_delegate_) |
492 visitedlink_master_->AddURL(url); | 468 visit_delegate_->AddURL(url); |
493 | 469 |
494 history::URLRow row(url); | 470 history::URLRow row(url); |
495 row.set_title(title); | 471 row.set_title(title); |
496 row.set_visit_count(visit_count); | 472 row.set_visit_count(visit_count); |
497 row.set_typed_count(typed_count); | 473 row.set_typed_count(typed_count); |
498 row.set_last_visit(last_visit); | 474 row.set_last_visit(last_visit); |
499 row.set_hidden(hidden); | 475 row.set_hidden(hidden); |
500 | 476 |
501 history::URLRows rows; | 477 history::URLRows rows; |
502 rows.push_back(row); | 478 rows.push_back(row); |
503 | 479 |
504 ScheduleTask(PRIORITY_NORMAL, | 480 ScheduleTask(PRIORITY_NORMAL, |
505 base::Bind(&HistoryBackend::AddPagesWithDetails, | 481 base::Bind(&HistoryBackend::AddPagesWithDetails, |
506 history_backend_.get(), rows, visit_source)); | 482 history_backend_.get(), rows, visit_source)); |
507 } | 483 } |
508 | 484 |
509 void HistoryService::AddPagesWithDetails(const history::URLRows& info, | 485 void HistoryService::AddPagesWithDetails(const history::URLRows& info, |
510 history::VisitSource visit_source) { | 486 history::VisitSource visit_source) { |
511 DCHECK(thread_) << "History service being called after cleanup"; | 487 DCHECK(thread_) << "History service being called after cleanup"; |
512 DCHECK(thread_checker_.CalledOnValidThread()); | 488 DCHECK(thread_checker_.CalledOnValidThread()); |
513 // Add to the visited links system. | 489 |
514 if (visitedlink_master_) { | 490 // Inform the VisitDelegate of the URLs |
| 491 if (!info.empty() && visit_delegate_) { |
515 std::vector<GURL> urls; | 492 std::vector<GURL> urls; |
516 urls.reserve(info.size()); | 493 urls.reserve(info.size()); |
517 for (history::URLRows::const_iterator i = info.begin(); i != info.end(); | 494 for (const auto& row : info) |
518 ++i) | 495 urls.push_back(row.url()); |
519 urls.push_back(i->url()); | 496 visit_delegate_->AddURLs(urls); |
520 | |
521 visitedlink_master_->AddURLs(urls); | |
522 } | 497 } |
523 | 498 |
524 ScheduleTask(PRIORITY_NORMAL, | 499 ScheduleTask(PRIORITY_NORMAL, |
525 base::Bind(&HistoryBackend::AddPagesWithDetails, | 500 base::Bind(&HistoryBackend::AddPagesWithDetails, |
526 history_backend_.get(), info, visit_source)); | 501 history_backend_.get(), info, visit_source)); |
527 } | 502 } |
528 | 503 |
529 base::CancelableTaskTracker::TaskId HistoryService::GetFavicons( | 504 base::CancelableTaskTracker::TaskId HistoryService::GetFavicons( |
530 const std::vector<GURL>& icon_urls, | 505 const std::vector<GURL>& icon_urls, |
531 int icon_types, | 506 int icon_types, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 } | 718 } |
744 | 719 |
745 // Handle queries for a list of all downloads in the history database's | 720 // Handle queries for a list of all downloads in the history database's |
746 // 'downloads' table. | 721 // 'downloads' table. |
747 void HistoryService::QueryDownloads( | 722 void HistoryService::QueryDownloads( |
748 const DownloadQueryCallback& callback) { | 723 const DownloadQueryCallback& callback) { |
749 DCHECK(thread_) << "History service being called after cleanup"; | 724 DCHECK(thread_) << "History service being called after cleanup"; |
750 DCHECK(thread_checker_.CalledOnValidThread()); | 725 DCHECK(thread_checker_.CalledOnValidThread()); |
751 std::vector<history::DownloadRow>* rows = | 726 std::vector<history::DownloadRow>* rows = |
752 new std::vector<history::DownloadRow>(); | 727 new std::vector<history::DownloadRow>(); |
753 scoped_ptr<std::vector<history::DownloadRow> > scoped_rows(rows); | 728 scoped_ptr<std::vector<history::DownloadRow>> scoped_rows(rows); |
754 // Beware! The first Bind() does not simply |scoped_rows.get()| because | 729 // Beware! The first Bind() does not simply |scoped_rows.get()| because |
755 // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not | 730 // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not |
756 // guarantee that the first Bind's arguments are evaluated before the second | 731 // guarantee that the first Bind's arguments are evaluated before the second |
757 // Bind's arguments. | 732 // Bind's arguments. |
758 thread_->message_loop_proxy()->PostTaskAndReply( | 733 thread_->message_loop_proxy()->PostTaskAndReply( |
759 FROM_HERE, | 734 FROM_HERE, |
760 base::Bind(&HistoryBackend::QueryDownloads, history_backend_.get(), rows), | 735 base::Bind(&HistoryBackend::QueryDownloads, history_backend_.get(), rows), |
761 base::Bind(callback, base::Passed(&scoped_rows))); | 736 base::Bind(callback, base::Passed(&scoped_rows))); |
762 } | 737 } |
763 | 738 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 // reference from the history thread, ensuring everything works properly. | 904 // reference from the history thread, ensuring everything works properly. |
930 // | 905 // |
931 // TODO(ajwong): Cleanup HistoryBackend lifetime issues. | 906 // TODO(ajwong): Cleanup HistoryBackend lifetime issues. |
932 // See http://crbug.com/99767. | 907 // See http://crbug.com/99767. |
933 history_backend_->AddRef(); | 908 history_backend_->AddRef(); |
934 base::Closure closing_task = | 909 base::Closure closing_task = |
935 base::Bind(&HistoryBackend::Closing, history_backend_.get()); | 910 base::Bind(&HistoryBackend::Closing, history_backend_.get()); |
936 ScheduleTask(PRIORITY_NORMAL, closing_task); | 911 ScheduleTask(PRIORITY_NORMAL, closing_task); |
937 closing_task.Reset(); | 912 closing_task.Reset(); |
938 HistoryBackend* raw_ptr = history_backend_.get(); | 913 HistoryBackend* raw_ptr = history_backend_.get(); |
939 history_backend_ = NULL; | 914 history_backend_ = nullptr; |
940 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr); | 915 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr); |
941 } | 916 } |
942 | 917 |
943 // Delete the thread, which joins with the background thread. We defensively | 918 // Delete the thread, which joins with the background thread. We defensively |
944 // NULL the pointer before deleting it in case somebody tries to use it | 919 // nullptr the pointer before deleting it in case somebody tries to use it |
945 // during shutdown, but this shouldn't happen. | 920 // during shutdown, but this shouldn't happen. |
946 base::Thread* thread = thread_; | 921 base::Thread* thread = thread_; |
947 thread_ = NULL; | 922 thread_ = nullptr; |
948 delete thread; | 923 delete thread; |
949 } | 924 } |
950 | 925 |
951 void HistoryService::RebuildTable( | |
952 const scoped_refptr<URLEnumerator>& enumerator) { | |
953 DCHECK(thread_) << "History service being called after cleanup"; | |
954 DCHECK(thread_checker_.CalledOnValidThread()); | |
955 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::IterateURLs, | |
956 history_backend_.get(), enumerator)); | |
957 } | |
958 | |
959 bool HistoryService::Init( | 926 bool HistoryService::Init( |
960 bool no_db, | 927 bool no_db, |
961 const std::string& languages, | 928 const std::string& languages, |
962 const history::HistoryDatabaseParams& history_database_params) { | 929 const history::HistoryDatabaseParams& history_database_params) { |
963 DCHECK(thread_) << "History service being called after cleanup"; | 930 DCHECK(thread_) << "History service being called after cleanup"; |
964 DCHECK(thread_checker_.CalledOnValidThread()); | 931 DCHECK(thread_checker_.CalledOnValidThread()); |
965 base::Thread::Options options; | 932 base::Thread::Options options; |
966 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 933 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
967 if (!thread_->StartWithOptions(options)) { | 934 if (!thread_->StartWithOptions(options)) { |
968 Cleanup(); | 935 Cleanup(); |
(...skipping 15 matching lines...) Expand all Loading... |
984 scoped_refptr<HistoryBackend> backend(new HistoryBackend( | 951 scoped_refptr<HistoryBackend> backend(new HistoryBackend( |
985 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), | 952 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), |
986 base::ThreadTaskRunnerHandle::Get()), | 953 base::ThreadTaskRunnerHandle::Get()), |
987 history_client_)); | 954 history_client_)); |
988 history_backend_.swap(backend); | 955 history_backend_.swap(backend); |
989 | 956 |
990 ScheduleTask(PRIORITY_UI, | 957 ScheduleTask(PRIORITY_UI, |
991 base::Bind(&HistoryBackend::Init, history_backend_.get(), | 958 base::Bind(&HistoryBackend::Init, history_backend_.get(), |
992 languages, no_db_, history_database_params)); | 959 languages, no_db_, history_database_params)); |
993 | 960 |
994 if (visitedlink_master_) { | 961 if (visit_delegate_ && !visit_delegate_->Init(this)) |
995 bool result = visitedlink_master_->Init(); | 962 return false; |
996 DCHECK(result); | |
997 } | |
998 | 963 |
999 return true; | 964 return true; |
1000 } | 965 } |
1001 | 966 |
1002 void HistoryService::ScheduleAutocomplete(const base::Callback< | 967 void HistoryService::ScheduleAutocomplete(const base::Callback< |
1003 void(history::HistoryBackend*, history::URLDatabase*)>& callback) { | 968 void(history::HistoryBackend*, history::URLDatabase*)>& callback) { |
1004 DCHECK(thread_checker_.CalledOnValidThread()); | 969 DCHECK(thread_checker_.CalledOnValidThread()); |
1005 ScheduleTask(PRIORITY_UI, base::Bind(&HistoryBackend::ScheduleAutocomplete, | 970 ScheduleTask(PRIORITY_UI, base::Bind(&HistoryBackend::ScheduleAutocomplete, |
1006 history_backend_.get(), callback)); | 971 history_backend_.get(), callback)); |
1007 } | 972 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 } | 1178 } |
1214 | 1179 |
1215 void HistoryService::NotifyURLsDeleted(bool all_history, | 1180 void HistoryService::NotifyURLsDeleted(bool all_history, |
1216 bool expired, | 1181 bool expired, |
1217 const history::URLRows& deleted_rows, | 1182 const history::URLRows& deleted_rows, |
1218 const std::set<GURL>& favicon_urls) { | 1183 const std::set<GURL>& favicon_urls) { |
1219 DCHECK(thread_checker_.CalledOnValidThread()); | 1184 DCHECK(thread_checker_.CalledOnValidThread()); |
1220 if (!thread_) | 1185 if (!thread_) |
1221 return; | 1186 return; |
1222 | 1187 |
1223 // Update the visited link system for deleted URLs. We will update the | 1188 // Inform the VisitDelegate of the deleted URLs. We will inform the delegate |
1224 // visited link system for added URLs as soon as we get the add | 1189 // of added URLs as soon as we get the add notification (we don't have to wait |
1225 // notification (we don't have to wait for the backend, which allows us to | 1190 // for the backend, which allows us to be faster to update the state). |
1226 // be faster to update the state). | |
1227 // | 1191 // |
1228 // For deleted URLs, we don't typically know what will be deleted since | 1192 // For deleted URLs, we don't typically know what will be deleted since |
1229 // delete notifications are by time. We would also like to be more | 1193 // delete notifications are by time. We would also like to be more |
1230 // respectful of privacy and never tell the user something is gone when it | 1194 // respectful of privacy and never tell the user something is gone when it |
1231 // isn't. Therefore, we update the delete URLs after the fact. | 1195 // isn't. Therefore, we update the delete URLs after the fact. |
1232 if (visitedlink_master_) { | 1196 if (visit_delegate_) { |
1233 if (all_history) { | 1197 if (all_history) { |
1234 visitedlink_master_->DeleteAllURLs(); | 1198 visit_delegate_->DeleteAllURLs(); |
1235 } else { | 1199 } else { |
1236 URLIteratorFromURLRows iterator(deleted_rows); | 1200 std::vector<GURL> urls; |
1237 visitedlink_master_->DeleteURLs(&iterator); | 1201 urls.reserve(deleted_rows.size()); |
| 1202 for (const auto& row : deleted_rows) |
| 1203 urls.push_back(row.url()); |
| 1204 visit_delegate_->DeleteURLs(urls); |
1238 } | 1205 } |
1239 } | 1206 } |
1240 | 1207 |
1241 FOR_EACH_OBSERVER( | 1208 FOR_EACH_OBSERVER( |
1242 history::HistoryServiceObserver, observers_, | 1209 history::HistoryServiceObserver, observers_, |
1243 OnURLsDeleted(this, all_history, expired, deleted_rows, favicon_urls)); | 1210 OnURLsDeleted(this, all_history, expired, deleted_rows, favicon_urls)); |
1244 } | 1211 } |
1245 | 1212 |
1246 void HistoryService::NotifyHistoryServiceLoaded() { | 1213 void HistoryService::NotifyHistoryServiceLoaded() { |
1247 DCHECK(thread_checker_.CalledOnValidThread()); | 1214 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 27 matching lines...) Expand all Loading... |
1275 const HistoryService::OnFaviconChangedCallback& callback) { | 1242 const HistoryService::OnFaviconChangedCallback& callback) { |
1276 DCHECK(thread_checker_.CalledOnValidThread()); | 1243 DCHECK(thread_checker_.CalledOnValidThread()); |
1277 return favicon_changed_callback_list_.Add(callback); | 1244 return favicon_changed_callback_list_.Add(callback); |
1278 } | 1245 } |
1279 | 1246 |
1280 void HistoryService::NotifyFaviconChanged( | 1247 void HistoryService::NotifyFaviconChanged( |
1281 const std::set<GURL>& changed_favicons) { | 1248 const std::set<GURL>& changed_favicons) { |
1282 DCHECK(thread_checker_.CalledOnValidThread()); | 1249 DCHECK(thread_checker_.CalledOnValidThread()); |
1283 favicon_changed_callback_list_.Notify(changed_favicons); | 1250 favicon_changed_callback_list_.Notify(changed_favicons); |
1284 } | 1251 } |
OLD | NEW |