| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 base::MakeCriticalClosure(base::Bind( | 219 base::MakeCriticalClosure(base::Bind( |
| 220 &HistoryBackend::PersistState, history_backend_.get()))); | 220 &HistoryBackend::PersistState, history_backend_.get()))); |
| 221 } | 221 } |
| 222 #endif | 222 #endif |
| 223 | 223 |
| 224 void HistoryService::ClearCachedDataForContextID(ContextID context_id) { | 224 void HistoryService::ClearCachedDataForContextID(ContextID context_id) { |
| 225 DCHECK(thread_) << "History service being called after cleanup"; | 225 DCHECK(thread_) << "History service being called after cleanup"; |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 226 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 ScheduleTask(PRIORITY_NORMAL, | 227 ScheduleTask(PRIORITY_NORMAL, |
| 228 base::Bind(&HistoryBackend::ClearCachedDataForContextID, | 228 base::Bind(&HistoryBackend::ClearCachedDataForContextID, |
| 229 history_backend_.get(), context_id)); | 229 history_backend_, context_id)); |
| 230 } | 230 } |
| 231 | 231 |
| 232 URLDatabase* HistoryService::InMemoryDatabase() { | 232 URLDatabase* HistoryService::InMemoryDatabase() { |
| 233 DCHECK(thread_checker_.CalledOnValidThread()); | 233 DCHECK(thread_checker_.CalledOnValidThread()); |
| 234 return in_memory_backend_ ? in_memory_backend_->db() : nullptr; | 234 return in_memory_backend_ ? in_memory_backend_->db() : nullptr; |
| 235 } | 235 } |
| 236 | 236 |
| 237 TypedUrlSyncableService* HistoryService::GetTypedUrlSyncableService() const { | 237 TypedUrlSyncableService* HistoryService::GetTypedUrlSyncableService() const { |
| 238 return history_backend_->GetTypedUrlSyncableService(); | 238 return history_backend_->GetTypedUrlSyncableService(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void HistoryService::Shutdown() { | 241 void HistoryService::Shutdown() { |
| 242 DCHECK(thread_checker_.CalledOnValidThread()); | 242 DCHECK(thread_checker_.CalledOnValidThread()); |
| 243 Cleanup(); | 243 Cleanup(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, | 246 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, |
| 247 KeywordID keyword_id, | 247 KeywordID keyword_id, |
| 248 const base::string16& term) { | 248 const base::string16& term) { |
| 249 DCHECK(thread_) << "History service being called after cleanup"; | 249 DCHECK(thread_) << "History service being called after cleanup"; |
| 250 DCHECK(thread_checker_.CalledOnValidThread()); | 250 DCHECK(thread_checker_.CalledOnValidThread()); |
| 251 ScheduleTask(PRIORITY_UI, | 251 ScheduleTask(PRIORITY_UI, |
| 252 base::Bind(&HistoryBackend::SetKeywordSearchTermsForURL, | 252 base::Bind(&HistoryBackend::SetKeywordSearchTermsForURL, |
| 253 history_backend_.get(), url, keyword_id, term)); | 253 history_backend_, url, keyword_id, term)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void HistoryService::DeleteAllSearchTermsForKeyword(KeywordID keyword_id) { | 256 void HistoryService::DeleteAllSearchTermsForKeyword(KeywordID keyword_id) { |
| 257 DCHECK(thread_) << "History service being called after cleanup"; | 257 DCHECK(thread_) << "History service being called after cleanup"; |
| 258 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(thread_checker_.CalledOnValidThread()); |
| 259 | 259 |
| 260 if (in_memory_backend_) | 260 if (in_memory_backend_) |
| 261 in_memory_backend_->DeleteAllSearchTermsForKeyword(keyword_id); | 261 in_memory_backend_->DeleteAllSearchTermsForKeyword(keyword_id); |
| 262 | 262 |
| 263 ScheduleTask(PRIORITY_UI, | 263 ScheduleTask(PRIORITY_UI, |
| 264 base::Bind(&HistoryBackend::DeleteAllSearchTermsForKeyword, | 264 base::Bind(&HistoryBackend::DeleteAllSearchTermsForKeyword, |
| 265 history_backend_.get(), keyword_id)); | 265 history_backend_, keyword_id)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void HistoryService::DeleteKeywordSearchTermForURL(const GURL& url) { | 268 void HistoryService::DeleteKeywordSearchTermForURL(const GURL& url) { |
| 269 DCHECK(thread_) << "History service being called after cleanup"; | 269 DCHECK(thread_) << "History service being called after cleanup"; |
| 270 DCHECK(thread_checker_.CalledOnValidThread()); | 270 DCHECK(thread_checker_.CalledOnValidThread()); |
| 271 ScheduleTask(PRIORITY_UI, | 271 ScheduleTask(PRIORITY_UI, |
| 272 base::Bind(&HistoryBackend::DeleteKeywordSearchTermForURL, | 272 base::Bind(&HistoryBackend::DeleteKeywordSearchTermForURL, |
| 273 history_backend_.get(), url)); | 273 history_backend_, url)); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void HistoryService::DeleteMatchingURLsForKeyword(KeywordID keyword_id, | 276 void HistoryService::DeleteMatchingURLsForKeyword(KeywordID keyword_id, |
| 277 const base::string16& term) { | 277 const base::string16& term) { |
| 278 DCHECK(thread_) << "History service being called after cleanup"; | 278 DCHECK(thread_) << "History service being called after cleanup"; |
| 279 DCHECK(thread_checker_.CalledOnValidThread()); | 279 DCHECK(thread_checker_.CalledOnValidThread()); |
| 280 ScheduleTask(PRIORITY_UI, | 280 ScheduleTask(PRIORITY_UI, |
| 281 base::Bind(&HistoryBackend::DeleteMatchingURLsForKeyword, | 281 base::Bind(&HistoryBackend::DeleteMatchingURLsForKeyword, |
| 282 history_backend_.get(), keyword_id, term)); | 282 history_backend_, keyword_id, term)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { | 285 void HistoryService::URLsNoLongerBookmarked(const std::set<GURL>& urls) { |
| 286 DCHECK(thread_) << "History service being called after cleanup"; | 286 DCHECK(thread_) << "History service being called after cleanup"; |
| 287 DCHECK(thread_checker_.CalledOnValidThread()); | 287 DCHECK(thread_checker_.CalledOnValidThread()); |
| 288 ScheduleTask(PRIORITY_NORMAL, | 288 ScheduleTask(PRIORITY_NORMAL, |
| 289 base::Bind(&HistoryBackend::URLsNoLongerBookmarked, | 289 base::Bind(&HistoryBackend::URLsNoLongerBookmarked, |
| 290 history_backend_.get(), urls)); | 290 history_backend_, urls)); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void HistoryService::AddObserver(HistoryServiceObserver* observer) { | 293 void HistoryService::AddObserver(HistoryServiceObserver* observer) { |
| 294 DCHECK(thread_checker_.CalledOnValidThread()); | 294 DCHECK(thread_checker_.CalledOnValidThread()); |
| 295 observers_.AddObserver(observer); | 295 observers_.AddObserver(observer); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void HistoryService::RemoveObserver(HistoryServiceObserver* observer) { | 298 void HistoryService::RemoveObserver(HistoryServiceObserver* observer) { |
| 299 DCHECK(thread_checker_.CalledOnValidThread()); | 299 DCHECK(thread_checker_.CalledOnValidThread()); |
| 300 observers_.RemoveObserver(observer); | 300 observers_.RemoveObserver(observer); |
| 301 } | 301 } |
| 302 | 302 |
| 303 base::CancelableTaskTracker::TaskId HistoryService::ScheduleDBTask( | 303 base::CancelableTaskTracker::TaskId HistoryService::ScheduleDBTask( |
| 304 std::unique_ptr<HistoryDBTask> task, | 304 std::unique_ptr<HistoryDBTask> task, |
| 305 base::CancelableTaskTracker* tracker) { | 305 base::CancelableTaskTracker* tracker) { |
| 306 DCHECK(thread_) << "History service being called after cleanup"; | 306 DCHECK(thread_) << "History service being called after cleanup"; |
| 307 DCHECK(thread_checker_.CalledOnValidThread()); | 307 DCHECK(thread_checker_.CalledOnValidThread()); |
| 308 base::CancelableTaskTracker::IsCanceledCallback is_canceled; | 308 base::CancelableTaskTracker::IsCanceledCallback is_canceled; |
| 309 base::CancelableTaskTracker::TaskId task_id = | 309 base::CancelableTaskTracker::TaskId task_id = |
| 310 tracker->NewTrackedTaskId(&is_canceled); | 310 tracker->NewTrackedTaskId(&is_canceled); |
| 311 // Use base::ThreadTaskRunnerHandler::Get() to get a task runner for | 311 // Use base::ThreadTaskRunnerHandler::Get() to get a task runner for |
| 312 // the current message loop so that we can forward the call to the method | 312 // the current message loop so that we can forward the call to the method |
| 313 // HistoryDBTask::DoneRunOnMainThread() in the correct thread. | 313 // HistoryDBTask::DoneRunOnMainThread() in the correct thread. |
| 314 thread_->task_runner()->PostTask( | 314 thread_->task_runner()->PostTask( |
| 315 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTask, | 315 FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTask, |
| 316 history_backend_.get(), base::Passed(&task), | 316 history_backend_, base::Passed(&task), |
| 317 base::ThreadTaskRunnerHandle::Get(), is_canceled)); | 317 base::ThreadTaskRunnerHandle::Get(), is_canceled)); |
| 318 return task_id; | 318 return task_id; |
| 319 } | 319 } |
| 320 | 320 |
| 321 void HistoryService::FlushForTest(const base::Closure& flushed) { | 321 void HistoryService::FlushForTest(const base::Closure& flushed) { |
| 322 thread_->task_runner()->PostTaskAndReply( | 322 thread_->task_runner()->PostTaskAndReply( |
| 323 FROM_HERE, base::Bind(&base::DoNothing), flushed); | 323 FROM_HERE, base::Bind(&base::DoNothing), flushed); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void HistoryService::SetOnBackendDestroyTask(const base::Closure& task) { | 326 void HistoryService::SetOnBackendDestroyTask(const base::Closure& task) { |
| 327 DCHECK(thread_) << "History service being called after cleanup"; | 327 DCHECK(thread_) << "History service being called after cleanup"; |
| 328 DCHECK(thread_checker_.CalledOnValidThread()); | 328 DCHECK(thread_checker_.CalledOnValidThread()); |
| 329 ScheduleTask( | 329 ScheduleTask( |
| 330 PRIORITY_NORMAL, | 330 PRIORITY_NORMAL, |
| 331 base::Bind(&HistoryBackend::SetOnBackendDestroyTask, | 331 base::Bind(&HistoryBackend::SetOnBackendDestroyTask, |
| 332 history_backend_.get(), base::MessageLoop::current(), task)); | 332 history_backend_, base::MessageLoop::current(), task)); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void HistoryService::TopHosts(size_t num_hosts, | 335 void HistoryService::TopHosts(size_t num_hosts, |
| 336 const TopHostsCallback& callback) const { | 336 const TopHostsCallback& callback) const { |
| 337 DCHECK(thread_) << "History service being called after cleanup"; | 337 DCHECK(thread_) << "History service being called after cleanup"; |
| 338 DCHECK(thread_checker_.CalledOnValidThread()); | 338 DCHECK(thread_checker_.CalledOnValidThread()); |
| 339 PostTaskAndReplyWithResult( | 339 PostTaskAndReplyWithResult( |
| 340 thread_->task_runner().get(), FROM_HERE, | 340 thread_->task_runner().get(), FROM_HERE, |
| 341 base::Bind(&HistoryBackend::TopHosts, history_backend_.get(), num_hosts), | 341 base::Bind(&HistoryBackend::TopHosts, history_backend_, num_hosts), |
| 342 callback); | 342 callback); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void HistoryService::GetCountsAndLastVisitForOrigins( | 345 void HistoryService::GetCountsAndLastVisitForOrigins( |
| 346 const std::set<GURL>& origins, | 346 const std::set<GURL>& origins, |
| 347 const GetCountsAndLastVisitForOriginsCallback& callback) const { | 347 const GetCountsAndLastVisitForOriginsCallback& callback) const { |
| 348 DCHECK(thread_) << "History service being called after cleanup"; | 348 DCHECK(thread_) << "History service being called after cleanup"; |
| 349 DCHECK(thread_checker_.CalledOnValidThread()); | 349 DCHECK(thread_checker_.CalledOnValidThread()); |
| 350 PostTaskAndReplyWithResult( | 350 PostTaskAndReplyWithResult( |
| 351 thread_->task_runner().get(), FROM_HERE, | 351 thread_->task_runner().get(), FROM_HERE, |
| 352 base::Bind(&HistoryBackend::GetCountsAndLastVisitForOrigins, | 352 base::Bind(&HistoryBackend::GetCountsAndLastVisitForOrigins, |
| 353 history_backend_.get(), origins), | 353 history_backend_, origins), |
| 354 callback); | 354 callback); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void HistoryService::HostRankIfAvailable( | 357 void HistoryService::HostRankIfAvailable( |
| 358 const GURL& url, | 358 const GURL& url, |
| 359 const base::Callback<void(int)>& callback) const { | 359 const base::Callback<void(int)>& callback) const { |
| 360 DCHECK(thread_) << "History service being called after cleanup"; | 360 DCHECK(thread_) << "History service being called after cleanup"; |
| 361 DCHECK(thread_checker_.CalledOnValidThread()); | 361 DCHECK(thread_checker_.CalledOnValidThread()); |
| 362 PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE, | 362 PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE, |
| 363 base::Bind(&HistoryBackend::HostRankIfAvailable, | 363 base::Bind(&HistoryBackend::HostRankIfAvailable, |
| 364 history_backend_.get(), url), | 364 history_backend_, url), |
| 365 callback); | 365 callback); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void HistoryService::AddPage(const GURL& url, | 368 void HistoryService::AddPage(const GURL& url, |
| 369 Time time, | 369 Time time, |
| 370 ContextID context_id, | 370 ContextID context_id, |
| 371 int nav_entry_id, | 371 int nav_entry_id, |
| 372 const GURL& referrer, | 372 const GURL& referrer, |
| 373 const RedirectList& redirects, | 373 const RedirectList& redirects, |
| 374 ui::PageTransition transition, | 374 ui::PageTransition transition, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 // add_page_args.redirects which mean we can use VisitDelegate::AddURLs() | 407 // add_page_args.redirects which mean we can use VisitDelegate::AddURLs() |
| 408 // with the whole array. | 408 // with the whole array. |
| 409 DCHECK_EQ(add_page_args.url, add_page_args.redirects.back()); | 409 DCHECK_EQ(add_page_args.url, add_page_args.redirects.back()); |
| 410 visit_delegate_->AddURLs(add_page_args.redirects); | 410 visit_delegate_->AddURLs(add_page_args.redirects); |
| 411 } else { | 411 } else { |
| 412 visit_delegate_->AddURL(add_page_args.url); | 412 visit_delegate_->AddURL(add_page_args.url); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 ScheduleTask(PRIORITY_NORMAL, | 416 ScheduleTask(PRIORITY_NORMAL, |
| 417 base::Bind(&HistoryBackend::AddPage, history_backend_.get(), | 417 base::Bind(&HistoryBackend::AddPage, history_backend_, |
| 418 add_page_args)); | 418 add_page_args)); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, | 421 void HistoryService::AddPageNoVisitForBookmark(const GURL& url, |
| 422 const base::string16& title) { | 422 const base::string16& title) { |
| 423 DCHECK(thread_) << "History service being called after cleanup"; | 423 DCHECK(thread_) << "History service being called after cleanup"; |
| 424 DCHECK(thread_checker_.CalledOnValidThread()); | 424 DCHECK(thread_checker_.CalledOnValidThread()); |
| 425 if (history_client_ && !history_client_->CanAddURL(url)) | 425 if (history_client_ && !history_client_->CanAddURL(url)) |
| 426 return; | 426 return; |
| 427 | 427 |
| 428 ScheduleTask(PRIORITY_NORMAL, | 428 ScheduleTask(PRIORITY_NORMAL, |
| 429 base::Bind(&HistoryBackend::AddPageNoVisitForBookmark, | 429 base::Bind(&HistoryBackend::AddPageNoVisitForBookmark, |
| 430 history_backend_.get(), url, title)); | 430 history_backend_, url, title)); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void HistoryService::SetPageTitle(const GURL& url, | 433 void HistoryService::SetPageTitle(const GURL& url, |
| 434 const base::string16& title) { | 434 const base::string16& title) { |
| 435 DCHECK(thread_) << "History service being called after cleanup"; | 435 DCHECK(thread_) << "History service being called after cleanup"; |
| 436 DCHECK(thread_checker_.CalledOnValidThread()); | 436 DCHECK(thread_checker_.CalledOnValidThread()); |
| 437 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::SetPageTitle, | 437 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::SetPageTitle, |
| 438 history_backend_.get(), url, title)); | 438 history_backend_, url, title)); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void HistoryService::UpdateWithPageEndTime(ContextID context_id, | 441 void HistoryService::UpdateWithPageEndTime(ContextID context_id, |
| 442 int nav_entry_id, | 442 int nav_entry_id, |
| 443 const GURL& url, | 443 const GURL& url, |
| 444 Time end_ts) { | 444 Time end_ts) { |
| 445 DCHECK(thread_) << "History service being called after cleanup"; | 445 DCHECK(thread_) << "History service being called after cleanup"; |
| 446 DCHECK(thread_checker_.CalledOnValidThread()); | 446 DCHECK(thread_checker_.CalledOnValidThread()); |
| 447 ScheduleTask( | 447 ScheduleTask( |
| 448 PRIORITY_NORMAL, | 448 PRIORITY_NORMAL, |
| 449 base::Bind(&HistoryBackend::UpdateWithPageEndTime, history_backend_.get(), | 449 base::Bind(&HistoryBackend::UpdateWithPageEndTime, history_backend_, |
| 450 context_id, nav_entry_id, url, end_ts)); | 450 context_id, nav_entry_id, url, end_ts)); |
| 451 } | 451 } |
| 452 | 452 |
| 453 void HistoryService::AddPageWithDetails(const GURL& url, | 453 void HistoryService::AddPageWithDetails(const GURL& url, |
| 454 const base::string16& title, | 454 const base::string16& title, |
| 455 int visit_count, | 455 int visit_count, |
| 456 int typed_count, | 456 int typed_count, |
| 457 Time last_visit, | 457 Time last_visit, |
| 458 bool hidden, | 458 bool hidden, |
| 459 VisitSource visit_source) { | 459 VisitSource visit_source) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 472 row.set_visit_count(visit_count); | 472 row.set_visit_count(visit_count); |
| 473 row.set_typed_count(typed_count); | 473 row.set_typed_count(typed_count); |
| 474 row.set_last_visit(last_visit); | 474 row.set_last_visit(last_visit); |
| 475 row.set_hidden(hidden); | 475 row.set_hidden(hidden); |
| 476 | 476 |
| 477 URLRows rows; | 477 URLRows rows; |
| 478 rows.push_back(row); | 478 rows.push_back(row); |
| 479 | 479 |
| 480 ScheduleTask(PRIORITY_NORMAL, | 480 ScheduleTask(PRIORITY_NORMAL, |
| 481 base::Bind(&HistoryBackend::AddPagesWithDetails, | 481 base::Bind(&HistoryBackend::AddPagesWithDetails, |
| 482 history_backend_.get(), rows, visit_source)); | 482 history_backend_, rows, visit_source)); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void HistoryService::AddPagesWithDetails(const URLRows& info, | 485 void HistoryService::AddPagesWithDetails(const URLRows& info, |
| 486 VisitSource visit_source) { | 486 VisitSource visit_source) { |
| 487 DCHECK(thread_) << "History service being called after cleanup"; | 487 DCHECK(thread_) << "History service being called after cleanup"; |
| 488 DCHECK(thread_checker_.CalledOnValidThread()); | 488 DCHECK(thread_checker_.CalledOnValidThread()); |
| 489 | 489 |
| 490 // Inform the VisitDelegate of the URLs | 490 // Inform the VisitDelegate of the URLs |
| 491 if (!info.empty() && visit_delegate_) { | 491 if (!info.empty() && visit_delegate_) { |
| 492 std::vector<GURL> urls; | 492 std::vector<GURL> urls; |
| 493 urls.reserve(info.size()); | 493 urls.reserve(info.size()); |
| 494 for (const auto& row : info) | 494 for (const auto& row : info) |
| 495 urls.push_back(row.url()); | 495 urls.push_back(row.url()); |
| 496 visit_delegate_->AddURLs(urls); | 496 visit_delegate_->AddURLs(urls); |
| 497 } | 497 } |
| 498 | 498 |
| 499 ScheduleTask(PRIORITY_NORMAL, | 499 ScheduleTask(PRIORITY_NORMAL, |
| 500 base::Bind(&HistoryBackend::AddPagesWithDetails, | 500 base::Bind(&HistoryBackend::AddPagesWithDetails, |
| 501 history_backend_.get(), info, visit_source)); | 501 history_backend_, info, visit_source)); |
| 502 } | 502 } |
| 503 | 503 |
| 504 base::CancelableTaskTracker::TaskId HistoryService::GetFavicons( | 504 base::CancelableTaskTracker::TaskId HistoryService::GetFavicons( |
| 505 const std::vector<GURL>& icon_urls, | 505 const std::vector<GURL>& icon_urls, |
| 506 int icon_types, | 506 int icon_types, |
| 507 const std::vector<int>& desired_sizes, | 507 const std::vector<int>& desired_sizes, |
| 508 const favicon_base::FaviconResultsCallback& callback, | 508 const favicon_base::FaviconResultsCallback& callback, |
| 509 base::CancelableTaskTracker* tracker) { | 509 base::CancelableTaskTracker* tracker) { |
| 510 DCHECK(thread_) << "History service being called after cleanup"; | 510 DCHECK(thread_) << "History service being called after cleanup"; |
| 511 DCHECK(thread_checker_.CalledOnValidThread()); | 511 DCHECK(thread_checker_.CalledOnValidThread()); |
| 512 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 512 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 513 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 513 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 514 return tracker->PostTaskAndReply( | 514 return tracker->PostTaskAndReply( |
| 515 thread_->task_runner().get(), FROM_HERE, | 515 thread_->task_runner().get(), FROM_HERE, |
| 516 base::Bind(&HistoryBackend::GetFavicons, history_backend_.get(), | 516 base::Bind(&HistoryBackend::GetFavicons, history_backend_, |
| 517 icon_urls, icon_types, desired_sizes, results), | 517 icon_urls, icon_types, desired_sizes, results), |
| 518 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 518 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 519 } | 519 } |
| 520 | 520 |
| 521 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconsForURL( | 521 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconsForURL( |
| 522 const GURL& page_url, | 522 const GURL& page_url, |
| 523 int icon_types, | 523 int icon_types, |
| 524 const std::vector<int>& desired_sizes, | 524 const std::vector<int>& desired_sizes, |
| 525 const favicon_base::FaviconResultsCallback& callback, | 525 const favicon_base::FaviconResultsCallback& callback, |
| 526 base::CancelableTaskTracker* tracker) { | 526 base::CancelableTaskTracker* tracker) { |
| 527 DCHECK(thread_) << "History service being called after cleanup"; | 527 DCHECK(thread_) << "History service being called after cleanup"; |
| 528 DCHECK(thread_checker_.CalledOnValidThread()); | 528 DCHECK(thread_checker_.CalledOnValidThread()); |
| 529 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 529 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 530 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 530 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 531 return tracker->PostTaskAndReply( | 531 return tracker->PostTaskAndReply( |
| 532 thread_->task_runner().get(), FROM_HERE, | 532 thread_->task_runner().get(), FROM_HERE, |
| 533 base::Bind(&HistoryBackend::GetFaviconsForURL, history_backend_.get(), | 533 base::Bind(&HistoryBackend::GetFaviconsForURL, history_backend_, |
| 534 page_url, icon_types, desired_sizes, results), | 534 page_url, icon_types, desired_sizes, results), |
| 535 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 535 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 536 } | 536 } |
| 537 | 537 |
| 538 base::CancelableTaskTracker::TaskId HistoryService::GetLargestFaviconForURL( | 538 base::CancelableTaskTracker::TaskId HistoryService::GetLargestFaviconForURL( |
| 539 const GURL& page_url, | 539 const GURL& page_url, |
| 540 const std::vector<int>& icon_types, | 540 const std::vector<int>& icon_types, |
| 541 int minimum_size_in_pixels, | 541 int minimum_size_in_pixels, |
| 542 const favicon_base::FaviconRawBitmapCallback& callback, | 542 const favicon_base::FaviconRawBitmapCallback& callback, |
| 543 base::CancelableTaskTracker* tracker) { | 543 base::CancelableTaskTracker* tracker) { |
| 544 DCHECK(thread_) << "History service being called after cleanup"; | 544 DCHECK(thread_) << "History service being called after cleanup"; |
| 545 DCHECK(thread_checker_.CalledOnValidThread()); | 545 DCHECK(thread_checker_.CalledOnValidThread()); |
| 546 favicon_base::FaviconRawBitmapResult* result = | 546 favicon_base::FaviconRawBitmapResult* result = |
| 547 new favicon_base::FaviconRawBitmapResult(); | 547 new favicon_base::FaviconRawBitmapResult(); |
| 548 return tracker->PostTaskAndReply( | 548 return tracker->PostTaskAndReply( |
| 549 thread_->task_runner().get(), FROM_HERE, | 549 thread_->task_runner().get(), FROM_HERE, |
| 550 base::Bind(&HistoryBackend::GetLargestFaviconForURL, | 550 base::Bind(&HistoryBackend::GetLargestFaviconForURL, |
| 551 history_backend_.get(), page_url, icon_types, | 551 history_backend_, page_url, icon_types, |
| 552 minimum_size_in_pixels, result), | 552 minimum_size_in_pixels, result), |
| 553 base::Bind(&RunWithFaviconResult, callback, base::Owned(result))); | 553 base::Bind(&RunWithFaviconResult, callback, base::Owned(result))); |
| 554 } | 554 } |
| 555 | 555 |
| 556 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconForID( | 556 base::CancelableTaskTracker::TaskId HistoryService::GetFaviconForID( |
| 557 favicon_base::FaviconID favicon_id, | 557 favicon_base::FaviconID favicon_id, |
| 558 int desired_size, | 558 int desired_size, |
| 559 const favicon_base::FaviconResultsCallback& callback, | 559 const favicon_base::FaviconResultsCallback& callback, |
| 560 base::CancelableTaskTracker* tracker) { | 560 base::CancelableTaskTracker* tracker) { |
| 561 DCHECK(thread_) << "History service being called after cleanup"; | 561 DCHECK(thread_) << "History service being called after cleanup"; |
| 562 DCHECK(thread_checker_.CalledOnValidThread()); | 562 DCHECK(thread_checker_.CalledOnValidThread()); |
| 563 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 563 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 564 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 564 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 565 return tracker->PostTaskAndReply( | 565 return tracker->PostTaskAndReply( |
| 566 thread_->task_runner().get(), FROM_HERE, | 566 thread_->task_runner().get(), FROM_HERE, |
| 567 base::Bind(&HistoryBackend::GetFaviconForID, history_backend_.get(), | 567 base::Bind(&HistoryBackend::GetFaviconForID, history_backend_, |
| 568 favicon_id, desired_size, results), | 568 favicon_id, desired_size, results), |
| 569 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 569 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 570 } | 570 } |
| 571 | 571 |
| 572 base::CancelableTaskTracker::TaskId | 572 base::CancelableTaskTracker::TaskId |
| 573 HistoryService::UpdateFaviconMappingsAndFetch( | 573 HistoryService::UpdateFaviconMappingsAndFetch( |
| 574 const GURL& page_url, | 574 const GURL& page_url, |
| 575 const std::vector<GURL>& icon_urls, | 575 const std::vector<GURL>& icon_urls, |
| 576 int icon_types, | 576 int icon_types, |
| 577 const std::vector<int>& desired_sizes, | 577 const std::vector<int>& desired_sizes, |
| 578 const favicon_base::FaviconResultsCallback& callback, | 578 const favicon_base::FaviconResultsCallback& callback, |
| 579 base::CancelableTaskTracker* tracker) { | 579 base::CancelableTaskTracker* tracker) { |
| 580 DCHECK(thread_) << "History service being called after cleanup"; | 580 DCHECK(thread_) << "History service being called after cleanup"; |
| 581 DCHECK(thread_checker_.CalledOnValidThread()); | 581 DCHECK(thread_checker_.CalledOnValidThread()); |
| 582 std::vector<favicon_base::FaviconRawBitmapResult>* results = | 582 std::vector<favicon_base::FaviconRawBitmapResult>* results = |
| 583 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 583 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
| 584 return tracker->PostTaskAndReply( | 584 return tracker->PostTaskAndReply( |
| 585 thread_->task_runner().get(), FROM_HERE, | 585 thread_->task_runner().get(), FROM_HERE, |
| 586 base::Bind(&HistoryBackend::UpdateFaviconMappingsAndFetch, | 586 base::Bind(&HistoryBackend::UpdateFaviconMappingsAndFetch, |
| 587 history_backend_.get(), page_url, icon_urls, icon_types, | 587 history_backend_, page_url, icon_urls, icon_types, |
| 588 desired_sizes, results), | 588 desired_sizes, results), |
| 589 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); | 589 base::Bind(&RunWithFaviconResults, callback, base::Owned(results))); |
| 590 } | 590 } |
| 591 | 591 |
| 592 void HistoryService::MergeFavicon( | 592 void HistoryService::MergeFavicon( |
| 593 const GURL& page_url, | 593 const GURL& page_url, |
| 594 const GURL& icon_url, | 594 const GURL& icon_url, |
| 595 favicon_base::IconType icon_type, | 595 favicon_base::IconType icon_type, |
| 596 scoped_refptr<base::RefCountedMemory> bitmap_data, | 596 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 597 const gfx::Size& pixel_size) { | 597 const gfx::Size& pixel_size) { |
| 598 DCHECK(thread_) << "History service being called after cleanup"; | 598 DCHECK(thread_) << "History service being called after cleanup"; |
| 599 DCHECK(thread_checker_.CalledOnValidThread()); | 599 DCHECK(thread_checker_.CalledOnValidThread()); |
| 600 if (history_client_ && !history_client_->CanAddURL(page_url)) | 600 if (history_client_ && !history_client_->CanAddURL(page_url)) |
| 601 return; | 601 return; |
| 602 | 602 |
| 603 ScheduleTask( | 603 ScheduleTask( |
| 604 PRIORITY_NORMAL, | 604 PRIORITY_NORMAL, |
| 605 base::Bind(&HistoryBackend::MergeFavicon, history_backend_.get(), | 605 base::Bind(&HistoryBackend::MergeFavicon, history_backend_, |
| 606 page_url, icon_url, icon_type, bitmap_data, pixel_size)); | 606 page_url, icon_url, icon_type, bitmap_data, pixel_size)); |
| 607 } | 607 } |
| 608 | 608 |
| 609 void HistoryService::SetFavicons(const GURL& page_url, | 609 void HistoryService::SetFavicons(const GURL& page_url, |
| 610 favicon_base::IconType icon_type, | 610 favicon_base::IconType icon_type, |
| 611 const GURL& icon_url, | 611 const GURL& icon_url, |
| 612 const std::vector<SkBitmap>& bitmaps) { | 612 const std::vector<SkBitmap>& bitmaps) { |
| 613 DCHECK(thread_) << "History service being called after cleanup"; | 613 DCHECK(thread_) << "History service being called after cleanup"; |
| 614 DCHECK(thread_checker_.CalledOnValidThread()); | 614 DCHECK(thread_checker_.CalledOnValidThread()); |
| 615 if (history_client_ && !history_client_->CanAddURL(page_url)) | 615 if (history_client_ && !history_client_->CanAddURL(page_url)) |
| 616 return; | 616 return; |
| 617 | 617 |
| 618 ScheduleTask(PRIORITY_NORMAL, | 618 ScheduleTask(PRIORITY_NORMAL, |
| 619 base::Bind(&HistoryBackend::SetFavicons, history_backend_.get(), | 619 base::Bind(&HistoryBackend::SetFavicons, history_backend_, |
| 620 page_url, icon_type, icon_url, bitmaps)); | 620 page_url, icon_type, icon_url, bitmaps)); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 623 void HistoryService::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
| 624 DCHECK(thread_) << "History service being called after cleanup"; | 624 DCHECK(thread_) << "History service being called after cleanup"; |
| 625 DCHECK(thread_checker_.CalledOnValidThread()); | 625 DCHECK(thread_checker_.CalledOnValidThread()); |
| 626 ScheduleTask(PRIORITY_NORMAL, | 626 ScheduleTask(PRIORITY_NORMAL, |
| 627 base::Bind(&HistoryBackend::SetFaviconsOutOfDateForPage, | 627 base::Bind(&HistoryBackend::SetFaviconsOutOfDateForPage, |
| 628 history_backend_.get(), page_url)); | 628 history_backend_, page_url)); |
| 629 } | 629 } |
| 630 | 630 |
| 631 void HistoryService::SetImportedFavicons( | 631 void HistoryService::SetImportedFavicons( |
| 632 const favicon_base::FaviconUsageDataList& favicon_usage) { | 632 const favicon_base::FaviconUsageDataList& favicon_usage) { |
| 633 DCHECK(thread_) << "History service being called after cleanup"; | 633 DCHECK(thread_) << "History service being called after cleanup"; |
| 634 DCHECK(thread_checker_.CalledOnValidThread()); | 634 DCHECK(thread_checker_.CalledOnValidThread()); |
| 635 ScheduleTask(PRIORITY_NORMAL, | 635 ScheduleTask(PRIORITY_NORMAL, |
| 636 base::Bind(&HistoryBackend::SetImportedFavicons, | 636 base::Bind(&HistoryBackend::SetImportedFavicons, |
| 637 history_backend_.get(), favicon_usage)); | 637 history_backend_, favicon_usage)); |
| 638 } | 638 } |
| 639 | 639 |
| 640 base::CancelableTaskTracker::TaskId HistoryService::QueryURL( | 640 base::CancelableTaskTracker::TaskId HistoryService::QueryURL( |
| 641 const GURL& url, | 641 const GURL& url, |
| 642 bool want_visits, | 642 bool want_visits, |
| 643 const QueryURLCallback& callback, | 643 const QueryURLCallback& callback, |
| 644 base::CancelableTaskTracker* tracker) { | 644 base::CancelableTaskTracker* tracker) { |
| 645 DCHECK(thread_) << "History service being called after cleanup"; | 645 DCHECK(thread_) << "History service being called after cleanup"; |
| 646 DCHECK(thread_checker_.CalledOnValidThread()); | 646 DCHECK(thread_checker_.CalledOnValidThread()); |
| 647 QueryURLResult* query_url_result = new QueryURLResult(); | 647 QueryURLResult* query_url_result = new QueryURLResult(); |
| 648 return tracker->PostTaskAndReply( | 648 return tracker->PostTaskAndReply( |
| 649 thread_->task_runner().get(), FROM_HERE, | 649 thread_->task_runner().get(), FROM_HERE, |
| 650 base::Bind(&HistoryBackend::QueryURL, history_backend_.get(), url, | 650 base::Bind(&HistoryBackend::QueryURL, history_backend_, url, |
| 651 want_visits, base::Unretained(query_url_result)), | 651 want_visits, base::Unretained(query_url_result)), |
| 652 base::Bind(&RunWithQueryURLResult, callback, | 652 base::Bind(&RunWithQueryURLResult, callback, |
| 653 base::Owned(query_url_result))); | 653 base::Owned(query_url_result))); |
| 654 } | 654 } |
| 655 | 655 |
| 656 // Statistics ------------------------------------------------------------------ | 656 // Statistics ------------------------------------------------------------------ |
| 657 | 657 |
| 658 base::CancelableTaskTracker::TaskId HistoryService::GetHistoryCount( | 658 base::CancelableTaskTracker::TaskId HistoryService::GetHistoryCount( |
| 659 const Time& begin_time, | 659 const Time& begin_time, |
| 660 const Time& end_time, | 660 const Time& end_time, |
| 661 const GetHistoryCountCallback& callback, | 661 const GetHistoryCountCallback& callback, |
| 662 base::CancelableTaskTracker* tracker) { | 662 base::CancelableTaskTracker* tracker) { |
| 663 DCHECK(thread_) << "History service being called after cleanup"; | 663 DCHECK(thread_) << "History service being called after cleanup"; |
| 664 DCHECK(thread_checker_.CalledOnValidThread()); | 664 DCHECK(thread_checker_.CalledOnValidThread()); |
| 665 | 665 |
| 666 return tracker->PostTaskAndReplyWithResult( | 666 return tracker->PostTaskAndReplyWithResult( |
| 667 thread_->task_runner().get(), FROM_HERE, | 667 thread_->task_runner().get(), FROM_HERE, |
| 668 base::Bind(&HistoryBackend::GetHistoryCount, | 668 base::Bind(&HistoryBackend::GetHistoryCount, |
| 669 history_backend_.get(), | 669 history_backend_, |
| 670 begin_time, | 670 begin_time, |
| 671 end_time), | 671 end_time), |
| 672 callback); | 672 callback); |
| 673 } | 673 } |
| 674 | 674 |
| 675 // Downloads ------------------------------------------------------------------- | 675 // Downloads ------------------------------------------------------------------- |
| 676 | 676 |
| 677 // Handle creation of a download by creating an entry in the history service's | 677 // Handle creation of a download by creating an entry in the history service's |
| 678 // 'downloads' table. | 678 // 'downloads' table. |
| 679 void HistoryService::CreateDownload( | 679 void HistoryService::CreateDownload( |
| 680 const DownloadRow& create_info, | 680 const DownloadRow& create_info, |
| 681 const HistoryService::DownloadCreateCallback& callback) { | 681 const HistoryService::DownloadCreateCallback& callback) { |
| 682 DCHECK(thread_) << "History service being called after cleanup"; | 682 DCHECK(thread_) << "History service being called after cleanup"; |
| 683 DCHECK(thread_checker_.CalledOnValidThread()); | 683 DCHECK(thread_checker_.CalledOnValidThread()); |
| 684 PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE, | 684 PostTaskAndReplyWithResult(thread_->task_runner().get(), FROM_HERE, |
| 685 base::Bind(&HistoryBackend::CreateDownload, | 685 base::Bind(&HistoryBackend::CreateDownload, |
| 686 history_backend_.get(), create_info), | 686 history_backend_, create_info), |
| 687 callback); | 687 callback); |
| 688 } | 688 } |
| 689 | 689 |
| 690 void HistoryService::GetNextDownloadId(const DownloadIdCallback& callback) { | 690 void HistoryService::GetNextDownloadId(const DownloadIdCallback& callback) { |
| 691 DCHECK(thread_) << "History service being called after cleanup"; | 691 DCHECK(thread_) << "History service being called after cleanup"; |
| 692 DCHECK(thread_checker_.CalledOnValidThread()); | 692 DCHECK(thread_checker_.CalledOnValidThread()); |
| 693 PostTaskAndReplyWithResult( | 693 PostTaskAndReplyWithResult( |
| 694 thread_->task_runner().get(), FROM_HERE, | 694 thread_->task_runner().get(), FROM_HERE, |
| 695 base::Bind(&HistoryBackend::GetNextDownloadId, history_backend_.get()), | 695 base::Bind(&HistoryBackend::GetNextDownloadId, history_backend_), |
| 696 callback); | 696 callback); |
| 697 } | 697 } |
| 698 | 698 |
| 699 // Handle queries for a list of all downloads in the history database's | 699 // Handle queries for a list of all downloads in the history database's |
| 700 // 'downloads' table. | 700 // 'downloads' table. |
| 701 void HistoryService::QueryDownloads(const DownloadQueryCallback& callback) { | 701 void HistoryService::QueryDownloads(const DownloadQueryCallback& callback) { |
| 702 DCHECK(thread_) << "History service being called after cleanup"; | 702 DCHECK(thread_) << "History service being called after cleanup"; |
| 703 DCHECK(thread_checker_.CalledOnValidThread()); | 703 DCHECK(thread_checker_.CalledOnValidThread()); |
| 704 std::vector<DownloadRow>* rows = new std::vector<DownloadRow>(); | 704 std::vector<DownloadRow>* rows = new std::vector<DownloadRow>(); |
| 705 std::unique_ptr<std::vector<DownloadRow>> scoped_rows(rows); | 705 std::unique_ptr<std::vector<DownloadRow>> scoped_rows(rows); |
| 706 // Beware! The first Bind() does not simply |scoped_rows.get()| because | 706 // Beware! The first Bind() does not simply |scoped_rows.get()| because |
| 707 // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not | 707 // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not |
| 708 // guarantee that the first Bind's arguments are evaluated before the second | 708 // guarantee that the first Bind's arguments are evaluated before the second |
| 709 // Bind's arguments. | 709 // Bind's arguments. |
| 710 thread_->task_runner()->PostTaskAndReply( | 710 thread_->task_runner()->PostTaskAndReply( |
| 711 FROM_HERE, | 711 FROM_HERE, |
| 712 base::Bind(&HistoryBackend::QueryDownloads, history_backend_.get(), rows), | 712 base::Bind(&HistoryBackend::QueryDownloads, history_backend_, rows), |
| 713 base::Bind(callback, base::Passed(&scoped_rows))); | 713 base::Bind(callback, base::Passed(&scoped_rows))); |
| 714 } | 714 } |
| 715 | 715 |
| 716 // Handle updates for a particular download. This is a 'fire and forget' | 716 // Handle updates for a particular download. This is a 'fire and forget' |
| 717 // operation, so we don't need to be called back. | 717 // operation, so we don't need to be called back. |
| 718 void HistoryService::UpdateDownload(const DownloadRow& data) { | 718 void HistoryService::UpdateDownload(const DownloadRow& data) { |
| 719 DCHECK(thread_) << "History service being called after cleanup"; | 719 DCHECK(thread_) << "History service being called after cleanup"; |
| 720 DCHECK(thread_checker_.CalledOnValidThread()); | 720 DCHECK(thread_checker_.CalledOnValidThread()); |
| 721 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::UpdateDownload, | 721 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::UpdateDownload, |
| 722 history_backend_.get(), data)); | 722 history_backend_, data)); |
| 723 } | 723 } |
| 724 | 724 |
| 725 void HistoryService::RemoveDownloads(const std::set<uint32_t>& ids) { | 725 void HistoryService::RemoveDownloads(const std::set<uint32_t>& ids) { |
| 726 DCHECK(thread_) << "History service being called after cleanup"; | 726 DCHECK(thread_) << "History service being called after cleanup"; |
| 727 DCHECK(thread_checker_.CalledOnValidThread()); | 727 DCHECK(thread_checker_.CalledOnValidThread()); |
| 728 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::RemoveDownloads, | 728 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::RemoveDownloads, |
| 729 history_backend_.get(), ids)); | 729 history_backend_, ids)); |
| 730 } | 730 } |
| 731 | 731 |
| 732 base::CancelableTaskTracker::TaskId HistoryService::QueryHistory( | 732 base::CancelableTaskTracker::TaskId HistoryService::QueryHistory( |
| 733 const base::string16& text_query, | 733 const base::string16& text_query, |
| 734 const QueryOptions& options, | 734 const QueryOptions& options, |
| 735 const QueryHistoryCallback& callback, | 735 const QueryHistoryCallback& callback, |
| 736 base::CancelableTaskTracker* tracker) { | 736 base::CancelableTaskTracker* tracker) { |
| 737 DCHECK(thread_) << "History service being called after cleanup"; | 737 DCHECK(thread_) << "History service being called after cleanup"; |
| 738 DCHECK(thread_checker_.CalledOnValidThread()); | 738 DCHECK(thread_checker_.CalledOnValidThread()); |
| 739 QueryResults* query_results = new QueryResults(); | 739 QueryResults* query_results = new QueryResults(); |
| 740 return tracker->PostTaskAndReply( | 740 return tracker->PostTaskAndReply( |
| 741 thread_->task_runner().get(), FROM_HERE, | 741 thread_->task_runner().get(), FROM_HERE, |
| 742 base::Bind(&HistoryBackend::QueryHistory, history_backend_.get(), | 742 base::Bind(&HistoryBackend::QueryHistory, history_backend_, |
| 743 text_query, options, base::Unretained(query_results)), | 743 text_query, options, base::Unretained(query_results)), |
| 744 base::Bind(callback, base::Owned(query_results))); | 744 base::Bind(callback, base::Owned(query_results))); |
| 745 } | 745 } |
| 746 | 746 |
| 747 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsFrom( | 747 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsFrom( |
| 748 const GURL& from_url, | 748 const GURL& from_url, |
| 749 const QueryRedirectsCallback& callback, | 749 const QueryRedirectsCallback& callback, |
| 750 base::CancelableTaskTracker* tracker) { | 750 base::CancelableTaskTracker* tracker) { |
| 751 DCHECK(thread_) << "History service being called after cleanup"; | 751 DCHECK(thread_) << "History service being called after cleanup"; |
| 752 DCHECK(thread_checker_.CalledOnValidThread()); | 752 DCHECK(thread_checker_.CalledOnValidThread()); |
| 753 RedirectList* result = new RedirectList(); | 753 RedirectList* result = new RedirectList(); |
| 754 return tracker->PostTaskAndReply( | 754 return tracker->PostTaskAndReply( |
| 755 thread_->task_runner().get(), FROM_HERE, | 755 thread_->task_runner().get(), FROM_HERE, |
| 756 base::Bind(&HistoryBackend::QueryRedirectsFrom, history_backend_.get(), | 756 base::Bind(&HistoryBackend::QueryRedirectsFrom, history_backend_, |
| 757 from_url, base::Unretained(result)), | 757 from_url, base::Unretained(result)), |
| 758 base::Bind(callback, base::Owned(result))); | 758 base::Bind(callback, base::Owned(result))); |
| 759 } | 759 } |
| 760 | 760 |
| 761 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsTo( | 761 base::CancelableTaskTracker::TaskId HistoryService::QueryRedirectsTo( |
| 762 const GURL& to_url, | 762 const GURL& to_url, |
| 763 const QueryRedirectsCallback& callback, | 763 const QueryRedirectsCallback& callback, |
| 764 base::CancelableTaskTracker* tracker) { | 764 base::CancelableTaskTracker* tracker) { |
| 765 DCHECK(thread_) << "History service being called after cleanup"; | 765 DCHECK(thread_) << "History service being called after cleanup"; |
| 766 DCHECK(thread_checker_.CalledOnValidThread()); | 766 DCHECK(thread_checker_.CalledOnValidThread()); |
| 767 RedirectList* result = new RedirectList(); | 767 RedirectList* result = new RedirectList(); |
| 768 return tracker->PostTaskAndReply( | 768 return tracker->PostTaskAndReply( |
| 769 thread_->task_runner().get(), FROM_HERE, | 769 thread_->task_runner().get(), FROM_HERE, |
| 770 base::Bind(&HistoryBackend::QueryRedirectsTo, history_backend_.get(), | 770 base::Bind(&HistoryBackend::QueryRedirectsTo, history_backend_, |
| 771 to_url, base::Unretained(result)), | 771 to_url, base::Unretained(result)), |
| 772 base::Bind(callback, base::Owned(result))); | 772 base::Bind(callback, base::Owned(result))); |
| 773 } | 773 } |
| 774 | 774 |
| 775 base::CancelableTaskTracker::TaskId HistoryService::GetVisibleVisitCountToHost( | 775 base::CancelableTaskTracker::TaskId HistoryService::GetVisibleVisitCountToHost( |
| 776 const GURL& url, | 776 const GURL& url, |
| 777 const GetVisibleVisitCountToHostCallback& callback, | 777 const GetVisibleVisitCountToHostCallback& callback, |
| 778 base::CancelableTaskTracker* tracker) { | 778 base::CancelableTaskTracker* tracker) { |
| 779 DCHECK(thread_) << "History service being called after cleanup"; | 779 DCHECK(thread_) << "History service being called after cleanup"; |
| 780 DCHECK(thread_checker_.CalledOnValidThread()); | 780 DCHECK(thread_checker_.CalledOnValidThread()); |
| 781 VisibleVisitCountToHostResult* result = new VisibleVisitCountToHostResult(); | 781 VisibleVisitCountToHostResult* result = new VisibleVisitCountToHostResult(); |
| 782 return tracker->PostTaskAndReply( | 782 return tracker->PostTaskAndReply( |
| 783 thread_->task_runner().get(), FROM_HERE, | 783 thread_->task_runner().get(), FROM_HERE, |
| 784 base::Bind(&HistoryBackend::GetVisibleVisitCountToHost, | 784 base::Bind(&HistoryBackend::GetVisibleVisitCountToHost, |
| 785 history_backend_.get(), url, base::Unretained(result)), | 785 history_backend_, url, base::Unretained(result)), |
| 786 base::Bind(&RunWithVisibleVisitCountToHostResult, callback, | 786 base::Bind(&RunWithVisibleVisitCountToHostResult, callback, |
| 787 base::Owned(result))); | 787 base::Owned(result))); |
| 788 } | 788 } |
| 789 | 789 |
| 790 base::CancelableTaskTracker::TaskId HistoryService::QueryMostVisitedURLs( | 790 base::CancelableTaskTracker::TaskId HistoryService::QueryMostVisitedURLs( |
| 791 int result_count, | 791 int result_count, |
| 792 int days_back, | 792 int days_back, |
| 793 const QueryMostVisitedURLsCallback& callback, | 793 const QueryMostVisitedURLsCallback& callback, |
| 794 base::CancelableTaskTracker* tracker) { | 794 base::CancelableTaskTracker* tracker) { |
| 795 DCHECK(thread_) << "History service being called after cleanup"; | 795 DCHECK(thread_) << "History service being called after cleanup"; |
| 796 DCHECK(thread_checker_.CalledOnValidThread()); | 796 DCHECK(thread_checker_.CalledOnValidThread()); |
| 797 MostVisitedURLList* result = new MostVisitedURLList(); | 797 MostVisitedURLList* result = new MostVisitedURLList(); |
| 798 return tracker->PostTaskAndReply( | 798 return tracker->PostTaskAndReply( |
| 799 thread_->task_runner().get(), FROM_HERE, | 799 thread_->task_runner().get(), FROM_HERE, |
| 800 base::Bind(&HistoryBackend::QueryMostVisitedURLs, history_backend_.get(), | 800 base::Bind(&HistoryBackend::QueryMostVisitedURLs, history_backend_, |
| 801 result_count, days_back, base::Unretained(result)), | 801 result_count, days_back, base::Unretained(result)), |
| 802 base::Bind(callback, base::Owned(result))); | 802 base::Bind(callback, base::Owned(result))); |
| 803 } | 803 } |
| 804 | 804 |
| 805 void HistoryService::Cleanup() { | 805 void HistoryService::Cleanup() { |
| 806 DCHECK(thread_checker_.CalledOnValidThread()); | 806 DCHECK(thread_checker_.CalledOnValidThread()); |
| 807 if (!thread_) { | 807 if (!thread_) { |
| 808 // We've already cleaned up. | 808 // We've already cleaned up. |
| 809 return; | 809 return; |
| 810 } | 810 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 837 // | 837 // |
| 838 // Therefore, we create a closure to run the Closing operation first. This | 838 // Therefore, we create a closure to run the Closing operation first. This |
| 839 // holds a reference to the backend. Then we release our reference, then we | 839 // holds a reference to the backend. Then we release our reference, then we |
| 840 // schedule the task to run. After the task runs, it will delete its | 840 // schedule the task to run. After the task runs, it will delete its |
| 841 // reference from the history thread, ensuring everything works properly. | 841 // reference from the history thread, ensuring everything works properly. |
| 842 // | 842 // |
| 843 // TODO(ajwong): Cleanup HistoryBackend lifetime issues. | 843 // TODO(ajwong): Cleanup HistoryBackend lifetime issues. |
| 844 // See http://crbug.com/99767. | 844 // See http://crbug.com/99767. |
| 845 history_backend_->AddRef(); | 845 history_backend_->AddRef(); |
| 846 base::Closure closing_task = | 846 base::Closure closing_task = |
| 847 base::Bind(&HistoryBackend::Closing, history_backend_.get()); | 847 base::Bind(&HistoryBackend::Closing, history_backend_); |
| 848 ScheduleTask(PRIORITY_NORMAL, closing_task); | 848 ScheduleTask(PRIORITY_NORMAL, closing_task); |
| 849 closing_task.Reset(); | 849 closing_task.Reset(); |
| 850 HistoryBackend* raw_ptr = history_backend_.get(); | 850 HistoryBackend* raw_ptr = history_backend_.get(); |
| 851 history_backend_ = nullptr; | 851 history_backend_ = nullptr; |
| 852 thread_->task_runner()->ReleaseSoon(FROM_HERE, raw_ptr); | 852 thread_->task_runner()->ReleaseSoon(FROM_HERE, raw_ptr); |
| 853 } | 853 } |
| 854 | 854 |
| 855 // Delete the thread, which joins with the background thread. We defensively | 855 // Delete the thread, which joins with the background thread. We defensively |
| 856 // nullptr the pointer before deleting it in case somebody tries to use it | 856 // nullptr the pointer before deleting it in case somebody tries to use it |
| 857 // during shutdown, but this shouldn't happen. | 857 // during shutdown, but this shouldn't happen. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 877 | 877 |
| 878 // Create the history backend. | 878 // Create the history backend. |
| 879 scoped_refptr<HistoryBackend> backend(new HistoryBackend( | 879 scoped_refptr<HistoryBackend> backend(new HistoryBackend( |
| 880 new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), | 880 new BackendDelegate(weak_ptr_factory_.GetWeakPtr(), |
| 881 base::ThreadTaskRunnerHandle::Get()), | 881 base::ThreadTaskRunnerHandle::Get()), |
| 882 history_client_ ? history_client_->CreateBackendClient() : nullptr, | 882 history_client_ ? history_client_->CreateBackendClient() : nullptr, |
| 883 thread_->task_runner())); | 883 thread_->task_runner())); |
| 884 history_backend_.swap(backend); | 884 history_backend_.swap(backend); |
| 885 | 885 |
| 886 ScheduleTask(PRIORITY_UI, | 886 ScheduleTask(PRIORITY_UI, |
| 887 base::Bind(&HistoryBackend::Init, history_backend_.get(), | 887 base::Bind(&HistoryBackend::Init, history_backend_, |
| 888 no_db, history_database_params)); | 888 no_db, history_database_params)); |
| 889 | 889 |
| 890 if (visit_delegate_ && !visit_delegate_->Init(this)) | 890 if (visit_delegate_ && !visit_delegate_->Init(this)) |
| 891 return false; | 891 return false; |
| 892 | 892 |
| 893 if (history_client_) | 893 if (history_client_) |
| 894 history_client_->OnHistoryServiceCreated(this); | 894 history_client_->OnHistoryServiceCreated(this); |
| 895 | 895 |
| 896 return true; | 896 return true; |
| 897 } | 897 } |
| 898 | 898 |
| 899 void HistoryService::ScheduleAutocomplete( | 899 void HistoryService::ScheduleAutocomplete( |
| 900 const base::Callback<void(HistoryBackend*, URLDatabase*)>& callback) { | 900 const base::Callback<void(HistoryBackend*, URLDatabase*)>& callback) { |
| 901 DCHECK(thread_checker_.CalledOnValidThread()); | 901 DCHECK(thread_checker_.CalledOnValidThread()); |
| 902 ScheduleTask(PRIORITY_UI, base::Bind(&HistoryBackend::ScheduleAutocomplete, | 902 ScheduleTask(PRIORITY_UI, base::Bind(&HistoryBackend::ScheduleAutocomplete, |
| 903 history_backend_.get(), callback)); | 903 history_backend_, callback)); |
| 904 } | 904 } |
| 905 | 905 |
| 906 void HistoryService::ScheduleTask(SchedulePriority priority, | 906 void HistoryService::ScheduleTask(SchedulePriority priority, |
| 907 const base::Closure& task) { | 907 const base::Closure& task) { |
| 908 DCHECK(thread_checker_.CalledOnValidThread()); | 908 DCHECK(thread_checker_.CalledOnValidThread()); |
| 909 CHECK(thread_); | 909 CHECK(thread_); |
| 910 CHECK(thread_->message_loop()); | 910 CHECK(thread_->message_loop()); |
| 911 // TODO(brettw): Do prioritization. | 911 // TODO(brettw): Do prioritization. |
| 912 thread_->task_runner()->PostTask(FROM_HERE, task); | 912 thread_->task_runner()->PostTask(FROM_HERE, task); |
| 913 } | 913 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 DCHECK(thread_checker_.CalledOnValidThread()); | 972 DCHECK(thread_checker_.CalledOnValidThread()); |
| 973 if (history_client_) | 973 if (history_client_) |
| 974 history_client_->NotifyProfileError(init_status, diagnostics); | 974 history_client_->NotifyProfileError(init_status, diagnostics); |
| 975 } | 975 } |
| 976 | 976 |
| 977 void HistoryService::DeleteURL(const GURL& url) { | 977 void HistoryService::DeleteURL(const GURL& url) { |
| 978 DCHECK(thread_) << "History service being called after cleanup"; | 978 DCHECK(thread_) << "History service being called after cleanup"; |
| 979 DCHECK(thread_checker_.CalledOnValidThread()); | 979 DCHECK(thread_checker_.CalledOnValidThread()); |
| 980 // We will update the visited links when we observe the delete notifications. | 980 // We will update the visited links when we observe the delete notifications. |
| 981 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURL, | 981 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURL, |
| 982 history_backend_.get(), url)); | 982 history_backend_, url)); |
| 983 } | 983 } |
| 984 | 984 |
| 985 void HistoryService::DeleteURLsForTest(const std::vector<GURL>& urls) { | 985 void HistoryService::DeleteURLsForTest(const std::vector<GURL>& urls) { |
| 986 DCHECK(thread_) << "History service being called after cleanup"; | 986 DCHECK(thread_) << "History service being called after cleanup"; |
| 987 DCHECK(thread_checker_.CalledOnValidThread()); | 987 DCHECK(thread_checker_.CalledOnValidThread()); |
| 988 // We will update the visited links when we observe the delete | 988 // We will update the visited links when we observe the delete |
| 989 // notifications. | 989 // notifications. |
| 990 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURLs, | 990 ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::DeleteURLs, |
| 991 history_backend_.get(), urls)); | 991 history_backend_, urls)); |
| 992 } | 992 } |
| 993 | 993 |
| 994 void HistoryService::ExpireHistoryBetween( | 994 void HistoryService::ExpireHistoryBetween( |
| 995 const std::set<GURL>& restrict_urls, | 995 const std::set<GURL>& restrict_urls, |
| 996 Time begin_time, | 996 Time begin_time, |
| 997 Time end_time, | 997 Time end_time, |
| 998 const base::Closure& callback, | 998 const base::Closure& callback, |
| 999 base::CancelableTaskTracker* tracker) { | 999 base::CancelableTaskTracker* tracker) { |
| 1000 DCHECK(thread_) << "History service being called after cleanup"; | 1000 DCHECK(thread_) << "History service being called after cleanup"; |
| 1001 DCHECK(thread_checker_.CalledOnValidThread()); | 1001 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 return favicon_changed_callback_list_.Add(callback); | 1134 return favicon_changed_callback_list_.Add(callback); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 void HistoryService::NotifyFaviconsChanged(const std::set<GURL>& page_urls, | 1137 void HistoryService::NotifyFaviconsChanged(const std::set<GURL>& page_urls, |
| 1138 const GURL& icon_url) { | 1138 const GURL& icon_url) { |
| 1139 DCHECK(thread_checker_.CalledOnValidThread()); | 1139 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1140 favicon_changed_callback_list_.Notify(page_urls, icon_url); | 1140 favicon_changed_callback_list_.Notify(page_urls, icon_url); |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 } // namespace history | 1143 } // namespace history |
| OLD | NEW |