| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const base::WeakPtr<HistoryService> history_service_; | 214 const base::WeakPtr<HistoryService> history_service_; |
| 215 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 215 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
| 216 }; | 216 }; |
| 217 | 217 |
| 218 // The history thread is intentionally not a BrowserThread because the | 218 // The history thread is intentionally not a BrowserThread because the |
| 219 // sync integration unit tests depend on being able to create more than one | 219 // sync integration unit tests depend on being able to create more than one |
| 220 // history thread. | 220 // history thread. |
| 221 HistoryService::HistoryService() | 221 HistoryService::HistoryService() |
| 222 : thread_(new base::Thread(kHistoryThreadName)), | 222 : thread_(new base::Thread(kHistoryThreadName)), |
| 223 history_client_(NULL), | 223 history_client_(NULL), |
| 224 profile_(NULL), | |
| 225 backend_loaded_(false), | 224 backend_loaded_(false), |
| 226 no_db_(false), | 225 no_db_(false), |
| 227 weak_ptr_factory_(this) { | 226 weak_ptr_factory_(this) { |
| 228 } | 227 } |
| 229 | 228 |
| 230 HistoryService::HistoryService(history::HistoryClient* client, Profile* profile) | 229 HistoryService::HistoryService( |
| 230 history::HistoryClient* history_client, Profile* profile) |
| 231 : thread_(new base::Thread(kHistoryThreadName)), | 231 : thread_(new base::Thread(kHistoryThreadName)), |
| 232 history_client_(client), | 232 history_client_(history_client), |
| 233 profile_(profile), | |
| 234 visitedlink_master_(new visitedlink::VisitedLinkMaster( | 233 visitedlink_master_(new visitedlink::VisitedLinkMaster( |
| 235 profile, this, true)), | 234 profile, this, true)), |
| 236 backend_loaded_(false), | 235 backend_loaded_(false), |
| 237 no_db_(false), | 236 no_db_(false), |
| 238 weak_ptr_factory_(this) { | 237 weak_ptr_factory_(this) { |
| 239 DCHECK(profile_); | |
| 240 } | 238 } |
| 241 | 239 |
| 242 HistoryService::~HistoryService() { | 240 HistoryService::~HistoryService() { |
| 243 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
| 244 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 242 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
| 245 Cleanup(); | 243 Cleanup(); |
| 246 } | 244 } |
| 247 | 245 |
| 248 bool HistoryService::BackendLoaded() { | 246 bool HistoryService::BackendLoaded() { |
| 249 DCHECK(thread_checker_.CalledOnValidThread()); | 247 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 void HistoryService::RebuildTable( | 958 void HistoryService::RebuildTable( |
| 961 const scoped_refptr<URLEnumerator>& enumerator) { | 959 const scoped_refptr<URLEnumerator>& enumerator) { |
| 962 DCHECK(thread_) << "History service being called after cleanup"; | 960 DCHECK(thread_) << "History service being called after cleanup"; |
| 963 DCHECK(thread_checker_.CalledOnValidThread()); | 961 DCHECK(thread_checker_.CalledOnValidThread()); |
| 964 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::IterateURLs, | 962 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::IterateURLs, |
| 965 history_backend_.get(), enumerator)); | 963 history_backend_.get(), enumerator)); |
| 966 } | 964 } |
| 967 | 965 |
| 968 bool HistoryService::Init( | 966 bool HistoryService::Init( |
| 969 bool no_db, | 967 bool no_db, |
| 968 PrefService* prefs, |
| 970 const history::HistoryDatabaseParams& history_database_params) { | 969 const history::HistoryDatabaseParams& history_database_params) { |
| 971 DCHECK(thread_) << "History service being called after cleanup"; | 970 DCHECK(thread_) << "History service being called after cleanup"; |
| 972 DCHECK(thread_checker_.CalledOnValidThread()); | 971 DCHECK(thread_checker_.CalledOnValidThread()); |
| 973 base::Thread::Options options; | 972 base::Thread::Options options; |
| 974 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 973 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 975 if (!thread_->StartWithOptions(options)) { | 974 if (!thread_->StartWithOptions(options)) { |
| 976 Cleanup(); | 975 Cleanup(); |
| 977 return false; | 976 return false; |
| 978 } | 977 } |
| 979 | 978 |
| 980 history_dir_ = history_database_params.history_dir; | 979 history_dir_ = history_database_params.history_dir; |
| 981 no_db_ = no_db; | 980 no_db_ = no_db; |
| 982 | 981 |
| 983 if (profile_) { | 982 std::string languages; |
| 984 std::string languages = | 983 if (prefs) { |
| 985 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 984 // During unit testing, there may not be a PrefService. |
| 985 languages = prefs->GetString(prefs::kAcceptLanguages); |
| 986 in_memory_url_index_.reset(new history::InMemoryURLIndex( | 986 in_memory_url_index_.reset(new history::InMemoryURLIndex( |
| 987 this, history_dir_, languages, history_client_)); | 987 this, history_dir_, languages, history_client_)); |
| 988 in_memory_url_index_->Init(); | 988 in_memory_url_index_->Init(); |
| 989 } | 989 } |
| 990 | 990 |
| 991 // Create the history backend. | 991 // Create the history backend. |
| 992 scoped_refptr<HistoryBackend> backend(new HistoryBackend( | 992 scoped_refptr<HistoryBackend> backend(new HistoryBackend( |
| 993 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), | 993 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), |
| 994 base::ThreadTaskRunnerHandle::Get()), | 994 base::ThreadTaskRunnerHandle::Get()), |
| 995 history_client_)); | 995 history_client_)); |
| 996 history_backend_.swap(backend); | 996 history_backend_.swap(backend); |
| 997 | 997 |
| 998 // There may not be a profile when unit testing. | |
| 999 std::string languages; | |
| 1000 if (profile_) { | |
| 1001 PrefService* prefs = profile_->GetPrefs(); | |
| 1002 languages = prefs->GetString(prefs::kAcceptLanguages); | |
| 1003 } | |
| 1004 | |
| 1005 ScheduleTask(PRIORITY_UI, | 998 ScheduleTask(PRIORITY_UI, |
| 1006 base::Bind(&HistoryBackend::Init, history_backend_.get(), | 999 base::Bind(&HistoryBackend::Init, history_backend_.get(), |
| 1007 languages, no_db_, history_database_params)); | 1000 languages, no_db_, history_database_params)); |
| 1008 | 1001 |
| 1009 if (visitedlink_master_) { | 1002 if (visitedlink_master_) { |
| 1010 bool result = visitedlink_master_->Init(); | 1003 bool result = visitedlink_master_->Init(); |
| 1011 DCHECK(result); | 1004 DCHECK(result); |
| 1012 } | 1005 } |
| 1013 | 1006 |
| 1014 return true; | 1007 return true; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 const HistoryService::OnFaviconChangedCallback& callback) { | 1283 const HistoryService::OnFaviconChangedCallback& callback) { |
| 1291 DCHECK(thread_checker_.CalledOnValidThread()); | 1284 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1292 return favicon_changed_callback_list_.Add(callback); | 1285 return favicon_changed_callback_list_.Add(callback); |
| 1293 } | 1286 } |
| 1294 | 1287 |
| 1295 void HistoryService::NotifyFaviconChanged( | 1288 void HistoryService::NotifyFaviconChanged( |
| 1296 const std::set<GURL>& changed_favicons) { | 1289 const std::set<GURL>& changed_favicons) { |
| 1297 DCHECK(thread_checker_.CalledOnValidThread()); | 1290 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1298 favicon_changed_callback_list_.Notify(changed_favicons); | 1291 favicon_changed_callback_list_.Notify(changed_favicons); |
| 1299 } | 1292 } |
| OLD | NEW |