Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/history/history_service.cc

Issue 934083003: Cleanup HistoryService and HistoryBackend interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@android-backend-provider
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/browser/profiles/profile.h"
35 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
36 #include "components/dom_distiller/core/url_constants.h" 35 #include "components/dom_distiller/core/url_constants.h"
37 #include "components/history/core/browser/download_row.h" 36 #include "components/history/core/browser/download_row.h"
38 #include "components/history/core/browser/history_client.h" 37 #include "components/history/core/browser/history_client.h"
39 #include "components/history/core/browser/history_database_params.h" 38 #include "components/history/core/browser/history_database_params.h"
40 #include "components/history/core/browser/history_service_observer.h" 39 #include "components/history/core/browser/history_service_observer.h"
41 #include "components/history/core/browser/history_types.h" 40 #include "components/history/core/browser/history_types.h"
42 #include "components/history/core/browser/in_memory_database.h" 41 #include "components/history/core/browser/in_memory_database.h"
43 #include "components/history/core/browser/keyword_search_term.h" 42 #include "components/history/core/browser/keyword_search_term.h"
44 #include "components/history/core/browser/visit_database.h" 43 #include "components/history/core/browser/visit_database.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; 186 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_;
188 }; 187 };
189 188
190 // The history thread is intentionally not a BrowserThread because the 189 // The history thread is intentionally not a BrowserThread because the
191 // sync integration unit tests depend on being able to create more than one 190 // sync integration unit tests depend on being able to create more than one
192 // history thread. 191 // history thread.
193 HistoryService::HistoryService() 192 HistoryService::HistoryService()
194 : thread_(new base::Thread(kHistoryThreadName)), 193 : thread_(new base::Thread(kHistoryThreadName)),
195 history_client_(nullptr), 194 history_client_(nullptr),
196 backend_loaded_(false), 195 backend_loaded_(false),
197 no_db_(false),
198 weak_ptr_factory_(this) { 196 weak_ptr_factory_(this) {
199 } 197 }
200 198
201 HistoryService::HistoryService( 199 HistoryService::HistoryService(
202 history::HistoryClient* history_client, 200 history::HistoryClient* history_client,
203 scoped_ptr<history::VisitDelegate> visit_delegate) 201 scoped_ptr<history::VisitDelegate> visit_delegate)
204 : thread_(new base::Thread(kHistoryThreadName)), 202 : thread_(new base::Thread(kHistoryThreadName)),
205 visit_delegate_(visit_delegate.Pass()), 203 visit_delegate_(visit_delegate.Pass()),
206 history_client_(history_client), 204 history_client_(history_client),
207 backend_loaded_(false), 205 backend_loaded_(false),
208 no_db_(false),
209 weak_ptr_factory_(this) { 206 weak_ptr_factory_(this) {
210 } 207 }
211 208
212 HistoryService::~HistoryService() { 209 HistoryService::~HistoryService() {
213 DCHECK(thread_checker_.CalledOnValidThread()); 210 DCHECK(thread_checker_.CalledOnValidThread());
214 // Shutdown the backend. This does nothing if Cleanup was already invoked. 211 // Shutdown the backend. This does nothing if Cleanup was already invoked.
215 Cleanup(); 212 Cleanup();
216 } 213 }
217 214
218 bool HistoryService::BackendLoaded() { 215 bool HistoryService::BackendLoaded() {
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 const history::HistoryDatabaseParams& history_database_params) { 929 const history::HistoryDatabaseParams& history_database_params) {
933 DCHECK(thread_) << "History service being called after cleanup"; 930 DCHECK(thread_) << "History service being called after cleanup";
934 DCHECK(thread_checker_.CalledOnValidThread()); 931 DCHECK(thread_checker_.CalledOnValidThread());
935 base::Thread::Options options; 932 base::Thread::Options options;
936 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 933 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
937 if (!thread_->StartWithOptions(options)) { 934 if (!thread_->StartWithOptions(options)) {
938 Cleanup(); 935 Cleanup();
939 return false; 936 return false;
940 } 937 }
941 938
942 history_dir_ = history_database_params.history_dir;
943 no_db_ = no_db;
944
945 if (!languages.empty()) { 939 if (!languages.empty()) {
946 // Do not create |in_memory_url_index_| when languages is empty (which 940 // Do not create |in_memory_url_index_| when languages is empty (which
947 // should only happens during testing). 941 // should only happens during testing).
948 in_memory_url_index_.reset( 942 in_memory_url_index_.reset(new history::InMemoryURLIndex(
949 new history::InMemoryURLIndex(this, history_dir_, languages)); 943 this, history_database_params.history_dir, languages));
950 in_memory_url_index_->Init(); 944 in_memory_url_index_->Init();
951 } 945 }
952 946
953 // Create the history backend. 947 // Create the history backend.
954 scoped_refptr<HistoryBackend> backend(new HistoryBackend( 948 scoped_refptr<HistoryBackend> backend(new HistoryBackend(
955 history_dir_, new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), 949 new BackendDelegate(weak_ptr_factory_.GetWeakPtr(),
956 base::ThreadTaskRunnerHandle::Get()), 950 base::ThreadTaskRunnerHandle::Get()),
957 history_client_)); 951 history_client_));
958 history_backend_.swap(backend); 952 history_backend_.swap(backend);
959 953
960 ScheduleTask(PRIORITY_UI, 954 ScheduleTask(PRIORITY_UI,
961 base::Bind(&HistoryBackend::Init, history_backend_.get(), 955 base::Bind(&HistoryBackend::Init, history_backend_.get(),
962 languages, no_db_, history_database_params)); 956 languages, no_db, history_database_params));
963 957
964 if (visit_delegate_ && !visit_delegate_->Init(this)) 958 if (visit_delegate_ && !visit_delegate_->Init(this))
965 return false; 959 return false;
966 960
967 return true; 961 return true;
968 } 962 }
969 963
970 void HistoryService::ScheduleAutocomplete(const base::Callback< 964 void HistoryService::ScheduleAutocomplete(const base::Callback<
971 void(history::HistoryBackend*, history::URLDatabase*)>& callback) { 965 void(history::HistoryBackend*, history::URLDatabase*)>& callback) {
972 DCHECK(thread_checker_.CalledOnValidThread()); 966 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 const HistoryService::OnFaviconChangedCallback& callback) { 1239 const HistoryService::OnFaviconChangedCallback& callback) {
1246 DCHECK(thread_checker_.CalledOnValidThread()); 1240 DCHECK(thread_checker_.CalledOnValidThread());
1247 return favicon_changed_callback_list_.Add(callback); 1241 return favicon_changed_callback_list_.Add(callback);
1248 } 1242 }
1249 1243
1250 void HistoryService::NotifyFaviconChanged( 1244 void HistoryService::NotifyFaviconChanged(
1251 const std::set<GURL>& changed_favicons) { 1245 const std::set<GURL>& changed_favicons) {
1252 DCHECK(thread_checker_.CalledOnValidThread()); 1246 DCHECK(thread_checker_.CalledOnValidThread());
1253 favicon_changed_callback_list_.Notify(changed_favicons); 1247 favicon_changed_callback_list_.Notify(changed_favicons);
1254 } 1248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698