| 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 13 matching lines...) Expand all Loading... |
| 24 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
| 25 #include "base/location.h" | 25 #include "base/location.h" |
| 26 #include "base/memory/ref_counted.h" | 26 #include "base/memory/ref_counted.h" |
| 27 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
| 28 #include "base/thread_task_runner_handle.h" | 28 #include "base/thread_task_runner_handle.h" |
| 29 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
| 30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 31 #include "chrome/browser/history/history_backend.h" | 31 #include "chrome/browser/history/history_backend.h" |
| 32 #include "chrome/browser/history/in_memory_history_backend.h" | 32 #include "chrome/browser/history/in_memory_history_backend.h" |
| 33 #include "chrome/browser/history/in_memory_url_index.h" | 33 #include "chrome/browser/history/in_memory_url_index.h" |
| 34 #include "chrome/common/url_constants.h" | |
| 35 #include "components/dom_distiller/core/url_constants.h" | |
| 36 #include "components/history/core/browser/download_row.h" | 34 #include "components/history/core/browser/download_row.h" |
| 37 #include "components/history/core/browser/history_client.h" | 35 #include "components/history/core/browser/history_client.h" |
| 38 #include "components/history/core/browser/history_database_params.h" | 36 #include "components/history/core/browser/history_database_params.h" |
| 39 #include "components/history/core/browser/history_service_observer.h" | 37 #include "components/history/core/browser/history_service_observer.h" |
| 40 #include "components/history/core/browser/history_types.h" | 38 #include "components/history/core/browser/history_types.h" |
| 41 #include "components/history/core/browser/in_memory_database.h" | 39 #include "components/history/core/browser/in_memory_database.h" |
| 42 #include "components/history/core/browser/keyword_search_term.h" | 40 #include "components/history/core/browser/keyword_search_term.h" |
| 43 #include "components/history/core/browser/visit_database.h" | 41 #include "components/history/core/browser/visit_database.h" |
| 44 #include "components/history/core/browser/visit_delegate.h" | 42 #include "components/history/core/browser/visit_delegate.h" |
| 45 #include "components/history/core/browser/visit_filter.h" | 43 #include "components/history/core/browser/visit_filter.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 387 } |
| 390 | 388 |
| 391 void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { | 389 void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { |
| 392 DCHECK(thread_) << "History service being called after cleanup"; | 390 DCHECK(thread_) << "History service being called after cleanup"; |
| 393 DCHECK(thread_checker_.CalledOnValidThread()); | 391 DCHECK(thread_checker_.CalledOnValidThread()); |
| 394 | 392 |
| 395 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a | 393 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a |
| 396 // large part of history (think iframes for ads) and we never display them in | 394 // large part of history (think iframes for ads) and we never display them in |
| 397 // history UI. We will still add manual subframes, which are ones the user | 395 // history UI. We will still add manual subframes, which are ones the user |
| 398 // has clicked on to get. | 396 // has clicked on to get. |
| 399 if (!CanAddURL(add_page_args.url)) | 397 if (history_client_ && !history_client_->CanAddURL(add_page_args.url)) |
| 400 return; | 398 return; |
| 401 | 399 |
| 402 // Inform VisitedDelegate of all links and redirects. | 400 // Inform VisitedDelegate of all links and redirects. |
| 403 if (visit_delegate_) { | 401 if (visit_delegate_) { |
| 404 if (!add_page_args.redirects.empty()) { | 402 if (!add_page_args.redirects.empty()) { |
| 405 // We should not be asked to add a page in the middle of a redirect chain, | 403 // We should not be asked to add a page in the middle of a redirect chain, |
| 406 // and thus add_page_args.url should be the last element in the array | 404 // and thus add_page_args.url should be the last element in the array |
| 407 // add_page_args.redirects which mean we can use VisitDelegate::AddURLs() | 405 // add_page_args.redirects which mean we can use VisitDelegate::AddURLs() |
| 408 // with the whole array. | 406 // with the whole array. |
| 409 DCHECK_EQ(add_page_args.url, add_page_args.redirects.back()); | 407 DCHECK_EQ(add_page_args.url, add_page_args.redirects.back()); |
| 410 visit_delegate_->AddURLs(add_page_args.redirects); | 408 visit_delegate_->AddURLs(add_page_args.redirects); |
| 411 } else { | 409 } else { |
| 412 visit_delegate_->AddURL(add_page_args.url); | 410 visit_delegate_->AddURL(add_page_args.url); |
| 413 } | 411 } |
| 414 } | 412 } |
| 415 | 413 |
| 416 ScheduleTask(PRIORITY_NORMAL, | 414 ScheduleTask(PRIORITY_NORMAL, |
| 417 base::Bind(&HistoryBackend::AddPage, history_backend_.get(), | 415 base::Bind(&HistoryBackend::AddPage, history_backend_.get(), |
| 418 add_page_args)); | 416 add_page_args)); |
| 419 } | 417 } |
| 420 | 418 |
| 421 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, | 419 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, |
| 422 const base::string16& title) { | 420 const base::string16& title) { |
| 423 DCHECK(thread_) << "History service being called after cleanup"; | 421 DCHECK(thread_) << "History service being called after cleanup"; |
| 424 DCHECK(thread_checker_.CalledOnValidThread()); | 422 DCHECK(thread_checker_.CalledOnValidThread()); |
| 425 if (!CanAddURL(url)) | 423 if (history_client_ && !history_client_->CanAddURL(url)) |
| 426 return; | 424 return; |
| 427 | 425 |
| 428 ScheduleTask(PRIORITY_NORMAL, | 426 ScheduleTask(PRIORITY_NORMAL, |
| 429 base::Bind(&HistoryBackend::AddPageNoVisitForBookmark, | 427 base::Bind(&HistoryBackend::AddPageNoVisitForBookmark, |
| 430 history_backend_.get(), url, title)); | 428 history_backend_.get(), url, title)); |
| 431 } | 429 } |
| 432 | 430 |
| 433 void HistoryService::SetPageTitle(const GURL& url, | 431 void HistoryService::SetPageTitle(const GURL& url, |
| 434 const base::string16& title) { | 432 const base::string16& title) { |
| 435 DCHECK(thread_) << "History service being called after cleanup"; | 433 DCHECK(thread_) << "History service being called after cleanup"; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 453 void HistoryService::AddPageWithDetails(const GURL& url, | 451 void HistoryService::AddPageWithDetails(const GURL& url, |
| 454 const base::string16& title, | 452 const base::string16& title, |
| 455 int visit_count, | 453 int visit_count, |
| 456 int typed_count, | 454 int typed_count, |
| 457 Time last_visit, | 455 Time last_visit, |
| 458 bool hidden, | 456 bool hidden, |
| 459 history::VisitSource visit_source) { | 457 history::VisitSource visit_source) { |
| 460 DCHECK(thread_) << "History service being called after cleanup"; | 458 DCHECK(thread_) << "History service being called after cleanup"; |
| 461 DCHECK(thread_checker_.CalledOnValidThread()); | 459 DCHECK(thread_checker_.CalledOnValidThread()); |
| 462 // Filter out unwanted URLs. | 460 // Filter out unwanted URLs. |
| 463 if (!CanAddURL(url)) | 461 if (history_client_ && !history_client_->CanAddURL(url)) |
| 464 return; | 462 return; |
| 465 | 463 |
| 466 // Inform VisitDelegate of the URL. | 464 // Inform VisitDelegate of the URL. |
| 467 if (visit_delegate_) | 465 if (visit_delegate_) |
| 468 visit_delegate_->AddURL(url); | 466 visit_delegate_->AddURL(url); |
| 469 | 467 |
| 470 history::URLRow row(url); | 468 history::URLRow row(url); |
| 471 row.set_title(title); | 469 row.set_title(title); |
| 472 row.set_visit_count(visit_count); | 470 row.set_visit_count(visit_count); |
| 473 row.set_typed_count(typed_count); | 471 row.set_typed_count(typed_count); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 } | 611 } |
| 614 | 612 |
| 615 void HistoryService::MergeFavicon( | 613 void HistoryService::MergeFavicon( |
| 616 const GURL& page_url, | 614 const GURL& page_url, |
| 617 const GURL& icon_url, | 615 const GURL& icon_url, |
| 618 favicon_base::IconType icon_type, | 616 favicon_base::IconType icon_type, |
| 619 scoped_refptr<base::RefCountedMemory> bitmap_data, | 617 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 620 const gfx::Size& pixel_size) { | 618 const gfx::Size& pixel_size) { |
| 621 DCHECK(thread_) << "History service being called after cleanup"; | 619 DCHECK(thread_) << "History service being called after cleanup"; |
| 622 DCHECK(thread_checker_.CalledOnValidThread()); | 620 DCHECK(thread_checker_.CalledOnValidThread()); |
| 623 if (!CanAddURL(page_url)) | 621 if (history_client_ && !history_client_->CanAddURL(page_url)) |
| 624 return; | 622 return; |
| 625 | 623 |
| 626 ScheduleTask( | 624 ScheduleTask( |
| 627 PRIORITY_NORMAL, | 625 PRIORITY_NORMAL, |
| 628 base::Bind(&HistoryBackend::MergeFavicon, history_backend_.get(), | 626 base::Bind(&HistoryBackend::MergeFavicon, history_backend_.get(), |
| 629 page_url, icon_url, icon_type, bitmap_data, pixel_size)); | 627 page_url, icon_url, icon_type, bitmap_data, pixel_size)); |
| 630 } | 628 } |
| 631 | 629 |
| 632 void HistoryService::SetFavicons( | 630 void HistoryService::SetFavicons( |
| 633 const GURL& page_url, | 631 const GURL& page_url, |
| 634 favicon_base::IconType icon_type, | 632 favicon_base::IconType icon_type, |
| 635 const GURL& icon_url, | 633 const GURL& icon_url, |
| 636 const std::vector<SkBitmap>& bitmaps) { | 634 const std::vector<SkBitmap>& bitmaps) { |
| 637 DCHECK(thread_) << "History service being called after cleanup"; | 635 DCHECK(thread_) << "History service being called after cleanup"; |
| 638 DCHECK(thread_checker_.CalledOnValidThread()); | 636 DCHECK(thread_checker_.CalledOnValidThread()); |
| 639 if (!CanAddURL(page_url)) | 637 if (history_client_ && !history_client_->CanAddURL(page_url)) |
| 640 return; | 638 return; |
| 641 | 639 |
| 642 ScheduleTask(PRIORITY_NORMAL, | 640 ScheduleTask(PRIORITY_NORMAL, |
| 643 base::Bind(&HistoryBackend::SetFavicons, history_backend_.get(), | 641 base::Bind(&HistoryBackend::SetFavicons, history_backend_.get(), |
| 644 page_url, icon_type, icon_url, bitmaps)); | 642 page_url, icon_type, icon_url, bitmaps)); |
| 645 } | 643 } |
| 646 | 644 |
| 647 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 645 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
| 648 DCHECK(thread_) << "History service being called after cleanup"; | 646 DCHECK(thread_) << "History service being called after cleanup"; |
| 649 DCHECK(thread_checker_.CalledOnValidThread()); | 647 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 | 968 |
| 971 void HistoryService::ScheduleTask(SchedulePriority priority, | 969 void HistoryService::ScheduleTask(SchedulePriority priority, |
| 972 const base::Closure& task) { | 970 const base::Closure& task) { |
| 973 DCHECK(thread_checker_.CalledOnValidThread()); | 971 DCHECK(thread_checker_.CalledOnValidThread()); |
| 974 CHECK(thread_); | 972 CHECK(thread_); |
| 975 CHECK(thread_->message_loop()); | 973 CHECK(thread_->message_loop()); |
| 976 // TODO(brettw): Do prioritization. | 974 // TODO(brettw): Do prioritization. |
| 977 thread_->message_loop()->PostTask(FROM_HERE, task); | 975 thread_->message_loop()->PostTask(FROM_HERE, task); |
| 978 } | 976 } |
| 979 | 977 |
| 980 // static | |
| 981 bool HistoryService::CanAddURL(const GURL& url) { | |
| 982 if (!url.is_valid()) | |
| 983 return false; | |
| 984 | |
| 985 // TODO: We should allow kChromeUIScheme URLs if they have been explicitly | |
| 986 // typed. Right now, however, these are marked as typed even when triggered | |
| 987 // by a shortcut or menu action. | |
| 988 if (url.SchemeIs(url::kJavaScriptScheme) || | |
| 989 url.SchemeIs(content::kChromeDevToolsScheme) || | |
| 990 url.SchemeIs(content::kChromeUIScheme) || | |
| 991 url.SchemeIs(content::kViewSourceScheme) || | |
| 992 url.SchemeIs(chrome::kChromeNativeScheme) || | |
| 993 url.SchemeIs(chrome::kChromeSearchScheme) || | |
| 994 url.SchemeIs(dom_distiller::kDomDistillerScheme)) | |
| 995 return false; | |
| 996 | |
| 997 // Allow all about: and chrome: URLs except about:blank, since the user may | |
| 998 // like to see "chrome://memory/", etc. in their history and autocomplete. | |
| 999 if (url == GURL(url::kAboutBlankURL)) | |
| 1000 return false; | |
| 1001 | |
| 1002 return true; | |
| 1003 } | |
| 1004 | |
| 1005 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { | 978 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { |
| 1006 DCHECK(thread_checker_.CalledOnValidThread()); | 979 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1007 return weak_ptr_factory_.GetWeakPtr(); | 980 return weak_ptr_factory_.GetWeakPtr(); |
| 1008 } | 981 } |
| 1009 | 982 |
| 1010 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( | 983 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( |
| 1011 syncer::ModelType type, | 984 syncer::ModelType type, |
| 1012 const syncer::SyncDataList& initial_sync_data, | 985 const syncer::SyncDataList& initial_sync_data, |
| 1013 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 986 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 1014 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 987 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 const HistoryService::OnFaviconChangedCallback& callback) { | 1212 const HistoryService::OnFaviconChangedCallback& callback) { |
| 1240 DCHECK(thread_checker_.CalledOnValidThread()); | 1213 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1241 return favicon_changed_callback_list_.Add(callback); | 1214 return favicon_changed_callback_list_.Add(callback); |
| 1242 } | 1215 } |
| 1243 | 1216 |
| 1244 void HistoryService::NotifyFaviconChanged( | 1217 void HistoryService::NotifyFaviconChanged( |
| 1245 const std::set<GURL>& changed_favicons) { | 1218 const std::set<GURL>& changed_favicons) { |
| 1246 DCHECK(thread_checker_.CalledOnValidThread()); | 1219 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1247 favicon_changed_callback_list_.Notify(changed_favicons); | 1220 favicon_changed_callback_list_.Notify(changed_favicons); |
| 1248 } | 1221 } |
| OLD | NEW |