Commit 4650dfdf authored by jkarlin's avatar jkarlin Committed by Commit bot

[ServiceWorkerCacheStorage] Delete unused get/create functions.

The spec added 'open' and removed 'get/create'.  Delete get and create.

CLs in this three-legged-patch:

1. Add open to browser - https://codereview.chromium.org/664433003/
2. Add open (remove get/create) to Blink - https://codereview.chromium.org/638023003
*3. Remove get/create from browser - https://codereview.chromium.org/663503002/

BUG=423942

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

Cr-Commit-Position: refs/heads/master@{#300266}
parent 62117928
......@@ -87,12 +87,8 @@ bool ServiceWorkerCacheListener::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheListener, message)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageGet,
OnCacheStorageGet)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageHas,
OnCacheStorageHas)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageCreate,
OnCacheStorageCreate)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageOpen,
OnCacheStorageOpen)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CacheStorageDelete,
......@@ -116,19 +112,6 @@ bool ServiceWorkerCacheListener::OnMessageReceived(
return handled;
}
void ServiceWorkerCacheListener::OnCacheStorageGet(
int request_id,
const base::string16& cache_name) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerCacheListener::OnCacheStorageGet");
context_->cache_manager()->GetCache(
version_->scope().GetOrigin(),
base::UTF16ToUTF8(cache_name),
base::Bind(&ServiceWorkerCacheListener::OnCacheStorageGetCallback,
weak_factory_.GetWeakPtr(),
request_id));
}
void ServiceWorkerCacheListener::OnCacheStorageHas(
int request_id,
const base::string16& cache_name) {
......@@ -142,19 +125,6 @@ void ServiceWorkerCacheListener::OnCacheStorageHas(
request_id));
}
void ServiceWorkerCacheListener::OnCacheStorageCreate(
int request_id,
const base::string16& cache_name) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerCacheListener::OnCacheStorageCreate");
context_->cache_manager()->CreateCache(
version_->scope().GetOrigin(),
base::UTF16ToUTF8(cache_name),
base::Bind(&ServiceWorkerCacheListener::OnCacheStorageCreateCallback,
weak_factory_.GetWeakPtr(),
request_id));
}
void ServiceWorkerCacheListener::OnCacheStorageOpen(
int request_id,
const base::string16& cache_name) {
......@@ -314,20 +284,6 @@ void ServiceWorkerCacheListener::Send(const IPC::Message& message) {
version_->embedded_worker()->SendMessage(message);
}
void ServiceWorkerCacheListener::OnCacheStorageGetCallback(
int request_id,
const scoped_refptr<ServiceWorkerCache>& cache,
ServiceWorkerCacheStorage::CacheStorageError error) {
if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
Send(ServiceWorkerMsg_CacheStorageGetError(
request_id, ToWebServiceWorkerCacheError(error)));
return;
}
CacheID cache_id = StoreCacheReference(cache);
Send(ServiceWorkerMsg_CacheStorageGetSuccess(request_id, cache_id));
}
void ServiceWorkerCacheListener::OnCacheStorageHasCallback(
int request_id,
bool has_cache,
......@@ -346,19 +302,6 @@ void ServiceWorkerCacheListener::OnCacheStorageHasCallback(
Send(ServiceWorkerMsg_CacheStorageHasSuccess(request_id));
}
void ServiceWorkerCacheListener::OnCacheStorageCreateCallback(
int request_id,
const scoped_refptr<ServiceWorkerCache>& cache,
ServiceWorkerCacheStorage::CacheStorageError error) {
if (error != ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR) {
Send(ServiceWorkerMsg_CacheStorageCreateError(
request_id, ToWebServiceWorkerCacheError(error)));
return;
}
CacheID cache_id = StoreCacheReference(cache);
Send(ServiceWorkerMsg_CacheStorageCreateSuccess(request_id, cache_id));
}
void ServiceWorkerCacheListener::OnCacheStorageOpenCallback(
int request_id,
const scoped_refptr<ServiceWorkerCache>& cache,
......
......@@ -351,31 +351,6 @@ ServiceWorkerCacheStorage::ServiceWorkerCacheStorage(
ServiceWorkerCacheStorage::~ServiceWorkerCacheStorage() {
}
void ServiceWorkerCacheStorage::CreateCache(
const std::string& cache_name,
const CacheAndErrorCallback& callback) {
if (!initialized_) {
LazyInit(base::Bind(&ServiceWorkerCacheStorage::CreateCache,
weak_factory_.GetWeakPtr(),
cache_name,
callback));
return;
}
if (cache_map_.find(cache_name) != cache_map_.end()) {
callback.Run(scoped_refptr<ServiceWorkerCache>(),
CACHE_STORAGE_ERROR_EXISTS);
return;
}
cache_loader_->CreateCache(
cache_name,
base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache,
weak_factory_.GetWeakPtr(),
cache_name,
callback));
}
void ServiceWorkerCacheStorage::OpenCache(
const std::string& cache_name,
const CacheAndErrorCallback& callback) {
......@@ -403,29 +378,6 @@ void ServiceWorkerCacheStorage::OpenCache(
callback));
}
void ServiceWorkerCacheStorage::GetCache(
const std::string& cache_name,
const CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!initialized_) {
LazyInit(base::Bind(&ServiceWorkerCacheStorage::GetCache,
weak_factory_.GetWeakPtr(),
cache_name,
callback));
return;
}
scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name);
if (!cache.get()) {
callback.Run(scoped_refptr<ServiceWorkerCache>(),
CACHE_STORAGE_ERROR_NOT_FOUND);
return;
}
callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR);
}
void ServiceWorkerCacheStorage::HasCache(const std::string& cache_name,
const BoolAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......
......@@ -58,17 +58,6 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage {
virtual ~ServiceWorkerCacheStorage();
// Create a ServiceWorkerCache if it doesn't already exist and call the
// callback with the cache. If it already
// exists the callback is called with CACHE_STORAGE_ERROR_EXISTS.
void CreateCache(const std::string& cache_name,
const CacheAndErrorCallback& callback);
// Get the cache for the given key. If not found returns
// CACHE_STORAGE_ERROR_NOT_FOUND.
void GetCache(const std::string& cache_name,
const CacheAndErrorCallback& callback);
// Get the cache for the given key. If the cache is not found it is
// created.
void OpenCache(const std::string& cache_name,
......
......@@ -68,30 +68,6 @@ ServiceWorkerCacheStorageManager::~ServiceWorkerCacheStorageManager() {
}
}
void ServiceWorkerCacheStorageManager::CreateCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
cache_storage->CreateCache(cache_name, callback);
}
void ServiceWorkerCacheStorageManager::GetCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerCacheStorage* cache_storage =
FindOrCreateServiceWorkerCacheManager(origin);
cache_storage->GetCache(cache_name, callback);
}
void ServiceWorkerCacheStorageManager::OpenCache(
const GURL& origin,
const std::string& cache_name,
......
......@@ -45,14 +45,6 @@ class CONTENT_EXPORT ServiceWorkerCacheStorageManager {
// Methods to support the CacheStorage spec. These methods call the
// corresponding ServiceWorkerCacheStorage method on the appropriate thread.
void CreateCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback);
void GetCache(
const GURL& origin,
const std::string& cache_name,
const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback);
void OpenCache(
const GURL& origin,
const std::string& cache_name,
......
......@@ -102,44 +102,6 @@ class ServiceWorkerCacheStorageManagerTest : public testing::Test {
run_loop->Quit();
}
bool CreateCache(const GURL& origin, const std::string& cache_name) {
scoped_ptr<base::RunLoop> loop(new base::RunLoop());
cache_manager_->CreateCache(
origin,
cache_name,
base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheAndErrorCallback,
base::Unretained(this),
base::Unretained(loop.get())));
loop->Run();
bool error = callback_error_ !=
ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR;
if (error)
EXPECT_TRUE(!callback_cache_.get());
else
EXPECT_TRUE(callback_cache_.get());
return !error;
}
bool Get(const GURL& origin, const std::string& cache_name) {
scoped_ptr<base::RunLoop> loop(new base::RunLoop());
cache_manager_->GetCache(
origin,
cache_name,
base::Bind(&ServiceWorkerCacheStorageManagerTest::CacheAndErrorCallback,
base::Unretained(this),
base::Unretained(loop.get())));
loop->Run();
bool error = callback_error_ !=
ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NO_ERROR;
if (error)
EXPECT_TRUE(!callback_cache_.get());
else
EXPECT_TRUE(callback_cache_.get());
return !error;
}
bool Open(const GURL& origin, const std::string& cache_name) {
scoped_ptr<base::RunLoop> loop(new base::RunLoop());
cache_manager_->OpenCache(
......@@ -273,60 +235,38 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, TestsRunOnIOThread) {
EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, CreateCache) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, CreateDuplicateCache) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_FALSE(CreateCache(origin1_, "foo"));
EXPECT_EQ(ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_EXISTS,
callback_error_);
TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenCache) {
EXPECT_TRUE(Open(origin1_, "foo"));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, CreateTwoCaches) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(CreateCache(origin1_, "bar"));
TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenTwoCaches) {
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "bar"));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, CachePointersDiffer) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
scoped_refptr<ServiceWorkerCache> cache = callback_cache_;
EXPECT_TRUE(CreateCache(origin1_, "bar"));
EXPECT_TRUE(cache.get() != callback_cache_.get());
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, Create2CachesSameNameDiffSWs) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(CreateCache(origin2_, "foo"));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, GetCache) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
scoped_refptr<ServiceWorkerCache> cache = callback_cache_;
EXPECT_TRUE(Get(origin1_, "foo"));
EXPECT_TRUE(cache.get() == callback_cache_.get());
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, GetNonExistent) {
EXPECT_FALSE(Get(origin1_, "foo"));
EXPECT_EQ(ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NOT_FOUND,
callback_error_);
EXPECT_TRUE(Open(origin1_, "bar"));
EXPECT_NE(callback_cache_.get(), cache.get());
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenNewCache) {
TEST_P(ServiceWorkerCacheStorageManagerTestP, Open2CachesSameNameDiffOrigins) {
EXPECT_TRUE(Open(origin1_, "foo"));
scoped_refptr<ServiceWorkerCache> cache = callback_cache_;
EXPECT_TRUE(Open(origin2_, "foo"));
EXPECT_NE(cache.get(), callback_cache_.get());
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, OpenExistingCache) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
scoped_refptr<ServiceWorkerCache> cache = callback_cache_;
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(cache.get() == callback_cache_.get());
EXPECT_EQ(callback_cache_.get(), cache.get());
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, HasCache) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Has(origin1_, "foo"));
EXPECT_TRUE(callback_bool_);
}
......@@ -336,15 +276,13 @@ TEST_P(ServiceWorkerCacheStorageManagerTestP, HasNonExistent) {
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, DeleteCache) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Delete(origin1_, "foo"));
EXPECT_FALSE(Get(origin1_, "foo"));
EXPECT_EQ(ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NOT_FOUND,
callback_error_);
EXPECT_FALSE(Has(origin1_, "foo"));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, DeleteTwice) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Delete(origin1_, "foo"));
EXPECT_FALSE(Delete(origin1_, "foo"));
EXPECT_EQ(ServiceWorkerCacheStorage::CACHE_STORAGE_ERROR_NOT_FOUND,
......@@ -357,24 +295,24 @@ TEST_P(ServiceWorkerCacheStorageManagerTestP, EmptyKeys) {
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, SomeKeys) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(CreateCache(origin1_, "bar"));
EXPECT_TRUE(CreateCache(origin2_, "baz"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "bar"));
EXPECT_TRUE(Open(origin2_, "baz"));
EXPECT_TRUE(Keys(origin1_));
EXPECT_EQ(2u, callback_strings_.size());
std::vector<std::string> expected_keys;
expected_keys.push_back("foo");
expected_keys.push_back("bar");
EXPECT_TRUE(expected_keys == callback_strings_);
EXPECT_EQ(expected_keys, callback_strings_);
EXPECT_TRUE(Keys(origin2_));
EXPECT_EQ(1u, callback_strings_.size());
EXPECT_STREQ("baz", callback_strings_[0].c_str());
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, DeletedKeysGone) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(CreateCache(origin1_, "bar"));
EXPECT_TRUE(CreateCache(origin2_, "baz"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "bar"));
EXPECT_TRUE(Open(origin2_, "baz"));
EXPECT_TRUE(Delete(origin1_, "bar"));
EXPECT_TRUE(Keys(origin1_));
EXPECT_EQ(1u, callback_strings_.size());
......@@ -382,23 +320,23 @@ TEST_P(ServiceWorkerCacheStorageManagerTestP, DeletedKeysGone) {
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, Chinese) {
EXPECT_TRUE(CreateCache(origin1_, "你好"));
EXPECT_TRUE(Open(origin1_, "你好"));
scoped_refptr<ServiceWorkerCache> cache = callback_cache_;
EXPECT_TRUE(Get(origin1_, "你好"));
EXPECT_TRUE(cache.get() == callback_cache_.get());
EXPECT_TRUE(Open(origin1_, "你好"));
EXPECT_EQ(callback_cache_.get(), cache.get());
EXPECT_TRUE(Keys(origin1_));
EXPECT_EQ(1u, callback_strings_.size());
EXPECT_TRUE("你好" == callback_strings_[0]);
EXPECT_STREQ("你好", callback_strings_[0].c_str());
}
TEST_F(ServiceWorkerCacheStorageManagerTest, EmptyKey) {
EXPECT_TRUE(CreateCache(origin1_, ""));
EXPECT_TRUE(Open(origin1_, ""));
scoped_refptr<ServiceWorkerCache> cache = callback_cache_;
EXPECT_TRUE(Get(origin1_, ""));
EXPECT_TRUE(Open(origin1_, ""));
EXPECT_EQ(cache.get(), callback_cache_.get());
EXPECT_TRUE(Keys(origin1_));
EXPECT_EQ(1u, callback_strings_.size());
EXPECT_TRUE("" == callback_strings_[0]);
EXPECT_STREQ("", callback_strings_[0].c_str());
EXPECT_TRUE(Has(origin1_, ""));
EXPECT_TRUE(Delete(origin1_, ""));
EXPECT_TRUE(Keys(origin1_));
......@@ -406,10 +344,10 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, EmptyKey) {
}
TEST_F(ServiceWorkerCacheStorageManagerTest, DataPersists) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(CreateCache(origin1_, "bar"));
EXPECT_TRUE(CreateCache(origin1_, "baz"));
EXPECT_TRUE(CreateCache(origin2_, "raz"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "bar"));
EXPECT_TRUE(Open(origin1_, "baz"));
EXPECT_TRUE(Open(origin2_, "raz"));
EXPECT_TRUE(Delete(origin1_, "bar"));
cache_manager_ =
ServiceWorkerCacheStorageManager::Create(cache_manager_.get());
......@@ -418,12 +356,12 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, DataPersists) {
std::vector<std::string> expected_keys;
expected_keys.push_back("foo");
expected_keys.push_back("baz");
EXPECT_TRUE(expected_keys == callback_strings_);
EXPECT_EQ(expected_keys, callback_strings_);
}
TEST_F(ServiceWorkerCacheStorageManagerMemoryOnlyTest, DataLostWhenMemoryOnly) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(CreateCache(origin2_, "baz"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Open(origin2_, "baz"));
cache_manager_ =
ServiceWorkerCacheStorageManager::Create(cache_manager_.get());
EXPECT_TRUE(Keys(origin1_));
......@@ -434,7 +372,7 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, BadCacheName) {
// Since the implementation writes cache names to disk, ensure that we don't
// escape the directory.
const std::string bad_name = "../../../../../../../../../../../../../../foo";
EXPECT_TRUE(CreateCache(origin1_, bad_name));
EXPECT_TRUE(Open(origin1_, bad_name));
EXPECT_TRUE(Keys(origin1_));
EXPECT_EQ(1u, callback_strings_.size());
EXPECT_STREQ(bad_name.c_str(), callback_strings_[0].c_str());
......@@ -444,7 +382,7 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, BadOriginName) {
// Since the implementation writes origin names to disk, ensure that we don't
// escape the directory.
GURL bad_origin("../../../../../../../../../../../../../../foo");
EXPECT_TRUE(CreateCache(bad_origin, "foo"));
EXPECT_TRUE(Open(bad_origin, "foo"));
EXPECT_TRUE(Keys(bad_origin));
EXPECT_EQ(1u, callback_strings_.size());
EXPECT_STREQ("foo", callback_strings_[0].c_str());
......@@ -454,7 +392,7 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, BadOriginName) {
// ServiceWorkerCache
// it should be deleted.
TEST_F(ServiceWorkerCacheStorageManagerTest, DropReference) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
base::WeakPtr<ServiceWorkerCache> cache = callback_cache_->AsWeakPtr();
callback_cache_ = NULL;
EXPECT_TRUE(!cache);
......@@ -464,7 +402,7 @@ TEST_F(ServiceWorkerCacheStorageManagerTest, DropReference) {
// calls delete.
TEST_F(ServiceWorkerCacheStorageManagerMemoryOnlyTest,
MemoryLosesReferenceOnlyAfterDelete) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
base::WeakPtr<ServiceWorkerCache> cache = callback_cache_->AsWeakPtr();
callback_cache_ = NULL;
EXPECT_TRUE(cache);
......@@ -473,15 +411,15 @@ TEST_F(ServiceWorkerCacheStorageManagerMemoryOnlyTest,
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, RecreateCacheOnDemand) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(CachePut(callback_cache_, "bar"));
callback_cache_ = NULL;
EXPECT_TRUE(Get(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(CacheMatch(callback_cache_, "bar"));
}
TEST_P(ServiceWorkerCacheStorageManagerTestP, DeleteBeforeRelease) {
EXPECT_TRUE(CreateCache(origin1_, "foo"));
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(Delete(origin1_, "foo"));
EXPECT_TRUE(callback_cache_->AsWeakPtr());
}
......
......@@ -189,18 +189,10 @@ IPC_MESSAGE_ROUTED3(ServiceWorkerHostMsg_PostMessageToDocument,
std::vector<int> /* sent_message_port_ids */)
// CacheStorage operations in the browser.
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageGet,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageHas,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageCreate,
int /* request_id */,
base::string16 /* fetch_store_name */)
IPC_MESSAGE_ROUTED2(ServiceWorkerHostMsg_CacheStorageOpen,
int /* request_id */,
base::string16 /* fetch_store_name */)
......@@ -365,14 +357,8 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DidGetClientDocuments,
std::vector<int> /* client_ids */)
// Sent via EmbeddedWorker at successful completion of CacheStorage operations.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageGetSuccess,
int /* request_id */,
int /* fetch_store_id */)
IPC_MESSAGE_CONTROL1(ServiceWorkerMsg_CacheStorageHasSuccess,
int /* request_id */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageCreateSuccess,
int /* request_id */,
int /* fetch_store_id */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageOpenSuccess,
int /* request_id */,
int /* fetch_store_id */)
......@@ -383,15 +369,9 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageKeysSuccess,
std::vector<base::string16> /* keys */)
// Sent via EmbeddedWorker at erroneous completion of CacheStorage operations.
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageGetError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageHasError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageCreateError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_CacheStorageOpenError,
int /* request_id */,
blink::WebServiceWorkerCacheError /* reason */)
......
......@@ -204,9 +204,7 @@ ServiceWorkerCacheStorageDispatcher::ServiceWorkerCacheStorageDispatcher(
weak_factory_(this) {}
ServiceWorkerCacheStorageDispatcher::~ServiceWorkerCacheStorageDispatcher() {
ClearCallbacksMapWithErrors(&get_callbacks_);
ClearCallbacksMapWithErrors(&has_callbacks_);
ClearCallbacksMapWithErrors(&create_callbacks_);
ClearCallbacksMapWithErrors(&open_callbacks_);
ClearCallbacksMapWithErrors(&delete_callbacks_);
ClearCallbacksMapWithErrors(&keys_callbacks_);
......@@ -221,24 +219,16 @@ bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerCacheStorageDispatcher, message)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetSuccess,
OnCacheStorageGetSuccess)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasSuccess,
OnCacheStorageHasSuccess)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateSuccess,
OnCacheStorageCreateSuccess)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageOpenSuccess,
OnCacheStorageOpenSuccess)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteSuccess,
OnCacheStorageDeleteSuccess)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageKeysSuccess,
OnCacheStorageKeysSuccess)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageGetError,
OnCacheStorageGetError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageHasError,
OnCacheStorageHasError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageCreateError,
OnCacheStorageCreateError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageOpenError,
OnCacheStorageOpenError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CacheStorageDeleteError,
......@@ -267,16 +257,6 @@ bool ServiceWorkerCacheStorageDispatcher::OnMessageReceived(
return handled;
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetSuccess(
int request_id,
int cache_id) {
WebCache* web_cache = new WebCache(weak_factory_.GetWeakPtr(), cache_id);
web_caches_.AddWithID(web_cache, cache_id);
CacheStorageWithCacheCallbacks* callbacks = get_callbacks_.Lookup(request_id);
callbacks->onSuccess(web_cache);
get_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess(
int request_id) {
CacheStorageCallbacks* callbacks = has_callbacks_.Lookup(request_id);
......@@ -284,17 +264,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasSuccess(
has_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageCreateSuccess(
int request_id,
int cache_id) {
WebCache* web_cache = new WebCache(weak_factory_.GetWeakPtr(), cache_id);
web_caches_.AddWithID(web_cache, cache_id);
CacheStorageWithCacheCallbacks* callbacks =
create_callbacks_.Lookup(request_id);
callbacks->onSuccess(web_cache);
create_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenSuccess(
int request_id,
int cache_id) {
......@@ -325,15 +294,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageKeysSuccess(
keys_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageGetError(
int request_id,
blink::WebServiceWorkerCacheError reason) {
CacheStorageWithCacheCallbacks* callbacks =
get_callbacks_.Lookup(request_id);
callbacks->onError(&reason);
get_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasError(
int request_id,
blink::WebServiceWorkerCacheError reason) {
......@@ -342,15 +302,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheStorageHasError(
has_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageCreateError(
int request_id,
blink::WebServiceWorkerCacheError reason) {
CacheStorageWithCacheCallbacks* callbacks =
create_callbacks_.Lookup(request_id);
callbacks->onError(&reason);
create_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::OnCacheStorageOpenError(
int request_id,
blink::WebServiceWorkerCacheError reason) {
......@@ -461,14 +412,6 @@ void ServiceWorkerCacheStorageDispatcher::OnCacheBatchError(
cache_batch_callbacks_.Remove(request_id);
}
void ServiceWorkerCacheStorageDispatcher::dispatchGet(
CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName) {
int request_id = get_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageGet(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchHas(
CacheStorageCallbacks* callbacks,
const blink::WebString& cacheName) {
......@@ -477,14 +420,6 @@ void ServiceWorkerCacheStorageDispatcher::dispatchHas(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchCreate(
CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName) {
int request_id = create_callbacks_.Add(callbacks);
script_context_->Send(new ServiceWorkerHostMsg_CacheStorageCreate(
script_context_->GetRoutingID(), request_id, cacheName));
}
void ServiceWorkerCacheStorageDispatcher::dispatchOpen(
CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName) {
......
......@@ -38,20 +38,14 @@ class ServiceWorkerCacheStorageDispatcher
bool OnMessageReceived(const IPC::Message& message);
// Message handlers for CacheStorage messages from the browser process.
void OnCacheStorageGetSuccess(int request_id, int cache_id);
void OnCacheStorageHasSuccess(int request_id);
void OnCacheStorageCreateSuccess(int request_id, int cache_id);
void OnCacheStorageOpenSuccess(int request_id, int cache_id);
void OnCacheStorageDeleteSuccess(int request_id);
void OnCacheStorageKeysSuccess(int request_id,
const std::vector<base::string16>& keys);
void OnCacheStorageGetError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageHasError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageCreateError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageOpenError(int request_id,
blink::WebServiceWorkerCacheError reason);
void OnCacheStorageDeleteError(int request_id,
......@@ -81,12 +75,8 @@ class ServiceWorkerCacheStorageDispatcher
blink::WebServiceWorkerCacheError reason);
// From WebServiceWorkerCacheStorage:
virtual void dispatchGet(CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchHas(CacheStorageCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchCreate(CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchOpen(CacheStorageWithCacheCallbacks* callbacks,
const blink::WebString& cacheName);
virtual void dispatchDelete(CacheStorageCallbacks* callbacks,
......@@ -144,9 +134,7 @@ class ServiceWorkerCacheStorageDispatcher
// Not owned. The script context containing this object.
ServiceWorkerScriptContext* script_context_;
WithCacheCallbacksMap get_callbacks_;
CallbacksMap has_callbacks_;
WithCacheCallbacksMap create_callbacks_;
WithCacheCallbacksMap open_callbacks_;
CallbacksMap delete_callbacks_;
KeysCallbacksMap keys_callbacks_;
......
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