| 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 19 matching lines...) Expand all Loading... |
| 30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
| 31 #include "base/time/time.h" | 31 #include "base/time/time.h" |
| 32 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/history/download_row.h" | 34 #include "chrome/browser/history/download_row.h" |
| 35 #include "chrome/browser/history/history_backend.h" | 35 #include "chrome/browser/history/history_backend.h" |
| 36 #include "chrome/browser/history/history_notifications.h" | 36 #include "chrome/browser/history/history_notifications.h" |
| 37 #include "chrome/browser/history/in_memory_history_backend.h" | 37 #include "chrome/browser/history/in_memory_history_backend.h" |
| 38 #include "chrome/browser/history/in_memory_url_index.h" | 38 #include "chrome/browser/history/in_memory_url_index.h" |
| 39 #include "chrome/browser/history/top_sites.h" | 39 #include "chrome/browser/history/top_sites.h" |
| 40 #include "chrome/browser/history/url_utils.h" |
| 40 #include "chrome/browser/history/visit_database.h" | 41 #include "chrome/browser/history/visit_database.h" |
| 41 #include "chrome/browser/history/visit_filter.h" | 42 #include "chrome/browser/history/visit_filter.h" |
| 42 #include "chrome/browser/history/web_history_service.h" | 43 #include "chrome/browser/history/web_history_service.h" |
| 43 #include "chrome/browser/history/web_history_service_factory.h" | 44 #include "chrome/browser/history/web_history_service_factory.h" |
| 44 #include "chrome/browser/profiles/profile.h" | 45 #include "chrome/browser/profiles/profile.h" |
| 45 #include "chrome/common/chrome_constants.h" | |
| 46 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/importer/imported_favicon_usage.h" | 47 #include "chrome/common/importer/imported_favicon_usage.h" |
| 48 #include "chrome/common/pref_names.h" | 48 #include "chrome/common/pref_names.h" |
| 49 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
| 50 #include "components/dom_distiller/core/url_constants.h" | 50 #include "components/dom_distiller/core/url_constants.h" |
| 51 #include "components/history/core/browser/history_client.h" | 51 #include "components/history/core/browser/history_client.h" |
| 52 #include "components/history/core/browser/history_service_observer.h" | 52 #include "components/history/core/browser/history_service_observer.h" |
| 53 #include "components/history/core/browser/history_types.h" | 53 #include "components/history/core/browser/history_types.h" |
| 54 #include "components/history/core/browser/in_memory_database.h" | 54 #include "components/history/core/browser/in_memory_database.h" |
| 55 #include "components/history/core/browser/keyword_search_term.h" | 55 #include "components/history/core/browser/keyword_search_term.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 417 } |
| 418 | 418 |
| 419 void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { | 419 void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { |
| 420 DCHECK(thread_) << "History service being called after cleanup"; | 420 DCHECK(thread_) << "History service being called after cleanup"; |
| 421 DCHECK(thread_checker_.CalledOnValidThread()); | 421 DCHECK(thread_checker_.CalledOnValidThread()); |
| 422 | 422 |
| 423 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a | 423 // 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 | 424 // 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 | 425 // history UI. We will still add manual subframes, which are ones the user |
| 426 // has clicked on to get. | 426 // has clicked on to get. |
| 427 if (!CanAddURL(add_page_args.url)) | 427 if (!history::CanAddURL(add_page_args.url)) |
| 428 return; | 428 return; |
| 429 | 429 |
| 430 // Add link & all redirects to visited link list. | 430 // Add link & all redirects to visited link list. |
| 431 if (visitedlink_master_) { | 431 if (visitedlink_master_) { |
| 432 visitedlink_master_->AddURL(add_page_args.url); | 432 visitedlink_master_->AddURL(add_page_args.url); |
| 433 | 433 |
| 434 if (!add_page_args.redirects.empty()) { | 434 if (!add_page_args.redirects.empty()) { |
| 435 // We should not be asked to add a page in the middle of a redirect chain. | 435 // We should not be asked to add a page in the middle of a redirect chain. |
| 436 DCHECK_EQ(add_page_args.url, | 436 DCHECK_EQ(add_page_args.url, |
| 437 add_page_args.redirects[add_page_args.redirects.size() - 1]); | 437 add_page_args.redirects[add_page_args.redirects.size() - 1]); |
| 438 | 438 |
| 439 // We need the !redirects.empty() condition above since size_t is unsigned | 439 // 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. | 440 // and will wrap around when we subtract one from a 0 size. |
| 441 for (size_t i = 0; i < add_page_args.redirects.size() - 1; i++) | 441 for (size_t i = 0; i < add_page_args.redirects.size() - 1; i++) |
| 442 visitedlink_master_->AddURL(add_page_args.redirects[i]); | 442 visitedlink_master_->AddURL(add_page_args.redirects[i]); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::AddPage, add_page_args); | 446 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::AddPage, add_page_args); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, | 449 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, |
| 450 const base::string16& title) { | 450 const base::string16& title) { |
| 451 DCHECK(thread_) << "History service being called after cleanup"; | 451 DCHECK(thread_) << "History service being called after cleanup"; |
| 452 DCHECK(thread_checker_.CalledOnValidThread()); | 452 DCHECK(thread_checker_.CalledOnValidThread()); |
| 453 if (!CanAddURL(url)) | 453 if (!history::CanAddURL(url)) |
| 454 return; | 454 return; |
| 455 | 455 |
| 456 ScheduleAndForget(PRIORITY_NORMAL, | 456 ScheduleAndForget(PRIORITY_NORMAL, |
| 457 &HistoryBackend::AddPageNoVisitForBookmark, url, title); | 457 &HistoryBackend::AddPageNoVisitForBookmark, url, title); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void HistoryService::SetPageTitle(const GURL& url, | 460 void HistoryService::SetPageTitle(const GURL& url, |
| 461 const base::string16& title) { | 461 const base::string16& title) { |
| 462 DCHECK(thread_) << "History service being called after cleanup"; | 462 DCHECK(thread_) << "History service being called after cleanup"; |
| 463 DCHECK(thread_checker_.CalledOnValidThread()); | 463 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 477 void HistoryService::AddPageWithDetails(const GURL& url, | 477 void HistoryService::AddPageWithDetails(const GURL& url, |
| 478 const base::string16& title, | 478 const base::string16& title, |
| 479 int visit_count, | 479 int visit_count, |
| 480 int typed_count, | 480 int typed_count, |
| 481 Time last_visit, | 481 Time last_visit, |
| 482 bool hidden, | 482 bool hidden, |
| 483 history::VisitSource visit_source) { | 483 history::VisitSource visit_source) { |
| 484 DCHECK(thread_) << "History service being called after cleanup"; | 484 DCHECK(thread_) << "History service being called after cleanup"; |
| 485 DCHECK(thread_checker_.CalledOnValidThread()); | 485 DCHECK(thread_checker_.CalledOnValidThread()); |
| 486 // Filter out unwanted URLs. | 486 // Filter out unwanted URLs. |
| 487 if (!CanAddURL(url)) | 487 if (!history::CanAddURL(url)) |
| 488 return; | 488 return; |
| 489 | 489 |
| 490 // Add to the visited links system. | 490 // Add to the visited links system. |
| 491 if (visitedlink_master_) | 491 if (visitedlink_master_) |
| 492 visitedlink_master_->AddURL(url); | 492 visitedlink_master_->AddURL(url); |
| 493 | 493 |
| 494 history::URLRow row(url); | 494 history::URLRow row(url); |
| 495 row.set_title(title); | 495 row.set_title(title); |
| 496 row.set_visit_count(visit_count); | 496 row.set_visit_count(visit_count); |
| 497 row.set_typed_count(typed_count); | 497 row.set_typed_count(typed_count); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 636 } |
| 637 | 637 |
| 638 void HistoryService::MergeFavicon( | 638 void HistoryService::MergeFavicon( |
| 639 const GURL& page_url, | 639 const GURL& page_url, |
| 640 const GURL& icon_url, | 640 const GURL& icon_url, |
| 641 favicon_base::IconType icon_type, | 641 favicon_base::IconType icon_type, |
| 642 scoped_refptr<base::RefCountedMemory> bitmap_data, | 642 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 643 const gfx::Size& pixel_size) { | 643 const gfx::Size& pixel_size) { |
| 644 DCHECK(thread_) << "History service being called after cleanup"; | 644 DCHECK(thread_) << "History service being called after cleanup"; |
| 645 DCHECK(thread_checker_.CalledOnValidThread()); | 645 DCHECK(thread_checker_.CalledOnValidThread()); |
| 646 if (!CanAddURL(page_url)) | 646 if (!history::CanAddURL(page_url)) |
| 647 return; | 647 return; |
| 648 | 648 |
| 649 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::MergeFavicon, page_url, | 649 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::MergeFavicon, page_url, |
| 650 icon_url, icon_type, bitmap_data, pixel_size); | 650 icon_url, icon_type, bitmap_data, pixel_size); |
| 651 } | 651 } |
| 652 | 652 |
| 653 void HistoryService::SetFavicons( | 653 void HistoryService::SetFavicons( |
| 654 const GURL& page_url, | 654 const GURL& page_url, |
| 655 favicon_base::IconType icon_type, | 655 favicon_base::IconType icon_type, |
| 656 const GURL& icon_url, | 656 const GURL& icon_url, |
| 657 const std::vector<SkBitmap>& bitmaps) { | 657 const std::vector<SkBitmap>& bitmaps) { |
| 658 DCHECK(thread_) << "History service being called after cleanup"; | 658 DCHECK(thread_) << "History service being called after cleanup"; |
| 659 DCHECK(thread_checker_.CalledOnValidThread()); | 659 DCHECK(thread_checker_.CalledOnValidThread()); |
| 660 if (!CanAddURL(page_url)) | 660 if (!history::CanAddURL(page_url)) |
| 661 return; | 661 return; |
| 662 | 662 |
| 663 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::SetFavicons, page_url, | 663 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::SetFavicons, page_url, |
| 664 icon_type, icon_url, bitmaps); | 664 icon_type, icon_url, bitmaps); |
| 665 } | 665 } |
| 666 | 666 |
| 667 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 667 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
| 668 DCHECK(thread_) << "History service being called after cleanup"; | 668 DCHECK(thread_) << "History service being called after cleanup"; |
| 669 DCHECK(thread_checker_.CalledOnValidThread()); | 669 DCHECK(thread_checker_.CalledOnValidThread()); |
| 670 ScheduleAndForget(PRIORITY_NORMAL, | 670 ScheduleAndForget(PRIORITY_NORMAL, |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 | 1037 |
| 1038 void HistoryService::ScheduleTask(SchedulePriority priority, | 1038 void HistoryService::ScheduleTask(SchedulePriority priority, |
| 1039 const base::Closure& task) { | 1039 const base::Closure& task) { |
| 1040 DCHECK(thread_checker_.CalledOnValidThread()); | 1040 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1041 CHECK(thread_); | 1041 CHECK(thread_); |
| 1042 CHECK(thread_->message_loop()); | 1042 CHECK(thread_->message_loop()); |
| 1043 // TODO(brettw): Do prioritization. | 1043 // TODO(brettw): Do prioritization. |
| 1044 thread_->message_loop()->PostTask(FROM_HERE, task); | 1044 thread_->message_loop()->PostTask(FROM_HERE, task); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 // static | |
| 1048 bool HistoryService::CanAddURL(const GURL& url) { | |
| 1049 if (!url.is_valid()) | |
| 1050 return false; | |
| 1051 | |
| 1052 // TODO: We should allow kChromeUIScheme URLs if they have been explicitly | |
| 1053 // typed. Right now, however, these are marked as typed even when triggered | |
| 1054 // by a shortcut or menu action. | |
| 1055 if (url.SchemeIs(url::kJavaScriptScheme) || | |
| 1056 url.SchemeIs(content::kChromeDevToolsScheme) || | |
| 1057 url.SchemeIs(content::kChromeUIScheme) || | |
| 1058 url.SchemeIs(content::kViewSourceScheme) || | |
| 1059 url.SchemeIs(chrome::kChromeNativeScheme) || | |
| 1060 url.SchemeIs(chrome::kChromeSearchScheme) || | |
| 1061 url.SchemeIs(dom_distiller::kDomDistillerScheme)) | |
| 1062 return false; | |
| 1063 | |
| 1064 // Allow all about: and chrome: URLs except about:blank, since the user may | |
| 1065 // like to see "chrome://memory/", etc. in their history and autocomplete. | |
| 1066 if (url == GURL(url::kAboutBlankURL)) | |
| 1067 return false; | |
| 1068 | |
| 1069 return true; | |
| 1070 } | |
| 1071 | |
| 1072 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { | 1047 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { |
| 1073 DCHECK(thread_checker_.CalledOnValidThread()); | 1048 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1074 return weak_ptr_factory_.GetWeakPtr(); | 1049 return weak_ptr_factory_.GetWeakPtr(); |
| 1075 } | 1050 } |
| 1076 | 1051 |
| 1077 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( | 1052 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( |
| 1078 syncer::ModelType type, | 1053 syncer::ModelType type, |
| 1079 const syncer::SyncDataList& initial_sync_data, | 1054 const syncer::SyncDataList& initial_sync_data, |
| 1080 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 1055 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 1081 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 1056 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 const HistoryService::OnFaviconChangedCallback& callback) { | 1249 const HistoryService::OnFaviconChangedCallback& callback) { |
| 1275 DCHECK(thread_checker_.CalledOnValidThread()); | 1250 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1276 return favicon_changed_callback_list_.Add(callback); | 1251 return favicon_changed_callback_list_.Add(callback); |
| 1277 } | 1252 } |
| 1278 | 1253 |
| 1279 void HistoryService::NotifyFaviconChanged( | 1254 void HistoryService::NotifyFaviconChanged( |
| 1280 const std::set<GURL>& changed_favicons) { | 1255 const std::set<GURL>& changed_favicons) { |
| 1281 DCHECK(thread_checker_.CalledOnValidThread()); | 1256 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1282 favicon_changed_callback_list_.Notify(changed_favicons); | 1257 favicon_changed_callback_list_.Notify(changed_favicons); |
| 1283 } | 1258 } |
| OLD | NEW |