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

Side by Side Diff: content/browser/appcache/appcache_service_impl.cc

Issue 2940023002: TaskScheduler: migrate appcache database over to use it. (Closed)
Patch Set: comments + rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/browser/appcache/appcache_service_impl.h" 5 #include "content/browser/appcache/appcache_service_impl.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/task_scheduler/post_task.h"
18 #include "base/threading/sequenced_task_runner_handle.h"
18 #include "content/browser/appcache/appcache.h" 19 #include "content/browser/appcache/appcache.h"
19 #include "content/browser/appcache/appcache_backend_impl.h" 20 #include "content/browser/appcache/appcache_backend_impl.h"
20 #include "content/browser/appcache/appcache_entry.h" 21 #include "content/browser/appcache/appcache_entry.h"
21 #include "content/browser/appcache/appcache_executable_handler.h" 22 #include "content/browser/appcache/appcache_executable_handler.h"
22 #include "content/browser/appcache/appcache_histograms.h" 23 #include "content/browser/appcache/appcache_histograms.h"
23 #include "content/browser/appcache/appcache_policy.h" 24 #include "content/browser/appcache/appcache_policy.h"
24 #include "content/browser/appcache/appcache_quota_client.h" 25 #include "content/browser/appcache/appcache_quota_client.h"
25 #include "content/browser/appcache/appcache_response.h" 26 #include "content/browser/appcache/appcache_response.h"
26 #include "content/browser/appcache/appcache_service_impl.h" 27 #include "content/browser/appcache/appcache_service_impl.h"
27 #include "content/browser/appcache/appcache_storage_impl.h" 28 #include "content/browser/appcache/appcache_storage_impl.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 62 }
62 } 63 }
63 64
64 virtual void Start() = 0; 65 virtual void Start() = 0;
65 virtual void Cancel(); 66 virtual void Cancel();
66 67
67 protected: 68 protected:
68 void CallCallback(int rv) { 69 void CallCallback(int rv) {
69 if (!callback_.is_null()) { 70 if (!callback_.is_null()) {
70 // Defer to guarantee async completion. 71 // Defer to guarantee async completion.
71 base::ThreadTaskRunnerHandle::Get()->PostTask( 72 base::SequencedTaskRunnerHandle::Get()->PostTask(
72 FROM_HERE, base::Bind(&DeferredCallback, callback_, rv)); 73 FROM_HERE, base::Bind(&DeferredCallback, callback_, rv));
73 } 74 }
74 callback_.Reset(); 75 callback_.Reset();
75 } 76 }
76 77
77 AppCacheServiceImpl* service_; 78 AppCacheServiceImpl* service_;
78 net::CompletionCallback callback_; 79 net::CompletionCallback callback_;
79 }; 80 };
80 81
81 void AppCacheServiceImpl::AsyncHelper::Cancel() { 82 void AppCacheServiceImpl::AsyncHelper::Cancel() {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 393
393 AppCacheStorageReference::AppCacheStorageReference( 394 AppCacheStorageReference::AppCacheStorageReference(
394 std::unique_ptr<AppCacheStorage> storage) 395 std::unique_ptr<AppCacheStorage> storage)
395 : storage_(std::move(storage)) {} 396 : storage_(std::move(storage)) {}
396 AppCacheStorageReference::~AppCacheStorageReference() {} 397 AppCacheStorageReference::~AppCacheStorageReference() {}
397 398
398 // AppCacheServiceImpl ------- 399 // AppCacheServiceImpl -------
399 400
400 AppCacheServiceImpl::AppCacheServiceImpl( 401 AppCacheServiceImpl::AppCacheServiceImpl(
401 storage::QuotaManagerProxy* quota_manager_proxy) 402 storage::QuotaManagerProxy* quota_manager_proxy)
402 : appcache_policy_(nullptr), 403 : db_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
404 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
405 base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
406 appcache_policy_(nullptr),
403 quota_client_(nullptr), 407 quota_client_(nullptr),
404 handler_factory_(nullptr), 408 handler_factory_(nullptr),
405 quota_manager_proxy_(quota_manager_proxy), 409 quota_manager_proxy_(quota_manager_proxy),
406 request_context_(nullptr), 410 request_context_(nullptr),
407 force_keep_session_state_(false), 411 force_keep_session_state_(false),
408 weak_factory_(this) { 412 weak_factory_(this) {
409 if (quota_manager_proxy_.get()) { 413 if (quota_manager_proxy_.get()) {
410 quota_client_ = new AppCacheQuotaClient(this); 414 quota_client_ = new AppCacheQuotaClient(this);
411 quota_manager_proxy_->RegisterClient(quota_client_); 415 quota_manager_proxy_->RegisterClient(quota_client_);
412 } 416 }
413 } 417 }
414 418
415 AppCacheServiceImpl::~AppCacheServiceImpl() { 419 AppCacheServiceImpl::~AppCacheServiceImpl() {
416 DCHECK(backends_.empty()); 420 DCHECK(backends_.empty());
417 for (auto& observer : observers_) 421 for (auto& observer : observers_)
418 observer.OnServiceDestructionImminent(this); 422 observer.OnServiceDestructionImminent(this);
419 for (auto& helper : pending_helpers_) 423 for (auto& helper : pending_helpers_)
420 helper.first->Cancel(); 424 helper.first->Cancel();
421 pending_helpers_.clear(); 425 pending_helpers_.clear();
422 if (quota_client_) 426 if (quota_client_)
423 quota_client_->NotifyAppCacheDestroyed(); 427 quota_client_->NotifyAppCacheDestroyed();
424 428
425 // Destroy storage_ first; ~AppCacheStorageImpl accesses other data members 429 // Destroy storage_ first; ~AppCacheStorageImpl accesses other data members
426 // (special_storage_policy_). 430 // (special_storage_policy_).
427 storage_.reset(); 431 storage_.reset();
428 } 432 }
429 433
430 void AppCacheServiceImpl::Initialize( 434 void AppCacheServiceImpl::Initialize(
431 const base::FilePath& cache_directory, 435 const base::FilePath& cache_directory,
432 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
433 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread) { 436 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread) {
434 DCHECK(!storage_.get()); 437 DCHECK(!storage_.get());
435 cache_directory_ = cache_directory; 438 cache_directory_ = cache_directory;
436 db_thread_ = db_thread;
437 cache_thread_ = cache_thread; 439 cache_thread_ = cache_thread;
438 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); 440 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this);
439 storage->Initialize(cache_directory, db_thread, cache_thread); 441 storage->Initialize(cache_directory, db_task_runner_, cache_thread);
440 storage_.reset(storage); 442 storage_.reset(storage);
441 } 443 }
442 444
443 void AppCacheServiceImpl::ScheduleReinitialize() { 445 void AppCacheServiceImpl::ScheduleReinitialize() {
444 if (reinit_timer_.IsRunning()) 446 if (reinit_timer_.IsRunning())
445 return; 447 return;
446 448
447 // Reinitialization only happens when corruption has been noticed. 449 // Reinitialization only happens when corruption has been noticed.
448 // We don't want to thrash the disk but we also don't want to 450 // We don't want to thrash the disk but we also don't want to
449 // leave the appcache disabled for an indefinite period of time. Some 451 // leave the appcache disabled for an indefinite period of time. Some
(...skipping 21 matching lines...) Expand all
471 AppCacheHistograms::CountReinitAttempt(!last_reinit_time_.is_null()); 473 AppCacheHistograms::CountReinitAttempt(!last_reinit_time_.is_null());
472 last_reinit_time_ = base::Time::Now(); 474 last_reinit_time_ = base::Time::Now();
473 475
474 // Inform observers of about this and give them a chance to 476 // Inform observers of about this and give them a chance to
475 // defer deletion of the old storage object. 477 // defer deletion of the old storage object.
476 scoped_refptr<AppCacheStorageReference> old_storage_ref( 478 scoped_refptr<AppCacheStorageReference> old_storage_ref(
477 new AppCacheStorageReference(std::move(storage_))); 479 new AppCacheStorageReference(std::move(storage_)));
478 for (auto& observer : observers_) 480 for (auto& observer : observers_)
479 observer.OnServiceReinitialized(old_storage_ref.get()); 481 observer.OnServiceReinitialized(old_storage_ref.get());
480 482
481 Initialize(cache_directory_, db_thread_, cache_thread_); 483 Initialize(cache_directory_, cache_thread_);
482 } 484 }
483 485
484 void AppCacheServiceImpl::GetAllAppCacheInfo( 486 void AppCacheServiceImpl::GetAllAppCacheInfo(
485 AppCacheInfoCollection* collection, 487 AppCacheInfoCollection* collection,
486 const net::CompletionCallback& callback) { 488 const net::CompletionCallback& callback) {
487 DCHECK(collection); 489 DCHECK(collection);
488 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); 490 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback);
489 helper->Start(); 491 helper->Start();
490 } 492 }
491 493
(...skipping 29 matching lines...) Expand all
521 backends_.insert( 523 backends_.insert(
522 BackendMap::value_type(backend_impl->process_id(), backend_impl)); 524 BackendMap::value_type(backend_impl->process_id(), backend_impl));
523 } 525 }
524 526
525 void AppCacheServiceImpl::UnregisterBackend( 527 void AppCacheServiceImpl::UnregisterBackend(
526 AppCacheBackendImpl* backend_impl) { 528 AppCacheBackendImpl* backend_impl) {
527 backends_.erase(backend_impl->process_id()); 529 backends_.erase(backend_impl->process_id());
528 } 530 }
529 531
530 } // namespace content 532 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_service_impl.h ('k') | content/browser/appcache/appcache_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698