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 |
11 // ----------- -------------- | 11 // ----------- -------------- |
12 // HistoryService <----------------> HistoryBackend | 12 // HistoryService <----------------> HistoryBackend |
13 // -> HistoryDatabase | 13 // -> HistoryDatabase |
14 // -> SQLite connection to History | 14 // -> SQLite connection to History |
15 // -> ThumbnailDatabase | 15 // -> ThumbnailDatabase |
16 // -> SQLite connection to Thumbnails | 16 // -> SQLite connection to Thumbnails |
17 // (and favicons) | 17 // (and favicons) |
18 | 18 |
19 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
20 | 20 |
21 #include "base/bind_helpers.h" | 21 #include "base/bind_helpers.h" |
22 #include "base/callback.h" | 22 #include "base/callback.h" |
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/prefs/pref_service.h" | |
29 #include "base/thread_task_runner_handle.h" | 28 #include "base/thread_task_runner_handle.h" |
30 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
31 #include "base/time/time.h" | 30 #include "base/time/time.h" |
32 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
33 #include "chrome/browser/history/history_backend.h" | 32 #include "chrome/browser/history/history_backend.h" |
34 #include "chrome/browser/history/in_memory_history_backend.h" | 33 #include "chrome/browser/history/in_memory_history_backend.h" |
35 #include "chrome/browser/history/in_memory_url_index.h" | 34 #include "chrome/browser/history/in_memory_url_index.h" |
36 #include "chrome/browser/history/web_history_service.h" | 35 #include "chrome/browser/history/web_history_service.h" |
37 #include "chrome/browser/history/web_history_service_factory.h" | 36 #include "chrome/browser/history/web_history_service_factory.h" |
38 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/common/chrome_constants.h" | 38 #include "chrome/common/chrome_constants.h" |
40 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/importer/imported_favicon_usage.h" | 40 #include "chrome/common/importer/imported_favicon_usage.h" |
42 #include "chrome/common/pref_names.h" | |
43 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
44 #include "components/dom_distiller/core/url_constants.h" | 42 #include "components/dom_distiller/core/url_constants.h" |
45 #include "components/history/core/browser/download_row.h" | 43 #include "components/history/core/browser/download_row.h" |
46 #include "components/history/core/browser/history_client.h" | 44 #include "components/history/core/browser/history_client.h" |
47 #include "components/history/core/browser/history_database_params.h" | 45 #include "components/history/core/browser/history_database_params.h" |
48 #include "components/history/core/browser/history_service_observer.h" | 46 #include "components/history/core/browser/history_service_observer.h" |
49 #include "components/history/core/browser/history_types.h" | 47 #include "components/history/core/browser/history_types.h" |
50 #include "components/history/core/browser/in_memory_database.h" | 48 #include "components/history/core/browser/in_memory_database.h" |
51 #include "components/history/core/browser/keyword_search_term.h" | 49 #include "components/history/core/browser/keyword_search_term.h" |
52 #include "components/history/core/browser/visit_database.h" | 50 #include "components/history/core/browser/visit_database.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 // history thread. | 219 // history thread. |
222 HistoryService::HistoryService() | 220 HistoryService::HistoryService() |
223 : thread_(new base::Thread(kHistoryThreadName)), | 221 : thread_(new base::Thread(kHistoryThreadName)), |
224 history_client_(NULL), | 222 history_client_(NULL), |
225 profile_(NULL), | 223 profile_(NULL), |
226 backend_loaded_(false), | 224 backend_loaded_(false), |
227 no_db_(false), | 225 no_db_(false), |
228 weak_ptr_factory_(this) { | 226 weak_ptr_factory_(this) { |
229 } | 227 } |
230 | 228 |
231 HistoryService::HistoryService(history::HistoryClient* client, Profile* profile) | 229 HistoryService::HistoryService( |
230 history::HistoryClient* history_client, Profile* profile) | |
232 : thread_(new base::Thread(kHistoryThreadName)), | 231 : thread_(new base::Thread(kHistoryThreadName)), |
233 history_client_(client), | 232 history_client_(history_client), |
234 profile_(profile), | 233 profile_(profile), |
235 visitedlink_master_(new visitedlink::VisitedLinkMaster( | 234 visitedlink_master_(new visitedlink::VisitedLinkMaster( |
236 profile, this, true)), | 235 profile, this, true)), |
237 backend_loaded_(false), | 236 backend_loaded_(false), |
238 no_db_(false), | 237 no_db_(false), |
239 weak_ptr_factory_(this) { | 238 weak_ptr_factory_(this) { |
240 DCHECK(profile_); | |
241 } | 239 } |
242 | 240 |
243 HistoryService::~HistoryService() { | 241 HistoryService::~HistoryService() { |
244 DCHECK(thread_checker_.CalledOnValidThread()); | 242 DCHECK(thread_checker_.CalledOnValidThread()); |
245 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 243 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
246 Cleanup(); | 244 Cleanup(); |
247 } | 245 } |
248 | 246 |
249 bool HistoryService::BackendLoaded() { | 247 bool HistoryService::BackendLoaded() { |
250 DCHECK(thread_checker_.CalledOnValidThread()); | 248 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 void HistoryService::RebuildTable( | 959 void HistoryService::RebuildTable( |
962 const scoped_refptr<URLEnumerator>& enumerator) { | 960 const scoped_refptr<URLEnumerator>& enumerator) { |
963 DCHECK(thread_) << "History service being called after cleanup"; | 961 DCHECK(thread_) << "History service being called after cleanup"; |
964 DCHECK(thread_checker_.CalledOnValidThread()); | 962 DCHECK(thread_checker_.CalledOnValidThread()); |
965 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::IterateURLs, | 963 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::IterateURLs, |
966 history_backend_.get(), enumerator)); | 964 history_backend_.get(), enumerator)); |
967 } | 965 } |
968 | 966 |
969 bool HistoryService::Init( | 967 bool HistoryService::Init( |
970 bool no_db, | 968 bool no_db, |
969 const std::string& languages, | |
971 const history::HistoryDatabaseParams& history_database_params) { | 970 const history::HistoryDatabaseParams& history_database_params) { |
972 DCHECK(thread_) << "History service being called after cleanup"; | 971 DCHECK(thread_) << "History service being called after cleanup"; |
973 DCHECK(thread_checker_.CalledOnValidThread()); | 972 DCHECK(thread_checker_.CalledOnValidThread()); |
974 base::Thread::Options options; | 973 base::Thread::Options options; |
975 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 974 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
976 if (!thread_->StartWithOptions(options)) { | 975 if (!thread_->StartWithOptions(options)) { |
977 Cleanup(); | 976 Cleanup(); |
978 return false; | 977 return false; |
979 } | 978 } |
980 | 979 |
981 history_dir_ = history_database_params.history_dir; | 980 history_dir_ = history_database_params.history_dir; |
982 no_db_ = no_db; | 981 no_db_ = no_db; |
983 | 982 |
984 if (profile_) { | 983 if (!languages.empty()) { |
985 std::string languages = | 984 // During unit testing, there may not be a PrefService, and thus |
droger
2015/02/04 16:42:46
Maybe remove the reference to PrefService in this
| |
986 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 985 // |languages| is empty. |
987 in_memory_url_index_.reset(new history::InMemoryURLIndex( | 986 in_memory_url_index_.reset(new history::InMemoryURLIndex( |
988 this, history_dir_, languages, history_client_)); | 987 this, history_dir_, languages, history_client_)); |
989 in_memory_url_index_->Init(); | 988 in_memory_url_index_->Init(); |
990 } | 989 } |
991 | 990 |
992 // Create the history backend. | 991 // Create the history backend. |
993 scoped_refptr<HistoryBackend> backend(new HistoryBackend( | 992 scoped_refptr<HistoryBackend> backend(new HistoryBackend( |
994 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), | 993 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), |
995 base::ThreadTaskRunnerHandle::Get()), | 994 base::ThreadTaskRunnerHandle::Get()), |
996 history_client_)); | 995 history_client_)); |
997 history_backend_.swap(backend); | 996 history_backend_.swap(backend); |
998 | 997 |
999 // There may not be a profile when unit testing. | |
1000 std::string languages; | |
1001 if (profile_) { | |
1002 PrefService* prefs = profile_->GetPrefs(); | |
1003 languages = prefs->GetString(prefs::kAcceptLanguages); | |
1004 } | |
1005 | |
1006 ScheduleTask(PRIORITY_UI, | 998 ScheduleTask(PRIORITY_UI, |
1007 base::Bind(&HistoryBackend::Init, history_backend_.get(), | 999 base::Bind(&HistoryBackend::Init, history_backend_.get(), |
1008 languages, no_db_, history_database_params)); | 1000 languages, no_db_, history_database_params)); |
1009 | 1001 |
1010 if (visitedlink_master_) { | 1002 if (visitedlink_master_) { |
1011 bool result = visitedlink_master_->Init(); | 1003 bool result = visitedlink_master_->Init(); |
1012 DCHECK(result); | 1004 DCHECK(result); |
1013 } | 1005 } |
1014 | 1006 |
1015 return true; | 1007 return true; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1293 const HistoryService::OnFaviconChangedCallback& callback) { | 1285 const HistoryService::OnFaviconChangedCallback& callback) { |
1294 DCHECK(thread_checker_.CalledOnValidThread()); | 1286 DCHECK(thread_checker_.CalledOnValidThread()); |
1295 return favicon_changed_callback_list_.Add(callback); | 1287 return favicon_changed_callback_list_.Add(callback); |
1296 } | 1288 } |
1297 | 1289 |
1298 void HistoryService::NotifyFaviconChanged( | 1290 void HistoryService::NotifyFaviconChanged( |
1299 const std::set<GURL>& changed_favicons) { | 1291 const std::set<GURL>& changed_favicons) { |
1300 DCHECK(thread_checker_.CalledOnValidThread()); | 1292 DCHECK(thread_checker_.CalledOnValidThread()); |
1301 favicon_changed_callback_list_.Notify(changed_favicons); | 1293 favicon_changed_callback_list_.Notify(changed_favicons); |
1302 } | 1294 } |
OLD | NEW |