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