Commit 393c0cf9 authored by michaeln@chromium.org's avatar michaeln@chromium.org

Initialize ServiceWorkerContextCore with a message loop for the disk cache to use.

BUG=364318

Review URL: https://codereview.chromium.org/279683002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269977 0039d316-1c4b-4281-b951-d872f2087c98
parent 98aaff50
......@@ -23,9 +23,10 @@ EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper(int mock_render_process_id)
: wrapper_(new ServiceWorkerContextWrapper(NULL)),
next_thread_id_(0),
weak_factory_(this) {
wrapper_->InitForTesting(base::FilePath(),
base::MessageLoopProxy::current(),
NULL);
wrapper_->InitInternal(base::FilePath(),
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
NULL);
scoped_ptr<ServiceWorkerProcessManager> process_manager(
new ServiceWorkerProcessManager(wrapper_));
process_manager->SetProcessRefcountOpsForTest(base::Bind(AlwaysTrue),
......
......@@ -5,6 +5,7 @@
#include "content/browser/service_worker/service_worker_context_core.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_util.h"
#include "content/browser/service_worker/embedded_worker_registry.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
......@@ -78,11 +79,14 @@ void ServiceWorkerContextCore::ProviderHostIterator::Initialize() {
ServiceWorkerContextCore::ServiceWorkerContextCore(
const base::FilePath& path,
base::SequencedTaskRunner* database_task_runner,
base::MessageLoopProxy* disk_cache_thread,
quota::QuotaManagerProxy* quota_manager_proxy,
ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list,
scoped_ptr<ServiceWorkerProcessManager> process_manager)
: storage_(new ServiceWorkerStorage(
path, AsWeakPtr(), database_task_runner, quota_manager_proxy)),
: weak_factory_(this),
storage_(new ServiceWorkerStorage(
path, AsWeakPtr(), database_task_runner, disk_cache_thread,
quota_manager_proxy)),
embedded_worker_registry_(new EmbeddedWorkerRegistry(AsWeakPtr())),
job_coordinator_(new ServiceWorkerJobCoordinator(AsWeakPtr())),
process_manager_(process_manager.Pass()),
......@@ -96,10 +100,7 @@ ServiceWorkerContextCore::~ServiceWorkerContextCore() {
++it) {
it->second->RemoveListener(this);
}
providers_.Clear();
storage_.reset();
job_coordinator_.reset();
embedded_worker_registry_ = NULL;
weak_factory_.InvalidateWeakPtrs();
}
ServiceWorkerProviderHost* ServiceWorkerContextCore::GetProviderHost(
......
......@@ -25,6 +25,7 @@ class GURL;
namespace base {
class FilePath;
class MessageLoopProxy;
class SequencedTaskRunner;
}
......@@ -48,8 +49,7 @@ class ServiceWorkerStorage;
// is the root of the containment hierarchy for service worker data
// associated with a particular partition.
class CONTENT_EXPORT ServiceWorkerContextCore
: NON_EXPORTED_BASE(public base::SupportsWeakPtr<ServiceWorkerContextCore>),
public ServiceWorkerVersion::Listener {
: public ServiceWorkerVersion::Listener {
public:
typedef base::Callback<void(ServiceWorkerStatusCode status,
int64 registration_id,
......@@ -88,6 +88,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
ServiceWorkerContextCore(
const base::FilePath& user_data_directory,
base::SequencedTaskRunner* database_task_runner,
base::MessageLoopProxy* disk_cache_thread,
quota::QuotaManagerProxy* quota_manager_proxy,
ObserverListThreadSafe<ServiceWorkerContextObserver>* observer_list,
scoped_ptr<ServiceWorkerProcessManager> process_manager);
......@@ -154,6 +155,10 @@ class CONTENT_EXPORT ServiceWorkerContextCore
// Returns new context-local unique ID for ServiceWorkerHandle.
int GetNewServiceWorkerHandleId();
base::WeakPtr<ServiceWorkerContextCore> AsWeakPtr() {
return weak_factory_.GetWeakPtr();
}
// Allows tests to change how processes are created.
void SetProcessManagerForTest(
scoped_ptr<ServiceWorkerProcessManager> new_process_manager) {
......@@ -174,6 +179,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
ServiceWorkerRegistration* registration,
ServiceWorkerVersion* version);
base::WeakPtrFactory<ServiceWorkerContextCore> weak_factory_;
ProcessToProviderMap providers_;
scoped_ptr<ServiceWorkerStorage> storage_;
scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_;
......@@ -182,7 +188,6 @@ class CONTENT_EXPORT ServiceWorkerContextCore
std::map<int64, ServiceWorkerRegistration*> live_registrations_;
std::map<int64, ServiceWorkerVersion*> live_versions_;
int next_handle_id_;
scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
observer_list_;
......
......@@ -32,7 +32,10 @@ void ServiceWorkerContextWrapper::Init(
GetSequencedTaskRunnerWithShutdownBehavior(
BrowserThread::GetBlockingPool()->GetSequenceToken(),
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
InitInternal(user_data_directory, database_task_runner, quota_manager_proxy);
scoped_refptr<base::MessageLoopProxy> disk_cache_thread =
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE);
InitInternal(user_data_directory, database_task_runner,
disk_cache_thread, quota_manager_proxy);
}
void ServiceWorkerContextWrapper::Shutdown() {
......@@ -128,16 +131,10 @@ void ServiceWorkerContextWrapper::RemoveObserver(
observer_list_->RemoveObserver(observer);
}
void ServiceWorkerContextWrapper::InitForTesting(
const base::FilePath& user_data_directory,
base::SequencedTaskRunner* database_task_runner,
quota::QuotaManagerProxy* quota_manager_proxy) {
InitInternal(user_data_directory, database_task_runner, quota_manager_proxy);
}
void ServiceWorkerContextWrapper::InitInternal(
const base::FilePath& user_data_directory,
base::SequencedTaskRunner* database_task_runner,
base::MessageLoopProxy* disk_cache_thread,
quota::QuotaManagerProxy* quota_manager_proxy) {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
BrowserThread::PostTask(
......@@ -147,6 +144,7 @@ void ServiceWorkerContextWrapper::InitInternal(
this,
user_data_directory,
make_scoped_refptr(database_task_runner),
make_scoped_refptr(disk_cache_thread),
make_scoped_refptr(quota_manager_proxy)));
return;
}
......@@ -154,6 +152,7 @@ void ServiceWorkerContextWrapper::InitInternal(
context_core_.reset(new ServiceWorkerContextCore(
user_data_directory,
database_task_runner,
disk_cache_thread,
quota_manager_proxy,
observer_list_,
make_scoped_ptr(new ServiceWorkerProcessManager(this))));
......
......@@ -16,6 +16,7 @@
namespace base {
class FilePath;
class MessageLoopProxy;
class SequencedTaskRunner;
}
......@@ -66,11 +67,9 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
friend class ServiceWorkerProcessManager;
virtual ~ServiceWorkerContextWrapper();
void InitForTesting(const base::FilePath& user_data_directory,
base::SequencedTaskRunner* database_task_runner,
quota::QuotaManagerProxy* quota_manager_proxy);
void InitInternal(const base::FilePath& user_data_directory,
base::SequencedTaskRunner* database_task_runner,
base::MessageLoopProxy* disk_cache_thread,
quota::QuotaManagerProxy* quota_manager_proxy);
const scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
......
......@@ -26,6 +26,7 @@ class ServiceWorkerProviderHostTest : public testing::Test {
context_.reset(new ServiceWorkerContextCore(
base::FilePath(),
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
NULL,
NULL,
scoped_ptr<ServiceWorkerProcessManager>()));
......
......@@ -25,6 +25,7 @@ class ServiceWorkerRegistrationTest : public testing::Test {
context_.reset(new ServiceWorkerContextCore(
base::FilePath(),
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
NULL,
NULL,
scoped_ptr<ServiceWorkerProcessManager>()));
......
......@@ -162,6 +162,7 @@ ServiceWorkerStorage::ServiceWorkerStorage(
const base::FilePath& path,
base::WeakPtr<ServiceWorkerContextCore> context,
base::SequencedTaskRunner* database_task_runner,
base::MessageLoopProxy* disk_cache_thread,
quota::QuotaManagerProxy* quota_manager_proxy)
: next_registration_id_(kInvalidServiceWorkerRegistrationId),
next_version_id_(kInvalidServiceWorkerVersionId),
......@@ -169,6 +170,7 @@ ServiceWorkerStorage::ServiceWorkerStorage(
state_(UNINITIALIZED),
context_(context),
database_task_runner_(database_task_runner),
disk_cache_thread_(disk_cache_thread),
quota_manager_proxy_(quota_manager_proxy),
weak_factory_(this) {
if (!path.empty()) {
......
......@@ -20,6 +20,7 @@
#include "url/gurl.h"
namespace base {
class MessageLoopProxy;
class SequencedTaskRunner;
}
......@@ -65,6 +66,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
ServiceWorkerStorage(const base::FilePath& path,
base::WeakPtr<ServiceWorkerContextCore> context,
base::SequencedTaskRunner* database_task_runner,
base::MessageLoopProxy* disk_cache_thread,
quota::QuotaManagerProxy* quota_manager_proxy);
~ServiceWorkerStorage();
......@@ -208,6 +210,7 @@ class CONTENT_EXPORT ServiceWorkerStorage {
scoped_ptr<ServiceWorkerDatabase> database_;
scoped_refptr<base::SequencedTaskRunner> database_task_runner_;
scoped_refptr<base::MessageLoopProxy> disk_cache_thread_;
scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
scoped_ptr<ServiceWorkerDiskCache> disk_cache_;
......
......@@ -75,6 +75,7 @@ class ServiceWorkerStorageTest : public testing::Test {
context_.reset(new ServiceWorkerContextCore(
base::FilePath(),
base::MessageLoopProxy::current(),
base::MessageLoopProxy::current(),
NULL,
NULL,
scoped_ptr<ServiceWorkerProcessManager>()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment