| 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 12 matching lines...) Expand all Loading... |
| 23 #include "base/command_line.h" | 23 #include "base/command_line.h" |
| 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/common/url_constants.h" | |
| 34 #include "components/dom_distiller/core/url_constants.h" | |
| 35 #include "components/history/core/browser/download_row.h" | 33 #include "components/history/core/browser/download_row.h" |
| 36 #include "components/history/core/browser/history_client.h" | 34 #include "components/history/core/browser/history_client.h" |
| 37 #include "components/history/core/browser/history_database_params.h" | 35 #include "components/history/core/browser/history_database_params.h" |
| 38 #include "components/history/core/browser/history_db_task.h" | 36 #include "components/history/core/browser/history_db_task.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" |
| (...skipping 344 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 | 955 |
| 958 void HistoryService::ScheduleTask(SchedulePriority priority, | 956 void HistoryService::ScheduleTask(SchedulePriority priority, |
| 959 const base::Closure& task) { | 957 const base::Closure& task) { |
| 960 DCHECK(thread_checker_.CalledOnValidThread()); | 958 DCHECK(thread_checker_.CalledOnValidThread()); |
| 961 CHECK(thread_); | 959 CHECK(thread_); |
| 962 CHECK(thread_->message_loop()); | 960 CHECK(thread_->message_loop()); |
| 963 // TODO(brettw): Do prioritization. | 961 // TODO(brettw): Do prioritization. |
| 964 thread_->message_loop()->PostTask(FROM_HERE, task); | 962 thread_->message_loop()->PostTask(FROM_HERE, task); |
| 965 } | 963 } |
| 966 | 964 |
| 967 // static | |
| 968 bool HistoryService::CanAddURL(const GURL& url) { | |
| 969 if (!url.is_valid()) | |
| 970 return false; | |
| 971 | |
| 972 // TODO: We should allow kChromeUIScheme URLs if they have been explicitly | |
| 973 // typed. Right now, however, these are marked as typed even when triggered | |
| 974 // by a shortcut or menu action. | |
| 975 if (url.SchemeIs(url::kJavaScriptScheme) || | |
| 976 url.SchemeIs(content::kChromeDevToolsScheme) || | |
| 977 url.SchemeIs(content::kChromeUIScheme) || | |
| 978 url.SchemeIs(content::kViewSourceScheme) || | |
| 979 url.SchemeIs(chrome::kChromeNativeScheme) || | |
| 980 url.SchemeIs(chrome::kChromeSearchScheme) || | |
| 981 url.SchemeIs(dom_distiller::kDomDistillerScheme)) | |
| 982 return false; | |
| 983 | |
| 984 // Allow all about: and chrome: URLs except about:blank, since the user may | |
| 985 // like to see "chrome://memory/", etc. in their history and autocomplete. | |
| 986 if (url == GURL(url::kAboutBlankURL)) | |
| 987 return false; | |
| 988 | |
| 989 return true; | |
| 990 } | |
| 991 | |
| 992 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { | 965 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { |
| 993 DCHECK(thread_checker_.CalledOnValidThread()); | 966 DCHECK(thread_checker_.CalledOnValidThread()); |
| 994 return weak_ptr_factory_.GetWeakPtr(); | 967 return weak_ptr_factory_.GetWeakPtr(); |
| 995 } | 968 } |
| 996 | 969 |
| 997 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( | 970 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( |
| 998 syncer::ModelType type, | 971 syncer::ModelType type, |
| 999 const syncer::SyncDataList& initial_sync_data, | 972 const syncer::SyncDataList& initial_sync_data, |
| 1000 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 973 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 1001 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 974 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 const HistoryService::OnFaviconChangedCallback& callback) { | 1199 const HistoryService::OnFaviconChangedCallback& callback) { |
| 1227 DCHECK(thread_checker_.CalledOnValidThread()); | 1200 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1228 return favicon_changed_callback_list_.Add(callback); | 1201 return favicon_changed_callback_list_.Add(callback); |
| 1229 } | 1202 } |
| 1230 | 1203 |
| 1231 void HistoryService::NotifyFaviconChanged( | 1204 void HistoryService::NotifyFaviconChanged( |
| 1232 const std::set<GURL>& changed_favicons) { | 1205 const std::set<GURL>& changed_favicons) { |
| 1233 DCHECK(thread_checker_.CalledOnValidThread()); | 1206 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1234 favicon_changed_callback_list_.Notify(changed_favicons); | 1207 favicon_changed_callback_list_.Notify(changed_favicons); |
| 1235 } | 1208 } |
| OLD | NEW |