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

Side by Side Diff: components/history/core/browser/history_service.cc

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

Powered by Google App Engine
This is Rietveld 408576698