| 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 10 matching lines...) Expand all Loading... |
| 21 #include <utility> | 21 #include <utility> |
| 22 | 22 |
| 23 #include "base/bind_helpers.h" | 23 #include "base/bind_helpers.h" |
| 24 #include "base/callback.h" | 24 #include "base/callback.h" |
| 25 #include "base/command_line.h" | 25 #include "base/command_line.h" |
| 26 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
| 27 #include "base/location.h" | 27 #include "base/location.h" |
| 28 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
| 29 #include "base/metrics/histogram_macros.h" | 29 #include "base/metrics/histogram_macros.h" |
| 30 #include "base/single_thread_task_runner.h" | 30 #include "base/single_thread_task_runner.h" |
| 31 #include "base/task_scheduler/post_task.h" |
| 31 #include "base/threading/thread.h" | 32 #include "base/threading/thread.h" |
| 32 #include "base/threading/thread_task_runner_handle.h" | 33 #include "base/threading/thread_task_runner_handle.h" |
| 33 #include "base/time/time.h" | 34 #include "base/time/time.h" |
| 34 #include "base/trace_event/trace_event.h" | 35 #include "base/trace_event/trace_event.h" |
| 35 #include "build/build_config.h" | 36 #include "build/build_config.h" |
| 36 #include "components/history/core/browser/download_row.h" | 37 #include "components/history/core/browser/download_row.h" |
| 37 #include "components/history/core/browser/history_backend.h" | 38 #include "components/history/core/browser/history_backend.h" |
| 38 #include "components/history/core/browser/history_backend_client.h" | 39 #include "components/history/core/browser/history_backend_client.h" |
| 39 #include "components/history/core/browser/history_client.h" | 40 #include "components/history/core/browser/history_client.h" |
| 40 #include "components/history/core/browser/history_database_params.h" | 41 #include "components/history/core/browser/history_database_params.h" |
| 41 #include "components/history/core/browser/history_db_task.h" | 42 #include "components/history/core/browser/history_db_task.h" |
| 42 #include "components/history/core/browser/history_service_observer.h" | 43 #include "components/history/core/browser/history_service_observer.h" |
| 43 #include "components/history/core/browser/history_types.h" | 44 #include "components/history/core/browser/history_types.h" |
| 44 #include "components/history/core/browser/in_memory_database.h" | 45 #include "components/history/core/browser/in_memory_database.h" |
| 45 #include "components/history/core/browser/in_memory_history_backend.h" | 46 #include "components/history/core/browser/in_memory_history_backend.h" |
| 46 #include "components/history/core/browser/keyword_search_term.h" | 47 #include "components/history/core/browser/keyword_search_term.h" |
| 47 #include "components/history/core/browser/visit_database.h" | 48 #include "components/history/core/browser/visit_database.h" |
| 48 #include "components/history/core/browser/visit_delegate.h" | 49 #include "components/history/core/browser/visit_delegate.h" |
| 49 #include "components/history/core/browser/web_history_service.h" | 50 #include "components/history/core/browser/web_history_service.h" |
| 50 #include "components/history/core/common/thumbnail_score.h" | 51 #include "components/history/core/common/thumbnail_score.h" |
| 51 #include "components/sync/model/sync_error_factory.h" | 52 #include "components/sync/model/sync_error_factory.h" |
| 53 #include "components/variations/variations_associated_data.h" |
| 52 #include "third_party/skia/include/core/SkBitmap.h" | 54 #include "third_party/skia/include/core/SkBitmap.h" |
| 53 | 55 |
| 54 #if defined(OS_IOS) | 56 #if defined(OS_IOS) |
| 55 #include "base/critical_closure.h" | 57 #include "base/critical_closure.h" |
| 56 #endif | 58 #endif |
| 57 | 59 |
| 58 using base::Time; | 60 using base::Time; |
| 59 | 61 |
| 60 namespace history { | 62 namespace history { |
| 61 namespace { | 63 namespace { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 void DBLoaded() override { | 177 void DBLoaded() override { |
| 176 service_task_runner_->PostTask( | 178 service_task_runner_->PostTask( |
| 177 FROM_HERE, base::Bind(&HistoryService::OnDBLoaded, history_service_)); | 179 FROM_HERE, base::Bind(&HistoryService::OnDBLoaded, history_service_)); |
| 178 } | 180 } |
| 179 | 181 |
| 180 private: | 182 private: |
| 181 const base::WeakPtr<HistoryService> history_service_; | 183 const base::WeakPtr<HistoryService> history_service_; |
| 182 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 184 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
| 183 }; | 185 }; |
| 184 | 186 |
| 185 // The history thread is intentionally not a BrowserThread because the | 187 HistoryService::HistoryService() : HistoryService(nullptr, nullptr) {} |
| 186 // sync integration unit tests depend on being able to create more than one | |
| 187 // history thread. | |
| 188 HistoryService::HistoryService() | |
| 189 : thread_(new base::Thread(kHistoryThreadName)), | |
| 190 history_client_(nullptr), | |
| 191 backend_loaded_(false), | |
| 192 weak_ptr_factory_(this) { | |
| 193 } | |
| 194 | 188 |
| 195 HistoryService::HistoryService(std::unique_ptr<HistoryClient> history_client, | 189 HistoryService::HistoryService(std::unique_ptr<HistoryClient> history_client, |
| 196 std::unique_ptr<VisitDelegate> visit_delegate) | 190 std::unique_ptr<VisitDelegate> visit_delegate) |
| 197 : thread_(new base::Thread(kHistoryThreadName)), | 191 : thread_(variations::GetVariationParamValue("BrowserScheduler", |
| 192 "RedirectHistoryService") == |
| 193 "true" |
| 194 ? nullptr |
| 195 : new base::Thread(kHistoryThreadName)), |
| 198 history_client_(std::move(history_client)), | 196 history_client_(std::move(history_client)), |
| 199 visit_delegate_(std::move(visit_delegate)), | 197 visit_delegate_(std::move(visit_delegate)), |
| 200 backend_loaded_(false), | 198 backend_loaded_(false), |
| 201 weak_ptr_factory_(this) {} | 199 weak_ptr_factory_(this) {} |
| 202 | 200 |
| 203 HistoryService::~HistoryService() { | 201 HistoryService::~HistoryService() { |
| 204 DCHECK(thread_checker_.CalledOnValidThread()); | 202 DCHECK(thread_checker_.CalledOnValidThread()); |
| 205 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 203 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
| 206 Cleanup(); | 204 Cleanup(); |
| 207 } | 205 } |
| 208 | 206 |
| 209 bool HistoryService::BackendLoaded() { | 207 bool HistoryService::BackendLoaded() { |
| 210 DCHECK(thread_checker_.CalledOnValidThread()); | 208 DCHECK(thread_checker_.CalledOnValidThread()); |
| 211 return backend_loaded_; | 209 return backend_loaded_; |
| 212 } | 210 } |
| 213 | 211 |
| 214 #if defined(OS_IOS) | 212 #if defined(OS_IOS) |
| 215 void HistoryService::HandleBackgrounding() { | 213 void HistoryService::HandleBackgrounding() { |
| 216 if (!thread_ || !history_backend_.get()) | 214 if (!backend_task_runner_ || !history_backend_.get()) |
| 217 return; | 215 return; |
| 218 | 216 |
| 219 ScheduleTask(PRIORITY_NORMAL, | 217 ScheduleTask(PRIORITY_NORMAL, |
| 220 base::MakeCriticalClosure(base::Bind( | 218 base::MakeCriticalClosure(base::Bind( |
| 221 &HistoryBackend::PersistState, history_backend_.get()))); | 219 &HistoryBackend::PersistState, history_backend_.get()))); |
| 222 } | 220 } |
| 223 #endif | 221 #endif |
| 224 | 222 |
| 225 void HistoryService::ClearCachedDataForContextID(ContextID context_id) { | 223 void HistoryService::ClearCachedDataForContextID(ContextID context_id) { |
| 226 DCHECK(thread_) << "History service being called after cleanup"; | 224 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 227 DCHECK(thread_checker_.CalledOnValidThread()); | 225 DCHECK(thread_checker_.CalledOnValidThread()); |
| 228 ScheduleTask(PRIORITY_NORMAL, | 226 ScheduleTask(PRIORITY_NORMAL, |
| 229 base::Bind(&HistoryBackend::ClearCachedDataForContextID, | 227 base::Bind(&HistoryBackend::ClearCachedDataForContextID, |
| 230 history_backend_, context_id)); | 228 history_backend_, context_id)); |
| 231 } | 229 } |
| 232 | 230 |
| 233 URLDatabase* HistoryService::InMemoryDatabase() { | 231 URLDatabase* HistoryService::InMemoryDatabase() { |
| 234 DCHECK(thread_checker_.CalledOnValidThread()); | 232 DCHECK(thread_checker_.CalledOnValidThread()); |
| 235 return in_memory_backend_ ? in_memory_backend_->db() : nullptr; | 233 return in_memory_backend_ ? in_memory_backend_->db() : nullptr; |
| 236 } | 234 } |
| 237 | 235 |
| 238 TypedUrlSyncableService* HistoryService::GetTypedUrlSyncableService() const { | 236 TypedUrlSyncableService* HistoryService::GetTypedUrlSyncableService() const { |
| 239 return history_backend_->GetTypedUrlSyncableService(); | 237 return history_backend_->GetTypedUrlSyncableService(); |
| 240 } | 238 } |
| 241 | 239 |
| 242 void HistoryService::Shutdown() { | 240 void HistoryService::Shutdown() { |
| 243 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
| 244 Cleanup(); | 242 Cleanup(); |
| 245 } | 243 } |
| 246 | 244 |
| 247 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 245 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
| 248 KeywordID keyword_id, | 246 KeywordID keyword_id, |
| 249 const base::string16& term) { | 247 const base::string16& term) { |
| 250 DCHECK(thread_) << "History service being called after cleanup"; | 248 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 251 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
| 252 ScheduleTask(PRIORITY_UI, | 250 ScheduleTask(PRIORITY_UI, |
| 253 base::Bind(&HistoryBackend::SetKeywordSearchTermsForURL, | 251 base::Bind(&HistoryBackend::SetKeywordSearchTermsForURL, |
| 254 history_backend_, url, keyword_id, term)); | 252 history_backend_, url, keyword_id, term)); |
| 255 } | 253 } |
| 256 | 254 |
| 257 void HistoryService::DeleteAllSearchTermsForKeyword(KeywordID keyword_id) { | 255 void HistoryService::DeleteAllSearchTermsForKeyword(KeywordID keyword_id) { |
| 258 DCHECK(thread_) << "History service being called after cleanup"; | 256 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 259 DCHECK(thread_checker_.CalledOnValidThread()); | 257 DCHECK(thread_checker_.CalledOnValidThread()); |
| 260 | 258 |
| 261 if (in_memory_backend_) | 259 if (in_memory_backend_) |
| 262 in_memory_backend_->DeleteAllSearchTermsForKeyword(keyword_id); | 260 in_memory_backend_->DeleteAllSearchTermsForKeyword(keyword_id); |
| 263 | 261 |
| 264 ScheduleTask(PRIORITY_UI, | 262 ScheduleTask(PRIORITY_UI, |
| 265 base::Bind(&HistoryBackend::DeleteAllSearchTermsForKeyword, | 263 base::Bind(&HistoryBackend::DeleteAllSearchTermsForKeyword, |
| 266 history_backend_, keyword_id)); | 264 history_backend_, keyword_id)); |
| 267 } | 265 } |
| 268 | 266 |
| 269 void HistoryService::DeleteKeywordSearchTermForURL(const GURL& url) { | 267 void HistoryService::DeleteKeywordSearchTermForURL(const GURL& url) { |
| 270 DCHECK(thread_) << "History service being called after cleanup"; | 268 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 271 DCHECK(thread_checker_.CalledOnValidThread()); | 269 DCHECK(thread_checker_.CalledOnValidThread()); |
| 272 ScheduleTask(PRIORITY_UI, | 270 ScheduleTask(PRIORITY_UI, |
| 273 base::Bind(&HistoryBackend::DeleteKeywordSearchTermForURL, | 271 base::Bind(&HistoryBackend::DeleteKeywordSearchTermForURL, |
| 274 history_backend_, url)); | 272 history_backend_, url)); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void HistoryService::DeleteMatchingURLsForKeyword(KeywordID keyword_id, | 275 void HistoryService::DeleteMatchingURLsForKeyword(KeywordID keyword_id, |
| 278 const base::string16& term) { | 276 const base::string16& term) { |
| 279 DCHECK(thread_) << "History service being called after cleanup"; | 277 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 280 DCHECK(thread_checker_.CalledOnValidThread()); | 278 DCHECK(thread_checker_.CalledOnValidThread()); |
| 281 ScheduleTask(PRIORITY_UI, | 279 ScheduleTask(PRIORITY_UI, |
| 282 base::Bind(&HistoryBackend::DeleteMatchingURLsForKeyword, | 280 base::Bind(&HistoryBackend::DeleteMatchingURLsForKeyword, |
| 283 history_backend_, keyword_id, term)); | 281 history_backend_, keyword_id, term)); |
| 284 } | 282 } |
| 285 | 283 |
| 286 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { | 284 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { |
| 287 DCHECK(thread_) << "History service being called after cleanup"; | 285 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 288 DCHECK(thread_checker_.CalledOnValidThread()); | 286 DCHECK(thread_checker_.CalledOnValidThread()); |
| 289 ScheduleTask(PRIORITY_NORMAL, | 287 ScheduleTask(PRIORITY_NORMAL, |
| 290 base::Bind(&HistoryBackend::URLsNoLongerBookmarked, | 288 base::Bind(&HistoryBackend::URLsNoLongerBookmarked, |
| 291 history_backend_, urls)); | 289 history_backend_, urls)); |
| 292 } | 290 } |
| 293 | 291 |
| 294 void HistoryService::AddObserver(HistoryServiceObserver* observer) { | 292 void HistoryService::AddObserver(HistoryServiceObserver* observer) { |
| 295 DCHECK(thread_checker_.CalledOnValidThread()); | 293 DCHECK(thread_checker_.CalledOnValidThread()); |
| 296 observers_.AddObserver(observer); | 294 observers_.AddObserver(observer); |
| 297 } | 295 } |
| 298 | 296 |
| 299 void HistoryService::RemoveObserver(HistoryServiceObserver* observer) { | 297 void HistoryService::RemoveObserver(HistoryServiceObserver* observer) { |
| 300 DCHECK(thread_checker_.CalledOnValidThread()); | 298 DCHECK(thread_checker_.CalledOnValidThread()); |
| 301 observers_.RemoveObserver(observer); | 299 observers_.RemoveObserver(observer); |
| 302 } | 300 } |
| 303 | 301 |
| 304 base::CancelableTaskTracker::TaskId HistoryService::ScheduleDBTask( | 302 base::CancelableTaskTracker::TaskId HistoryService::ScheduleDBTask( |
| 305 std::unique_ptr<HistoryDBTask> task, | 303 std::unique_ptr<HistoryDBTask> task, |
| 306 base::CancelableTaskTracker* tracker) { | 304 base::CancelableTaskTracker* tracker) { |
| 307 DCHECK(thread_) << "History service being called after cleanup"; | 305 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 308 DCHECK(thread_checker_.CalledOnValidThread()); | 306 DCHECK(thread_checker_.CalledOnValidThread()); |
| 309 base::CancelableTaskTracker::IsCanceledCallback is_canceled; | 307 base::CancelableTaskTracker::IsCanceledCallback is_canceled; |
| 310 base::CancelableTaskTracker::TaskId task_id = | 308 base::CancelableTaskTracker::TaskId task_id = |
| 311 tracker->NewTrackedTaskId(&is_canceled); | 309 tracker->NewTrackedTaskId(&is_canceled); |
| 312 // Use base::ThreadTaskRunnerHandler::Get() to get a task runner for | 310 // Use base::ThreadTaskRunnerHandler::Get() to get a task runner for |
| 313 // the current message loop so that we can forward the call to the method | 311 // the current message loop so that we can forward the call to the method |
| 314 // HistoryDBTask::DoneRunOnMainThread() in the correct thread. | 312 // HistoryDBTask::DoneRunOnMainThread() in the correct thread. |
| 315 thread_->task_runner()->PostTask( | 313 backend_task_runner_->PostTask( |
| 316 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTask, | 314 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTask, history_backend_, |
| 317 history_backend_, base::Passed(&task), | 315 base::Passed(&task), |
| 318 base::ThreadTaskRunnerHandle::Get(), is_canceled)); | 316 base::ThreadTaskRunnerHandle::Get(), is_canceled)); |
| 319 return task_id; | 317 return task_id; |
| 320 } | 318 } |
| 321 | 319 |
| 322 void HistoryService::FlushForTest(const base::Closure& flushed) { | 320 void HistoryService::FlushForTest(const base::Closure& flushed) { |
| 323 thread_->task_runner()->PostTaskAndReply( | 321 backend_task_runner_->PostTaskAndReply(FROM_HERE, |
| 324 FROM_HERE, base::Bind(&base::DoNothing), flushed); | 322 base::Bind(&base::DoNothing), flushed); |
| 325 } | 323 } |
| 326 | 324 |
| 327 void HistoryService::SetOnBackendDestroyTask(const base::Closure& task) { | 325 void HistoryService::SetOnBackendDestroyTask(const base::Closure& task) { |
| 328 DCHECK(thread_) << "History service being called after cleanup"; | 326 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 329 DCHECK(thread_checker_.CalledOnValidThread()); | 327 DCHECK(thread_checker_.CalledOnValidThread()); |
| 330 ScheduleTask( | 328 ScheduleTask( |
| 331 PRIORITY_NORMAL, | 329 PRIORITY_NORMAL, |
| 332 base::Bind(&HistoryBackend::SetOnBackendDestroyTask, history_backend_, | 330 base::Bind(&HistoryBackend::SetOnBackendDestroyTask, history_backend_, |
| 333 base::ThreadTaskRunnerHandle::Get(), task)); | 331 base::ThreadTaskRunnerHandle::Get(), task)); |
| 334 } | 332 } |
| 335 | 333 |
| 336 void HistoryService::TopHosts(size_t num_hosts, | 334 void HistoryService::TopHosts(size_t num_hosts, |
| 337 const TopHostsCallback& callback) const { | 335 const TopHostsCallback& callback) const { |
| 338 DCHECK(thread_) << "History service being called after cleanup"; | 336 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 339 DCHECK(thread_checker_.CalledOnValidThread()); | 337 DCHECK(thread_checker_.CalledOnValidThread()); |
| 340 PostTaskAndReplyWithResult( | 338 PostTaskAndReplyWithResult( |
| 341 thread_->task_runner().get(), FROM_HERE, | 339 backend_task_runner_.get(), FROM_HERE, |
| 342 base::Bind(&HistoryBackend::TopHosts, history_backend_, num_hosts), | 340 base::Bind(&HistoryBackend::TopHosts, history_backend_, num_hosts), |
| 343 callback); | 341 callback); |
| 344 } | 342 } |
| 345 | 343 |
| 346 void HistoryService::GetCountsAndLastVisitForOrigins( | 344 void HistoryService::GetCountsAndLastVisitForOrigins( |
| 347 const std::set<GURL>& origins, | 345 const std::set<GURL>& origins, |
| 348 const GetCountsAndLastVisitForOriginsCallback& callback) const { | 346 const GetCountsAndLastVisitForOriginsCallback& callback) const { |
| 349 DCHECK(thread_) << "History service being called after cleanup"; | 347 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 350 DCHECK(thread_checker_.CalledOnValidThread()); | 348 DCHECK(thread_checker_.CalledOnValidThread()); |
| 351 PostTaskAndReplyWithResult( | 349 PostTaskAndReplyWithResult( |
| 352 thread_->task_runner().get(), FROM_HERE, | 350 backend_task_runner_.get(), FROM_HERE, |
| 353 base::Bind(&HistoryBackend::GetCountsAndLastVisitForOrigins, | 351 base::Bind(&HistoryBackend::GetCountsAndLastVisitForOrigins, |
| 354 history_backend_, origins), | 352 history_backend_, origins), |
| 355 callback); | 353 callback); |
| 356 } | 354 } |
| 357 | 355 |
| 358 void HistoryService::HostRankIfAvailable( | 356 void HistoryService::HostRankIfAvailable( |
| 359 const GURL& url, | 357 const GURL& url, |
| 360 const base::Callback<void(int)>& callback) const { | 358 const base::Callback<void(int)>& callback) const { |
| 361 DCHECK(thread_) << "History service being called after cleanup"; | 359 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 362 DCHECK(thread_checker_.CalledOnValidThread()); | 360 DCHECK(thread_checker_.CalledOnValidThread()); |
| 363 PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE, | 361 PostTaskAndReplyWithResult( |
| 364 base::Bind(&HistoryBackend::HostRankIfAvailable, | 362 backend_task_runner_.get(), FROM_HERE, |
| 365 history_backend_, url), | 363 base::Bind(&HistoryBackend::HostRankIfAvailable, history_backend_, url), |
| 366 callback); | 364 callback); |
| 367 } | 365 } |
| 368 | 366 |
| 369 void HistoryService::AddPage(const GURL& url, | 367 void HistoryService::AddPage(const GURL& url, |
| 370 Time time, | 368 Time time, |
| 371 ContextID context_id, | 369 ContextID context_id, |
| 372 int nav_entry_id, | 370 int nav_entry_id, |
| 373 const GURL& referrer, | 371 const GURL& referrer, |
| 374 const RedirectList& redirects, | 372 const RedirectList& redirects, |
| 375 ui::PageTransition transition, | 373 ui::PageTransition transition, |
| 376 VisitSource visit_source, | 374 VisitSource visit_source, |
| 377 bool did_replace_entry) { | 375 bool did_replace_entry) { |
| 378 DCHECK(thread_checker_.CalledOnValidThread()); | 376 DCHECK(thread_checker_.CalledOnValidThread()); |
| 379 AddPage(HistoryAddPageArgs(url, time, context_id, nav_entry_id, referrer, | 377 AddPage(HistoryAddPageArgs(url, time, context_id, nav_entry_id, referrer, |
| 380 redirects, transition, visit_source, | 378 redirects, transition, visit_source, |
| 381 did_replace_entry, true)); | 379 did_replace_entry, true)); |
| 382 } | 380 } |
| 383 | 381 |
| 384 void HistoryService::AddPage(const GURL& url, | 382 void HistoryService::AddPage(const GURL& url, |
| 385 base::Time time, | 383 base::Time time, |
| 386 VisitSource visit_source) { | 384 VisitSource visit_source) { |
| 387 DCHECK(thread_checker_.CalledOnValidThread()); | 385 DCHECK(thread_checker_.CalledOnValidThread()); |
| 388 AddPage(HistoryAddPageArgs(url, time, nullptr, 0, GURL(), RedirectList(), | 386 AddPage(HistoryAddPageArgs(url, time, nullptr, 0, GURL(), RedirectList(), |
| 389 ui::PAGE_TRANSITION_LINK, visit_source, false, | 387 ui::PAGE_TRANSITION_LINK, visit_source, false, |
| 390 true)); | 388 true)); |
| 391 } | 389 } |
| 392 | 390 |
| 393 void HistoryService::AddPage(const HistoryAddPageArgs& add_page_args) { | 391 void HistoryService::AddPage(const HistoryAddPageArgs& add_page_args) { |
| 394 DCHECK(thread_) << "History service being called after cleanup"; | 392 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 395 DCHECK(thread_checker_.CalledOnValidThread()); | 393 DCHECK(thread_checker_.CalledOnValidThread()); |
| 396 | 394 |
| 397 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a | 395 // Filter out unwanted URLs. We don't add auto-subframe URLs. They are a |
| 398 // large part of history (think iframes for ads) and we never display them in | 396 // large part of history (think iframes for ads) and we never display them in |
| 399 // history UI. We will still add manual subframes, which are ones the user | 397 // history UI. We will still add manual subframes, which are ones the user |
| 400 // has clicked on to get. | 398 // has clicked on to get. |
| 401 if (history_client_ && !history_client_->CanAddURL(add_page_args.url)) | 399 if (history_client_ && !history_client_->CanAddURL(add_page_args.url)) |
| 402 return; | 400 return; |
| 403 | 401 |
| 404 // Inform VisitedDelegate of all links and redirects. | 402 // Inform VisitedDelegate of all links and redirects. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 415 } | 413 } |
| 416 } | 414 } |
| 417 | 415 |
| 418 ScheduleTask(PRIORITY_NORMAL, | 416 ScheduleTask(PRIORITY_NORMAL, |
| 419 base::Bind(&HistoryBackend::AddPage, history_backend_, | 417 base::Bind(&HistoryBackend::AddPage, history_backend_, |
| 420 add_page_args)); | 418 add_page_args)); |
| 421 } | 419 } |
| 422 | 420 |
| 423 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, | 421 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, |
| 424 const base::string16& title) { | 422 const base::string16& title) { |
| 425 DCHECK(thread_) << "History service being called after cleanup"; | 423 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 426 DCHECK(thread_checker_.CalledOnValidThread()); | 424 DCHECK(thread_checker_.CalledOnValidThread()); |
| 427 if (history_client_ && !history_client_->CanAddURL(url)) | 425 if (history_client_ && !history_client_->CanAddURL(url)) |
| 428 return; | 426 return; |
| 429 | 427 |
| 430 ScheduleTask(PRIORITY_NORMAL, | 428 ScheduleTask(PRIORITY_NORMAL, |
| 431 base::Bind(&HistoryBackend::AddPageNoVisitForBookmark, | 429 base::Bind(&HistoryBackend::AddPageNoVisitForBookmark, |
| 432 history_backend_, url, title)); | 430 history_backend_, url, title)); |
| 433 } | 431 } |
| 434 | 432 |
| 435 void HistoryService::SetPageTitle(const GURL& url, | 433 void HistoryService::SetPageTitle(const GURL& url, |
| 436 const base::string16& title) { | 434 const base::string16& title) { |
| 437 DCHECK(thread_) << "History service being called after cleanup"; | 435 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 438 DCHECK(thread_checker_.CalledOnValidThread()); | 436 DCHECK(thread_checker_.CalledOnValidThread()); |
| 439 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::SetPageTitle, | 437 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::SetPageTitle, |
| 440 history_backend_, url, title)); | 438 history_backend_, url, title)); |
| 441 } | 439 } |
| 442 | 440 |
| 443 void HistoryService::UpdateWithPageEndTime(ContextID context_id, | 441 void HistoryService::UpdateWithPageEndTime(ContextID context_id, |
| 444 int nav_entry_id, | 442 int nav_entry_id, |
| 445 const GURL& url, | 443 const GURL& url, |
| 446 Time end_ts) { | 444 Time end_ts) { |
| 447 DCHECK(thread_) << "History service being called after cleanup"; | 445 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 448 DCHECK(thread_checker_.CalledOnValidThread()); | 446 DCHECK(thread_checker_.CalledOnValidThread()); |
| 449 ScheduleTask( | 447 ScheduleTask( |
| 450 PRIORITY_NORMAL, | 448 PRIORITY_NORMAL, |
| 451 base::Bind(&HistoryBackend::UpdateWithPageEndTime, history_backend_, | 449 base::Bind(&HistoryBackend::UpdateWithPageEndTime, history_backend_, |
| 452 context_id, nav_entry_id, url, end_ts)); | 450 context_id, nav_entry_id, url, end_ts)); |
| 453 } | 451 } |
| 454 | 452 |
| 455 void HistoryService::AddPageWithDetails(const GURL& url, | 453 void HistoryService::AddPageWithDetails(const GURL& url, |
| 456 const base::string16& title, | 454 const base::string16& title, |
| 457 int visit_count, | 455 int visit_count, |
| 458 int typed_count, | 456 int typed_count, |
| 459 Time last_visit, | 457 Time last_visit, |
| 460 bool hidden, | 458 bool hidden, |
| 461 VisitSource visit_source) { | 459 VisitSource visit_source) { |
| 462 DCHECK(thread_) << "History service being called after cleanup"; | 460 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 463 DCHECK(thread_checker_.CalledOnValidThread()); | 461 DCHECK(thread_checker_.CalledOnValidThread()); |
| 464 // Filter out unwanted URLs. | 462 // Filter out unwanted URLs. |
| 465 if (history_client_ && !history_client_->CanAddURL(url)) | 463 if (history_client_ && !history_client_->CanAddURL(url)) |
| 466 return; | 464 return; |
| 467 | 465 |
| 468 // Inform VisitDelegate of the URL. | 466 // Inform VisitDelegate of the URL. |
| 469 if (visit_delegate_) | 467 if (visit_delegate_) |
| 470 visit_delegate_->AddURL(url); | 468 visit_delegate_->AddURL(url); |
| 471 | 469 |
| 472 URLRow row(url); | 470 URLRow row(url); |
| 473 row.set_title(title); | 471 row.set_title(title); |
| 474 row.set_visit_count(visit_count); | 472 row.set_visit_count(visit_count); |
| 475 row.set_typed_count(typed_count); | 473 row.set_typed_count(typed_count); |
| 476 row.set_last_visit(last_visit); | 474 row.set_last_visit(last_visit); |
| 477 row.set_hidden(hidden); | 475 row.set_hidden(hidden); |
| 478 | 476 |
| 479 URLRows rows; | 477 URLRows rows; |
| 480 rows.push_back(row); | 478 rows.push_back(row); |
| 481 | 479 |
| 482 ScheduleTask(PRIORITY_NORMAL, | 480 ScheduleTask(PRIORITY_NORMAL, |
| 483 base::Bind(&HistoryBackend::AddPagesWithDetails, | 481 base::Bind(&HistoryBackend::AddPagesWithDetails, |
| 484 history_backend_, rows, visit_source)); | 482 history_backend_, rows, visit_source)); |
| 485 } | 483 } |
| 486 | 484 |
| 487 void HistoryService::AddPagesWithDetails(const URLRows& info, | 485 void HistoryService::AddPagesWithDetails(const URLRows& info, |
| 488 VisitSource visit_source) { | 486 VisitSource visit_source) { |
| 489 DCHECK(thread_) << "History service being called after cleanup"; | 487 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 490 DCHECK(thread_checker_.CalledOnValidThread()); | 488 DCHECK(thread_checker_.CalledOnValidThread()); |
| 491 | 489 |
| 492 // Inform the VisitDelegate of the URLs | 490 // Inform the VisitDelegate of the URLs |
| 493 if (!info.empty() && visit_delegate_) { | 491 if (!info.empty() && visit_delegate_) { |
| 494 std::vector<GURL> urls; | 492 std::vector<GURL> urls; |
| 495 urls.reserve(info.size()); | 493 urls.reserve(info.size()); |
| 496 for (const auto& row : info) | 494 for (const auto& row : info) |
| 497 urls.push_back(row.url()); | 495 urls.push_back(row.url()); |
| 498 visit_delegate_->AddURLs(urls); | 496 visit_delegate_->AddURLs(urls); |
| 499 } | 497 } |
| 500 | 498 |
| 501 ScheduleTask(PRIORITY_NORMAL, | 499 ScheduleTask(PRIORITY_NORMAL, |
| 502 base::Bind(&HistoryBackend::AddPagesWithDetails, | 500 base::Bind(&HistoryBackend::AddPagesWithDetails, |
| 503 history_backend_, info, visit_source)); | 501 history_backend_, info, visit_source)); |
| 504 } | 502 } |
| 505 | 503 |
| 506 base::CancelableTaskTracker::TaskId HistoryService::GetFavicons( | 504 base::CancelableTaskTracker::TaskId HistoryService::GetFavicons( |
| 507 const std::vector<GURL>& icon_urls, | 505 const std::vector<GURL>& icon_urls, |
| 508 int icon_types, | 506 int icon_types, |
| 509 const std::vector<int>& desired_sizes, | 507 const std::vector<int>& desired_sizes, |
| 510 const favicon_base::FaviconResultsCallback& callback, | 508 const favicon_base::FaviconResultsCallback& callback, |
| 511 base::CancelableTaskTracker* tracker) { | 509 base::CancelableTaskTracker* tracker) { |
| 512 TRACE_EVENT0("browser", "HistoryService::GetFavicons"); | 510 TRACE_EVENT0("browser", "HistoryService::GetFavicons"); |
| 513 DCHECK(thread_) << "History service being called after cleanup"; | 511 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 514 DCHECK(thread_checker_.CalledOnValidThread()); | 512 DCHECK(thread_checker_.CalledOnValidThread()); |
| 515 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 513 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 516 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 514 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 517 return tracker->PostTaskAndReply( | 515 return tracker->PostTaskAndReply( |
| 518 thread_->task_runner().get(), FROM_HERE, | 516 backend_task_runner_.get(), FROM_HERE, |
| 519 base::Bind(&HistoryBackend::GetFavicons, history_backend_, | 517 base::Bind(&HistoryBackend::GetFavicons, history_backend_, icon_urls, |
| 520 icon_urls, icon_types, desired_sizes, results), | 518 icon_types, desired_sizes, results), |
| 521 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 519 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 522 } | 520 } |
| 523 | 521 |
| 524 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconsForURL( | 522 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconsForURL( |
| 525 const GURL& page_url, | 523 const GURL& page_url, |
| 526 int icon_types, | 524 int icon_types, |
| 527 const std::vector<int>& desired_sizes, | 525 const std::vector<int>& desired_sizes, |
| 528 const favicon_base::FaviconResultsCallback& callback, | 526 const favicon_base::FaviconResultsCallback& callback, |
| 529 base::CancelableTaskTracker* tracker) { | 527 base::CancelableTaskTracker* tracker) { |
| 530 TRACE_EVENT0("browser", "HistoryService::GetFaviconsForURL"); | 528 TRACE_EVENT0("browser", "HistoryService::GetFaviconsForURL"); |
| 531 DCHECK(thread_) << "History service being called after cleanup"; | 529 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 532 DCHECK(thread_checker_.CalledOnValidThread()); | 530 DCHECK(thread_checker_.CalledOnValidThread()); |
| 533 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 531 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 534 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 532 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 535 return tracker->PostTaskAndReply( | 533 return tracker->PostTaskAndReply( |
| 536 thread_->task_runner().get(), FROM_HERE, | 534 backend_task_runner_.get(), FROM_HERE, |
| 537 base::Bind(&HistoryBackend::GetFaviconsForURL, history_backend_, | 535 base::Bind(&HistoryBackend::GetFaviconsForURL, history_backend_, page_url, |
| 538 page_url, icon_types, desired_sizes, results), | 536 icon_types, desired_sizes, results), |
| 539 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 537 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 540 } | 538 } |
| 541 | 539 |
| 542 base::CancelableTaskTracker::TaskId HistoryService::GetLargestFaviconForURL( | 540 base::CancelableTaskTracker::TaskId HistoryService::GetLargestFaviconForURL( |
| 543 const GURL& page_url, | 541 const GURL& page_url, |
| 544 const std::vector<int>& icon_types, | 542 const std::vector<int>& icon_types, |
| 545 int minimum_size_in_pixels, | 543 int minimum_size_in_pixels, |
| 546 const favicon_base::FaviconRawBitmapCallback& callback, | 544 const favicon_base::FaviconRawBitmapCallback& callback, |
| 547 base::CancelableTaskTracker* tracker) { | 545 base::CancelableTaskTracker* tracker) { |
| 548 DCHECK(thread_) << "History service being called after cleanup"; | 546 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 549 DCHECK(thread_checker_.CalledOnValidThread()); | 547 DCHECK(thread_checker_.CalledOnValidThread()); |
| 550 favicon_base::FaviconRawBitmapResult* result = | 548 favicon_base::FaviconRawBitmapResult* result = |
| 551 new favicon_base::FaviconRawBitmapResult(); | 549 new favicon_base::FaviconRawBitmapResult(); |
| 552 return tracker->PostTaskAndReply( | 550 return tracker->PostTaskAndReply( |
| 553 thread_->task_runner().get(), FROM_HERE, | 551 backend_task_runner_.get(), FROM_HERE, |
| 554 base::Bind(&HistoryBackend::GetLargestFaviconForURL, | 552 base::Bind(&HistoryBackend::GetLargestFaviconForURL, history_backend_, |
| 555 history_backend_, page_url, icon_types, | 553 page_url, icon_types, minimum_size_in_pixels, result), |
| 556 minimum_size_in_pixels, result), | |
| 557 base::Bind(&RunWithFaviconResult, callback, base::Owned(result))); | 554 base::Bind(&RunWithFaviconResult, callback, base::Owned(result))); |
| 558 } | 555 } |
| 559 | 556 |
| 560 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconForID( | 557 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconForID( |
| 561 favicon_base::FaviconID favicon_id, | 558 favicon_base::FaviconID favicon_id, |
| 562 int desired_size, | 559 int desired_size, |
| 563 const favicon_base::FaviconResultsCallback& callback, | 560 const favicon_base::FaviconResultsCallback& callback, |
| 564 base::CancelableTaskTracker* tracker) { | 561 base::CancelableTaskTracker* tracker) { |
| 565 TRACE_EVENT0("browser", "HistoryService::GetFaviconForID"); | 562 TRACE_EVENT0("browser", "HistoryService::GetFaviconForID"); |
| 566 DCHECK(thread_) << "History service being called after cleanup"; | 563 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 567 DCHECK(thread_checker_.CalledOnValidThread()); | 564 DCHECK(thread_checker_.CalledOnValidThread()); |
| 568 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 565 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 569 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 566 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 570 return tracker->PostTaskAndReply( | 567 return tracker->PostTaskAndReply( |
| 571 thread_->task_runner().get(), FROM_HERE, | 568 backend_task_runner_.get(), FROM_HERE, |
| 572 base::Bind(&HistoryBackend::GetFaviconForID, history_backend_, | 569 base::Bind(&HistoryBackend::GetFaviconForID, history_backend_, favicon_id, |
| 573 favicon_id, desired_size, results), | 570 desired_size, results), |
| 574 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 571 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 575 } | 572 } |
| 576 | 573 |
| 577 base::CancelableTaskTracker::TaskId | 574 base::CancelableTaskTracker::TaskId |
| 578 HistoryService::UpdateFaviconMappingsAndFetch( | 575 HistoryService::UpdateFaviconMappingsAndFetch( |
| 579 const GURL& page_url, | 576 const GURL& page_url, |
| 580 const std::vector<GURL>& icon_urls, | 577 const std::vector<GURL>& icon_urls, |
| 581 int icon_types, | 578 int icon_types, |
| 582 const std::vector<int>& desired_sizes, | 579 const std::vector<int>& desired_sizes, |
| 583 const favicon_base::FaviconResultsCallback& callback, | 580 const favicon_base::FaviconResultsCallback& callback, |
| 584 base::CancelableTaskTracker* tracker) { | 581 base::CancelableTaskTracker* tracker) { |
| 585 TRACE_EVENT0("browser", "HistoryService::UpdateFaviconMappingsAndFetch"); | 582 TRACE_EVENT0("browser", "HistoryService::UpdateFaviconMappingsAndFetch"); |
| 586 DCHECK(thread_) << "History service being called after cleanup"; | 583 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 587 DCHECK(thread_checker_.CalledOnValidThread()); | 584 DCHECK(thread_checker_.CalledOnValidThread()); |
| 588 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 585 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 589 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 586 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 590 return tracker->PostTaskAndReply( | 587 return tracker->PostTaskAndReply( |
| 591 thread_->task_runner().get(), FROM_HERE, | 588 backend_task_runner_.get(), FROM_HERE, |
| 592 base::Bind(&HistoryBackend::UpdateFaviconMappingsAndFetch, | 589 base::Bind(&HistoryBackend::UpdateFaviconMappingsAndFetch, |
| 593 history_backend_, page_url, icon_urls, icon_types, | 590 history_backend_, page_url, icon_urls, icon_types, |
| 594 desired_sizes, results), | 591 desired_sizes, results), |
| 595 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 592 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 596 } | 593 } |
| 597 | 594 |
| 598 void HistoryService::MergeFavicon( | 595 void HistoryService::MergeFavicon( |
| 599 const GURL& page_url, | 596 const GURL& page_url, |
| 600 const GURL& icon_url, | 597 const GURL& icon_url, |
| 601 favicon_base::IconType icon_type, | 598 favicon_base::IconType icon_type, |
| 602 scoped_refptr<base::RefCountedMemory> bitmap_data, | 599 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 603 const gfx::Size& pixel_size) { | 600 const gfx::Size& pixel_size) { |
| 604 TRACE_EVENT0("browser", "HistoryService::MergeFavicon"); | 601 TRACE_EVENT0("browser", "HistoryService::MergeFavicon"); |
| 605 DCHECK(thread_) << "History service being called after cleanup"; | 602 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 606 DCHECK(thread_checker_.CalledOnValidThread()); | 603 DCHECK(thread_checker_.CalledOnValidThread()); |
| 607 if (history_client_ && !history_client_->CanAddURL(page_url)) | 604 if (history_client_ && !history_client_->CanAddURL(page_url)) |
| 608 return; | 605 return; |
| 609 | 606 |
| 610 ScheduleTask( | 607 ScheduleTask( |
| 611 PRIORITY_NORMAL, | 608 PRIORITY_NORMAL, |
| 612 base::Bind(&HistoryBackend::MergeFavicon, history_backend_, | 609 base::Bind(&HistoryBackend::MergeFavicon, history_backend_, |
| 613 page_url, icon_url, icon_type, bitmap_data, pixel_size)); | 610 page_url, icon_url, icon_type, bitmap_data, pixel_size)); |
| 614 } | 611 } |
| 615 | 612 |
| 616 void HistoryService::SetFavicons(const GURL& page_url, | 613 void HistoryService::SetFavicons(const GURL& page_url, |
| 617 favicon_base::IconType icon_type, | 614 favicon_base::IconType icon_type, |
| 618 const GURL& icon_url, | 615 const GURL& icon_url, |
| 619 const std::vector<SkBitmap>& bitmaps) { | 616 const std::vector<SkBitmap>& bitmaps) { |
| 620 DCHECK(thread_) << "History service being called after cleanup"; | 617 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 621 DCHECK(thread_checker_.CalledOnValidThread()); | 618 DCHECK(thread_checker_.CalledOnValidThread()); |
| 622 if (history_client_ && !history_client_->CanAddURL(page_url)) | 619 if (history_client_ && !history_client_->CanAddURL(page_url)) |
| 623 return; | 620 return; |
| 624 | 621 |
| 625 ScheduleTask(PRIORITY_NORMAL, | 622 ScheduleTask(PRIORITY_NORMAL, |
| 626 base::Bind(&HistoryBackend::SetFavicons, history_backend_, | 623 base::Bind(&HistoryBackend::SetFavicons, history_backend_, |
| 627 page_url, icon_type, icon_url, bitmaps)); | 624 page_url, icon_type, icon_url, bitmaps)); |
| 628 } | 625 } |
| 629 | 626 |
| 630 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 627 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
| 631 DCHECK(thread_) << "History service being called after cleanup"; | 628 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 632 DCHECK(thread_checker_.CalledOnValidThread()); | 629 DCHECK(thread_checker_.CalledOnValidThread()); |
| 633 ScheduleTask(PRIORITY_NORMAL, | 630 ScheduleTask(PRIORITY_NORMAL, |
| 634 base::Bind(&HistoryBackend::SetFaviconsOutOfDateForPage, | 631 base::Bind(&HistoryBackend::SetFaviconsOutOfDateForPage, |
| 635 history_backend_, page_url)); | 632 history_backend_, page_url)); |
| 636 } | 633 } |
| 637 | 634 |
| 638 void HistoryService::SetImportedFavicons( | 635 void HistoryService::SetImportedFavicons( |
| 639 const favicon_base::FaviconUsageDataList& favicon_usage) { | 636 const favicon_base::FaviconUsageDataList& favicon_usage) { |
| 640 DCHECK(thread_) << "History service being called after cleanup"; | 637 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 641 DCHECK(thread_checker_.CalledOnValidThread()); | 638 DCHECK(thread_checker_.CalledOnValidThread()); |
| 642 ScheduleTask(PRIORITY_NORMAL, | 639 ScheduleTask(PRIORITY_NORMAL, |
| 643 base::Bind(&HistoryBackend::SetImportedFavicons, | 640 base::Bind(&HistoryBackend::SetImportedFavicons, |
| 644 history_backend_, favicon_usage)); | 641 history_backend_, favicon_usage)); |
| 645 } | 642 } |
| 646 | 643 |
| 647 base::CancelableTaskTracker::TaskId HistoryService::QueryURL( | 644 base::CancelableTaskTracker::TaskId HistoryService::QueryURL( |
| 648 const GURL& url, | 645 const GURL& url, |
| 649 bool want_visits, | 646 bool want_visits, |
| 650 const QueryURLCallback& callback, | 647 const QueryURLCallback& callback, |
| 651 base::CancelableTaskTracker* tracker) { | 648 base::CancelableTaskTracker* tracker) { |
| 652 DCHECK(thread_) << "History service being called after cleanup"; | 649 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 653 DCHECK(thread_checker_.CalledOnValidThread()); | 650 DCHECK(thread_checker_.CalledOnValidThread()); |
| 654 QueryURLResult* query_url_result = new QueryURLResult(); | 651 QueryURLResult* query_url_result = new QueryURLResult(); |
| 655 return tracker->PostTaskAndReply( | 652 return tracker->PostTaskAndReply( |
| 656 thread_->task_runner().get(), FROM_HERE, | 653 backend_task_runner_.get(), FROM_HERE, |
| 657 base::Bind(&HistoryBackend::QueryURL, history_backend_, url, | 654 base::Bind(&HistoryBackend::QueryURL, history_backend_, url, want_visits, |
| 658 want_visits, base::Unretained(query_url_result)), | 655 base::Unretained(query_url_result)), |
| 659 base::Bind(&RunWithQueryURLResult, callback, | 656 base::Bind(&RunWithQueryURLResult, callback, |
| 660 base::Owned(query_url_result))); | 657 base::Owned(query_url_result))); |
| 661 } | 658 } |
| 662 | 659 |
| 663 // Statistics ------------------------------------------------------------------ | 660 // Statistics ------------------------------------------------------------------ |
| 664 | 661 |
| 665 base::CancelableTaskTracker::TaskId HistoryService::GetHistoryCount( | 662 base::CancelableTaskTracker::TaskId HistoryService::GetHistoryCount( |
| 666 const Time& begin_time, | 663 const Time& begin_time, |
| 667 const Time& end_time, | 664 const Time& end_time, |
| 668 const GetHistoryCountCallback& callback, | 665 const GetHistoryCountCallback& callback, |
| 669 base::CancelableTaskTracker* tracker) { | 666 base::CancelableTaskTracker* tracker) { |
| 670 DCHECK(thread_) << "History service being called after cleanup"; | 667 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 671 DCHECK(thread_checker_.CalledOnValidThread()); | 668 DCHECK(thread_checker_.CalledOnValidThread()); |
| 672 | 669 |
| 673 return tracker->PostTaskAndReplyWithResult( | 670 return tracker->PostTaskAndReplyWithResult( |
| 674 thread_->task_runner().get(), FROM_HERE, | 671 backend_task_runner_.get(), FROM_HERE, |
| 675 base::Bind(&HistoryBackend::GetHistoryCount, | 672 base::Bind(&HistoryBackend::GetHistoryCount, history_backend_, begin_time, |
| 676 history_backend_, | |
| 677 begin_time, | |
| 678 end_time), | 673 end_time), |
| 679 callback); | 674 callback); |
| 680 } | 675 } |
| 681 | 676 |
| 682 // Downloads ------------------------------------------------------------------- | 677 // Downloads ------------------------------------------------------------------- |
| 683 | 678 |
| 684 // Handle creation of a download by creating an entry in the history service's | 679 // Handle creation of a download by creating an entry in the history service's |
| 685 // 'downloads' table. | 680 // 'downloads' table. |
| 686 void HistoryService::CreateDownload( | 681 void HistoryService::CreateDownload( |
| 687 const DownloadRow& create_info, | 682 const DownloadRow& create_info, |
| 688 const HistoryService::DownloadCreateCallback& callback) { | 683 const HistoryService::DownloadCreateCallback& callback) { |
| 689 DCHECK(thread_) << "History service being called after cleanup"; | 684 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 690 DCHECK(thread_checker_.CalledOnValidThread()); | 685 DCHECK(thread_checker_.CalledOnValidThread()); |
| 691 PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE, | 686 PostTaskAndReplyWithResult(backend_task_runner_.get(), FROM_HERE, |
| 692 base::Bind(&HistoryBackend::CreateDownload, | 687 base::Bind(&HistoryBackend::CreateDownload, |
| 693 history_backend_, create_info), | 688 history_backend_, create_info), |
| 694 callback); | 689 callback); |
| 695 } | 690 } |
| 696 | 691 |
| 697 void HistoryService::GetNextDownloadId(const DownloadIdCallback& callback) { | 692 void HistoryService::GetNextDownloadId(const DownloadIdCallback& callback) { |
| 698 DCHECK(thread_) << "History service being called after cleanup"; | 693 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 699 DCHECK(thread_checker_.CalledOnValidThread()); | 694 DCHECK(thread_checker_.CalledOnValidThread()); |
| 700 PostTaskAndReplyWithResult( | 695 PostTaskAndReplyWithResult( |
| 701 thread_->task_runner().get(), FROM_HERE, | 696 backend_task_runner_.get(), FROM_HERE, |
| 702 base::Bind(&HistoryBackend::GetNextDownloadId, history_backend_), | 697 base::Bind(&HistoryBackend::GetNextDownloadId, history_backend_), |
| 703 callback); | 698 callback); |
| 704 } | 699 } |
| 705 | 700 |
| 706 // Handle queries for a list of all downloads in the history database's | 701 // Handle queries for a list of all downloads in the history database's |
| 707 // 'downloads' table. | 702 // 'downloads' table. |
| 708 void HistoryService::QueryDownloads(const DownloadQueryCallback& callback) { | 703 void HistoryService::QueryDownloads(const DownloadQueryCallback& callback) { |
| 709 DCHECK(thread_) << "History service being called after cleanup"; | 704 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 710 DCHECK(thread_checker_.CalledOnValidThread()); | 705 DCHECK(thread_checker_.CalledOnValidThread()); |
| 711 std::vector<DownloadRow>* rows = new std::vector<DownloadRow>(); | 706 std::vector<DownloadRow>* rows = new std::vector<DownloadRow>(); |
| 712 std::unique_ptr<std::vector<DownloadRow>> scoped_rows(rows); | 707 std::unique_ptr<std::vector<DownloadRow>> scoped_rows(rows); |
| 713 // Beware! The first Bind() does not simply |scoped_rows.get()| because | 708 // Beware! The first Bind() does not simply |scoped_rows.get()| because |
| 714 // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not | 709 // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not |
| 715 // guarantee that the first Bind's arguments are evaluated before the second | 710 // guarantee that the first Bind's arguments are evaluated before the second |
| 716 // Bind's arguments. | 711 // Bind's arguments. |
| 717 thread_->task_runner()->PostTaskAndReply( | 712 backend_task_runner_->PostTaskAndReply( |
| 718 FROM_HERE, | 713 FROM_HERE, |
| 719 base::Bind(&HistoryBackend::QueryDownloads, history_backend_, rows), | 714 base::Bind(&HistoryBackend::QueryDownloads, history_backend_, rows), |
| 720 base::Bind(callback, base::Passed(&scoped_rows))); | 715 base::Bind(callback, base::Passed(&scoped_rows))); |
| 721 } | 716 } |
| 722 | 717 |
| 723 // Handle updates for a particular download. This is a 'fire and forget' | 718 // Handle updates for a particular download. This is a 'fire and forget' |
| 724 // operation, so we don't need to be called back. | 719 // operation, so we don't need to be called back. |
| 725 void HistoryService::UpdateDownload(const DownloadRow& data) { | 720 void HistoryService::UpdateDownload(const DownloadRow& data) { |
| 726 DCHECK(thread_) << "History service being called after cleanup"; | 721 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 727 DCHECK(thread_checker_.CalledOnValidThread()); | 722 DCHECK(thread_checker_.CalledOnValidThread()); |
| 728 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::UpdateDownload, | 723 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::UpdateDownload, |
| 729 history_backend_, data)); | 724 history_backend_, data)); |
| 730 } | 725 } |
| 731 | 726 |
| 732 void HistoryService::RemoveDownloads(const std::set<uint32_t>& ids) { | 727 void HistoryService::RemoveDownloads(const std::set<uint32_t>& ids) { |
| 733 DCHECK(thread_) << "History service being called after cleanup"; | 728 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 734 DCHECK(thread_checker_.CalledOnValidThread()); | 729 DCHECK(thread_checker_.CalledOnValidThread()); |
| 735 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::RemoveDownloads, | 730 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::RemoveDownloads, |
| 736 history_backend_, ids)); | 731 history_backend_, ids)); |
| 737 } | 732 } |
| 738 | 733 |
| 739 base::CancelableTaskTracker::TaskId HistoryService::QueryHistory( | 734 base::CancelableTaskTracker::TaskId HistoryService::QueryHistory( |
| 740 const base::string16& text_query, | 735 const base::string16& text_query, |
| 741 const QueryOptions& options, | 736 const QueryOptions& options, |
| 742 const QueryHistoryCallback& callback, | 737 const QueryHistoryCallback& callback, |
| 743 base::CancelableTaskTracker* tracker) { | 738 base::CancelableTaskTracker* tracker) { |
| 744 DCHECK(thread_) << "History service being called after cleanup"; | 739 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 745 DCHECK(thread_checker_.CalledOnValidThread()); | 740 DCHECK(thread_checker_.CalledOnValidThread()); |
| 746 QueryResults* query_results = new QueryResults(); | 741 QueryResults* query_results = new QueryResults(); |
| 747 return tracker->PostTaskAndReply( | 742 return tracker->PostTaskAndReply( |
| 748 thread_->task_runner().get(), FROM_HERE, | 743 backend_task_runner_.get(), FROM_HERE, |
| 749 base::Bind(&HistoryBackend::QueryHistory, history_backend_, | 744 base::Bind(&HistoryBackend::QueryHistory, history_backend_, text_query, |
| 750 text_query, options, base::Unretained(query_results)), | 745 options, base::Unretained(query_results)), |
| 751 base::Bind(callback, base::Owned(query_results))); | 746 base::Bind(callback, base::Owned(query_results))); |
| 752 } | 747 } |
| 753 | 748 |
| 754 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsFrom( | 749 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsFrom( |
| 755 const GURL& from_url, | 750 const GURL& from_url, |
| 756 const QueryRedirectsCallback& callback, | 751 const QueryRedirectsCallback& callback, |
| 757 base::CancelableTaskTracker* tracker) { | 752 base::CancelableTaskTracker* tracker) { |
| 758 DCHECK(thread_) << "History service being called after cleanup"; | 753 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 759 DCHECK(thread_checker_.CalledOnValidThread()); | 754 DCHECK(thread_checker_.CalledOnValidThread()); |
| 760 RedirectList* result = new RedirectList(); | 755 RedirectList* result = new RedirectList(); |
| 761 return tracker->PostTaskAndReply( | 756 return tracker->PostTaskAndReply( |
| 762 thread_->task_runner().get(), FROM_HERE, | 757 backend_task_runner_.get(), FROM_HERE, |
| 763 base::Bind(&HistoryBackend::QueryRedirectsFrom, history_backend_, | 758 base::Bind(&HistoryBackend::QueryRedirectsFrom, history_backend_, |
| 764 from_url, base::Unretained(result)), | 759 from_url, base::Unretained(result)), |
| 765 base::Bind(callback, base::Owned(result))); | 760 base::Bind(callback, base::Owned(result))); |
| 766 } | 761 } |
| 767 | 762 |
| 768 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsTo( | 763 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsTo( |
| 769 const GURL& to_url, | 764 const GURL& to_url, |
| 770 const QueryRedirectsCallback& callback, | 765 const QueryRedirectsCallback& callback, |
| 771 base::CancelableTaskTracker* tracker) { | 766 base::CancelableTaskTracker* tracker) { |
| 772 DCHECK(thread_) << "History service being called after cleanup"; | 767 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 773 DCHECK(thread_checker_.CalledOnValidThread()); | 768 DCHECK(thread_checker_.CalledOnValidThread()); |
| 774 RedirectList* result = new RedirectList(); | 769 RedirectList* result = new RedirectList(); |
| 775 return tracker->PostTaskAndReply( | 770 return tracker->PostTaskAndReply( |
| 776 thread_->task_runner().get(), FROM_HERE, | 771 backend_task_runner_.get(), FROM_HERE, |
| 777 base::Bind(&HistoryBackend::QueryRedirectsTo, history_backend_, | 772 base::Bind(&HistoryBackend::QueryRedirectsTo, history_backend_, to_url, |
| 778 to_url, base::Unretained(result)), | 773 base::Unretained(result)), |
| 779 base::Bind(callback, base::Owned(result))); | 774 base::Bind(callback, base::Owned(result))); |
| 780 } | 775 } |
| 781 | 776 |
| 782 base::CancelableTaskTracker::TaskId HistoryService::GetVisibleVisitCountToHost( | 777 base::CancelableTaskTracker::TaskId HistoryService::GetVisibleVisitCountToHost( |
| 783 const GURL& url, | 778 const GURL& url, |
| 784 const GetVisibleVisitCountToHostCallback& callback, | 779 const GetVisibleVisitCountToHostCallback& callback, |
| 785 base::CancelableTaskTracker* tracker) { | 780 base::CancelableTaskTracker* tracker) { |
| 786 DCHECK(thread_) << "History service being called after cleanup"; | 781 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 787 DCHECK(thread_checker_.CalledOnValidThread()); | 782 DCHECK(thread_checker_.CalledOnValidThread()); |
| 788 VisibleVisitCountToHostResult* result = new VisibleVisitCountToHostResult(); | 783 VisibleVisitCountToHostResult* result = new VisibleVisitCountToHostResult(); |
| 789 return tracker->PostTaskAndReply( | 784 return tracker->PostTaskAndReply( |
| 790 thread_->task_runner().get(), FROM_HERE, | 785 backend_task_runner_.get(), FROM_HERE, |
| 791 base::Bind(&HistoryBackend::GetVisibleVisitCountToHost, | 786 base::Bind(&HistoryBackend::GetVisibleVisitCountToHost, history_backend_, |
| 792 history_backend_, url, base::Unretained(result)), | 787 url, base::Unretained(result)), |
| 793 base::Bind(&RunWithVisibleVisitCountToHostResult, callback, | 788 base::Bind(&RunWithVisibleVisitCountToHostResult, callback, |
| 794 base::Owned(result))); | 789 base::Owned(result))); |
| 795 } | 790 } |
| 796 | 791 |
| 797 base::CancelableTaskTracker::TaskId HistoryService::QueryMostVisitedURLs( | 792 base::CancelableTaskTracker::TaskId HistoryService::QueryMostVisitedURLs( |
| 798 int result_count, | 793 int result_count, |
| 799 int days_back, | 794 int days_back, |
| 800 const QueryMostVisitedURLsCallback& callback, | 795 const QueryMostVisitedURLsCallback& callback, |
| 801 base::CancelableTaskTracker* tracker) { | 796 base::CancelableTaskTracker* tracker) { |
| 802 DCHECK(thread_) << "History service being called after cleanup"; | 797 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 803 DCHECK(thread_checker_.CalledOnValidThread()); | 798 DCHECK(thread_checker_.CalledOnValidThread()); |
| 804 MostVisitedURLList* result = new MostVisitedURLList(); | 799 MostVisitedURLList* result = new MostVisitedURLList(); |
| 805 return tracker->PostTaskAndReply( | 800 return tracker->PostTaskAndReply( |
| 806 thread_->task_runner().get(), FROM_HERE, | 801 backend_task_runner_.get(), FROM_HERE, |
| 807 base::Bind(&HistoryBackend::QueryMostVisitedURLs, history_backend_, | 802 base::Bind(&HistoryBackend::QueryMostVisitedURLs, history_backend_, |
| 808 result_count, days_back, base::Unretained(result)), | 803 result_count, days_back, base::Unretained(result)), |
| 809 base::Bind(callback, base::Owned(result))); | 804 base::Bind(callback, base::Owned(result))); |
| 810 } | 805 } |
| 811 | 806 |
| 812 void HistoryService::Cleanup() { | 807 void HistoryService::Cleanup() { |
| 813 DCHECK(thread_checker_.CalledOnValidThread()); | 808 DCHECK(thread_checker_.CalledOnValidThread()); |
| 814 if (!thread_) { | 809 if (!backend_task_runner_) { |
| 815 // We've already cleaned up. | 810 // We've already cleaned up. |
| 816 return; | 811 return; |
| 817 } | 812 } |
| 818 | 813 |
| 819 NotifyHistoryServiceBeingDeleted(); | 814 NotifyHistoryServiceBeingDeleted(); |
| 820 | 815 |
| 821 weak_ptr_factory_.InvalidateWeakPtrs(); | 816 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 822 | 817 |
| 823 // Inform the HistoryClient that we are shuting down. | 818 // Inform the HistoryClient that we are shuting down. |
| 824 if (history_client_) | 819 if (history_client_) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 849 // | 844 // |
| 850 // TODO(ajwong): Cleanup HistoryBackend lifetime issues. | 845 // TODO(ajwong): Cleanup HistoryBackend lifetime issues. |
| 851 // See http://crbug.com/99767. | 846 // See http://crbug.com/99767. |
| 852 history_backend_->AddRef(); | 847 history_backend_->AddRef(); |
| 853 base::Closure closing_task = | 848 base::Closure closing_task = |
| 854 base::Bind(&HistoryBackend::Closing, history_backend_); | 849 base::Bind(&HistoryBackend::Closing, history_backend_); |
| 855 ScheduleTask(PRIORITY_NORMAL, closing_task); | 850 ScheduleTask(PRIORITY_NORMAL, closing_task); |
| 856 closing_task.Reset(); | 851 closing_task.Reset(); |
| 857 HistoryBackend* raw_ptr = history_backend_.get(); | 852 HistoryBackend* raw_ptr = history_backend_.get(); |
| 858 history_backend_ = nullptr; | 853 history_backend_ = nullptr; |
| 859 thread_->task_runner()->ReleaseSoon(FROM_HERE, raw_ptr); | 854 backend_task_runner_->ReleaseSoon(FROM_HERE, raw_ptr); |
| 860 } | 855 } |
| 861 | 856 |
| 862 // Delete the thread, which joins with the background thread. We defensively | 857 // Clear |backend_task_runner_| to make sure it's not used after Cleanup(). |
| 863 // nullptr the pointer before deleting it in case somebody tries to use it | 858 backend_task_runner_ = nullptr; |
| 864 // during shutdown, but this shouldn't happen. | 859 |
| 865 base::Thread* thread = thread_; | 860 // Join the background thread, if any. |
| 866 thread_ = nullptr; | 861 thread_.reset(); |
| 867 delete thread; | |
| 868 } | 862 } |
| 869 | 863 |
| 870 bool HistoryService::Init( | 864 bool HistoryService::Init( |
| 871 bool no_db, | 865 bool no_db, |
| 872 const HistoryDatabaseParams& history_database_params) { | 866 const HistoryDatabaseParams& history_database_params) { |
| 873 TRACE_EVENT0("browser,startup", "HistoryService::Init") | 867 TRACE_EVENT0("browser,startup", "HistoryService::Init") |
| 874 SCOPED_UMA_HISTOGRAM_TIMER("History.HistoryServiceInitTime"); | 868 SCOPED_UMA_HISTOGRAM_TIMER("History.HistoryServiceInitTime"); |
| 875 DCHECK(thread_) << "History service being called after cleanup"; | |
| 876 DCHECK(thread_checker_.CalledOnValidThread()); | 869 DCHECK(thread_checker_.CalledOnValidThread()); |
| 870 DCHECK(!backend_task_runner_); |
| 877 | 871 |
| 878 base::Thread::Options options; | 872 if (thread_) { |
| 879 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 873 base::Thread::Options options; |
| 880 if (!thread_->StartWithOptions(options)) { | 874 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 881 Cleanup(); | 875 if (!thread_->StartWithOptions(options)) { |
| 882 return false; | 876 Cleanup(); |
| 877 return false; |
| 878 } |
| 879 backend_task_runner_ = thread_->task_runner(); |
| 880 } else { |
| 881 backend_task_runner_ = base::CreateSequencedTaskRunnerWithTraits( |
| 882 base::TaskTraits() |
| 883 .WithPriority(base::TaskPriority::USER_BLOCKING) |
| 884 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN) |
| 885 .WithFileIO()); |
| 883 } | 886 } |
| 884 | 887 |
| 885 // Create the history backend. | 888 // Create the history backend. |
| 886 scoped_refptr<HistoryBackend> backend(new HistoryBackend( | 889 scoped_refptr<HistoryBackend> backend(new HistoryBackend( |
| 887 new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), | 890 new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), |
| 888 base::ThreadTaskRunnerHandle::Get()), | 891 base::ThreadTaskRunnerHandle::Get()), |
| 889 history_client_ ? history_client_->CreateBackendClient() : nullptr, | 892 history_client_ ? history_client_->CreateBackendClient() : nullptr, |
| 890 thread_->task_runner())); | 893 backend_task_runner_)); |
| 891 history_backend_.swap(backend); | 894 history_backend_.swap(backend); |
| 892 | 895 |
| 893 ScheduleTask(PRIORITY_UI, | 896 ScheduleTask(PRIORITY_UI, |
| 894 base::Bind(&HistoryBackend::Init, history_backend_, | 897 base::Bind(&HistoryBackend::Init, history_backend_, |
| 895 no_db, history_database_params)); | 898 no_db, history_database_params)); |
| 896 | 899 |
| 897 if (visit_delegate_ && !visit_delegate_->Init(this)) | 900 if (visit_delegate_ && !visit_delegate_->Init(this)) |
| 898 return false; | 901 return false; |
| 899 | 902 |
| 900 if (history_client_) | 903 if (history_client_) |
| 901 history_client_->OnHistoryServiceCreated(this); | 904 history_client_->OnHistoryServiceCreated(this); |
| 902 | 905 |
| 903 return true; | 906 return true; |
| 904 } | 907 } |
| 905 | 908 |
| 906 void HistoryService::ScheduleAutocomplete( | 909 void HistoryService::ScheduleAutocomplete( |
| 907 const base::Callback<void(HistoryBackend*, URLDatabase*)>& callback) { | 910 const base::Callback<void(HistoryBackend*, URLDatabase*)>& callback) { |
| 908 DCHECK(thread_checker_.CalledOnValidThread()); | 911 DCHECK(thread_checker_.CalledOnValidThread()); |
| 909 ScheduleTask(PRIORITY_UI, base::Bind(&HistoryBackend::ScheduleAutocomplete, | 912 ScheduleTask(PRIORITY_UI, base::Bind(&HistoryBackend::ScheduleAutocomplete, |
| 910 history_backend_, callback)); | 913 history_backend_, callback)); |
| 911 } | 914 } |
| 912 | 915 |
| 913 void HistoryService::ScheduleTask(SchedulePriority priority, | 916 void HistoryService::ScheduleTask(SchedulePriority priority, |
| 914 const base::Closure& task) { | 917 const base::Closure& task) { |
| 915 DCHECK(thread_checker_.CalledOnValidThread()); | 918 DCHECK(thread_checker_.CalledOnValidThread()); |
| 916 CHECK(thread_); | 919 CHECK(backend_task_runner_); |
| 917 CHECK(thread_->message_loop()); | |
| 918 // TODO(brettw): Do prioritization. | 920 // TODO(brettw): Do prioritization. |
| 919 thread_->task_runner()->PostTask(FROM_HERE, task); | 921 backend_task_runner_->PostTask(FROM_HERE, task); |
| 920 } | 922 } |
| 921 | 923 |
| 922 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { | 924 base::WeakPtr<HistoryService> HistoryService::AsWeakPtr() { |
| 923 DCHECK(thread_checker_.CalledOnValidThread()); | 925 DCHECK(thread_checker_.CalledOnValidThread()); |
| 924 return weak_ptr_factory_.GetWeakPtr(); | 926 return weak_ptr_factory_.GetWeakPtr(); |
| 925 } | 927 } |
| 926 | 928 |
| 927 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( | 929 syncer::SyncMergeResult HistoryService::MergeDataAndStartSyncing( |
| 928 syncer::ModelType type, | 930 syncer::ModelType type, |
| 929 const syncer::SyncDataList& initial_sync_data, | 931 const syncer::SyncDataList& initial_sync_data, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 } | 977 } |
| 976 | 978 |
| 977 void HistoryService::NotifyProfileError(sql::InitStatus init_status, | 979 void HistoryService::NotifyProfileError(sql::InitStatus init_status, |
| 978 const std::string& diagnostics) { | 980 const std::string& diagnostics) { |
| 979 DCHECK(thread_checker_.CalledOnValidThread()); | 981 DCHECK(thread_checker_.CalledOnValidThread()); |
| 980 if (history_client_) | 982 if (history_client_) |
| 981 history_client_->NotifyProfileError(init_status, diagnostics); | 983 history_client_->NotifyProfileError(init_status, diagnostics); |
| 982 } | 984 } |
| 983 | 985 |
| 984 void HistoryService::DeleteURL(const GURL& url) { | 986 void HistoryService::DeleteURL(const GURL& url) { |
| 985 DCHECK(thread_) << "History service being called after cleanup"; | 987 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 986 DCHECK(thread_checker_.CalledOnValidThread()); | 988 DCHECK(thread_checker_.CalledOnValidThread()); |
| 987 // We will update the visited links when we observe the delete notifications. | 989 // We will update the visited links when we observe the delete notifications. |
| 988 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURL, | 990 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURL, |
| 989 history_backend_, url)); | 991 history_backend_, url)); |
| 990 } | 992 } |
| 991 | 993 |
| 992 void HistoryService::DeleteURLsForTest(const std::vector<GURL>& urls) { | 994 void HistoryService::DeleteURLsForTest(const std::vector<GURL>& urls) { |
| 993 DCHECK(thread_) << "History service being called after cleanup"; | 995 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 994 DCHECK(thread_checker_.CalledOnValidThread()); | 996 DCHECK(thread_checker_.CalledOnValidThread()); |
| 995 // We will update the visited links when we observe the delete | 997 // We will update the visited links when we observe the delete |
| 996 // notifications. | 998 // notifications. |
| 997 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURLs, | 999 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURLs, |
| 998 history_backend_, urls)); | 1000 history_backend_, urls)); |
| 999 } | 1001 } |
| 1000 | 1002 |
| 1001 void HistoryService::ExpireHistoryBetween( | 1003 void HistoryService::ExpireHistoryBetween( |
| 1002 const std::set<GURL>& restrict_urls, | 1004 const std::set<GURL>& restrict_urls, |
| 1003 Time begin_time, | 1005 Time begin_time, |
| 1004 Time end_time, | 1006 Time end_time, |
| 1005 const base::Closure& callback, | 1007 const base::Closure& callback, |
| 1006 base::CancelableTaskTracker* tracker) { | 1008 base::CancelableTaskTracker* tracker) { |
| 1007 DCHECK(thread_) << "History service being called after cleanup"; | 1009 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 1008 DCHECK(thread_checker_.CalledOnValidThread()); | 1010 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1009 tracker->PostTaskAndReply( | 1011 tracker->PostTaskAndReply( |
| 1010 thread_->task_runner().get(), FROM_HERE, | 1012 backend_task_runner_.get(), FROM_HERE, |
| 1011 base::Bind(&HistoryBackend::ExpireHistoryBetween, history_backend_, | 1013 base::Bind(&HistoryBackend::ExpireHistoryBetween, history_backend_, |
| 1012 restrict_urls, begin_time, end_time), | 1014 restrict_urls, begin_time, end_time), |
| 1013 callback); | 1015 callback); |
| 1014 } | 1016 } |
| 1015 | 1017 |
| 1016 void HistoryService::ExpireHistory( | 1018 void HistoryService::ExpireHistory( |
| 1017 const std::vector<ExpireHistoryArgs>& expire_list, | 1019 const std::vector<ExpireHistoryArgs>& expire_list, |
| 1018 const base::Closure& callback, | 1020 const base::Closure& callback, |
| 1019 base::CancelableTaskTracker* tracker) { | 1021 base::CancelableTaskTracker* tracker) { |
| 1020 DCHECK(thread_) << "History service being called after cleanup"; | 1022 DCHECK(backend_task_runner_) << "History service being called after cleanup"; |
| 1021 DCHECK(thread_checker_.CalledOnValidThread()); | 1023 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1022 tracker->PostTaskAndReply( | 1024 tracker->PostTaskAndReply( |
| 1023 thread_->task_runner().get(), FROM_HERE, | 1025 backend_task_runner_.get(), FROM_HERE, |
| 1024 base::Bind(&HistoryBackend::ExpireHistory, history_backend_, expire_list), | 1026 base::Bind(&HistoryBackend::ExpireHistory, history_backend_, expire_list), |
| 1025 callback); | 1027 callback); |
| 1026 } | 1028 } |
| 1027 | 1029 |
| 1028 void HistoryService::ExpireLocalAndRemoteHistoryBetween( | 1030 void HistoryService::ExpireLocalAndRemoteHistoryBetween( |
| 1029 WebHistoryService* web_history, | 1031 WebHistoryService* web_history, |
| 1030 const std::set<GURL>& restrict_urls, | 1032 const std::set<GURL>& restrict_urls, |
| 1031 Time begin_time, | 1033 Time begin_time, |
| 1032 Time end_time, | 1034 Time end_time, |
| 1033 const base::Closure& callback, | 1035 const base::Closure& callback, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 DCHECK(thread_checker_.CalledOnValidThread()); | 1073 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1072 for (HistoryServiceObserver& observer : observers_) | 1074 for (HistoryServiceObserver& observer : observers_) |
| 1073 observer.OnURLsModified(this, changed_urls); | 1075 observer.OnURLsModified(this, changed_urls); |
| 1074 } | 1076 } |
| 1075 | 1077 |
| 1076 void HistoryService::NotifyURLsDeleted(bool all_history, | 1078 void HistoryService::NotifyURLsDeleted(bool all_history, |
| 1077 bool expired, | 1079 bool expired, |
| 1078 const URLRows& deleted_rows, | 1080 const URLRows& deleted_rows, |
| 1079 const std::set<GURL>& favicon_urls) { | 1081 const std::set<GURL>& favicon_urls) { |
| 1080 DCHECK(thread_checker_.CalledOnValidThread()); | 1082 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1081 if (!thread_) | 1083 if (!backend_task_runner_) |
| 1082 return; | 1084 return; |
| 1083 | 1085 |
| 1084 // Inform the VisitDelegate of the deleted URLs. We will inform the delegate | 1086 // Inform the VisitDelegate of the deleted URLs. We will inform the delegate |
| 1085 // of added URLs as soon as we get the add notification (we don't have to wait | 1087 // of added URLs as soon as we get the add notification (we don't have to wait |
| 1086 // for the backend, which allows us to be faster to update the state). | 1088 // for the backend, which allows us to be faster to update the state). |
| 1087 // | 1089 // |
| 1088 // For deleted URLs, we don't typically know what will be deleted since | 1090 // For deleted URLs, we don't typically know what will be deleted since |
| 1089 // delete notifications are by time. We would also like to be more | 1091 // delete notifications are by time. We would also like to be more |
| 1090 // respectful of privacy and never tell the user something is gone when it | 1092 // respectful of privacy and never tell the user something is gone when it |
| 1091 // isn't. Therefore, we update the delete URLs after the fact. | 1093 // isn't. Therefore, we update the delete URLs after the fact. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 return favicon_changed_callback_list_.Add(callback); | 1144 return favicon_changed_callback_list_.Add(callback); |
| 1143 } | 1145 } |
| 1144 | 1146 |
| 1145 void HistoryService::NotifyFaviconsChanged(const std::set<GURL>& page_urls, | 1147 void HistoryService::NotifyFaviconsChanged(const std::set<GURL>& page_urls, |
| 1146 const GURL& icon_url) { | 1148 const GURL& icon_url) { |
| 1147 DCHECK(thread_checker_.CalledOnValidThread()); | 1149 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1148 favicon_changed_callback_list_.Notify(page_urls, icon_url); | 1150 favicon_changed_callback_list_.Notify(page_urls, icon_url); |
| 1149 } | 1151 } |
| 1150 | 1152 |
| 1151 } // namespace history | 1153 } // namespace history |
| OLD | NEW |