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

Side by Side Diff: content/browser/service_worker/service_worker_cache_storage.cc

Issue 663503002: [ServiceWorkerCacheStorage] Delete unused get/create functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@open
Patch Set: Rebase Created 6 years, 2 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/service_worker/service_worker_cache_storage.h" 5 #include "content/browser/service_worker/service_worker_cache_storage.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 cache_loader_.reset(new MemoryLoader( 344 cache_loader_.reset(new MemoryLoader(
345 cache_task_runner_.get(), request_context, blob_context)); 345 cache_task_runner_.get(), request_context, blob_context));
346 else 346 else
347 cache_loader_.reset(new SimpleCacheLoader( 347 cache_loader_.reset(new SimpleCacheLoader(
348 origin_path_, cache_task_runner_.get(), request_context, blob_context)); 348 origin_path_, cache_task_runner_.get(), request_context, blob_context));
349 } 349 }
350 350
351 ServiceWorkerCacheStorage::~ServiceWorkerCacheStorage() { 351 ServiceWorkerCacheStorage::~ServiceWorkerCacheStorage() {
352 } 352 }
353 353
354 void ServiceWorkerCacheStorage::CreateCache(
355 const std::string& cache_name,
356 const CacheAndErrorCallback& callback) {
357 if (!initialized_) {
358 LazyInit(base::Bind(&ServiceWorkerCacheStorage::CreateCache,
359 weak_factory_.GetWeakPtr(),
360 cache_name,
361 callback));
362 return;
363 }
364
365 if (cache_map_.find(cache_name) != cache_map_.end()) {
366 callback.Run(scoped_refptr<ServiceWorkerCache>(),
367 CACHE_STORAGE_ERROR_EXISTS);
368 return;
369 }
370
371 cache_loader_->CreateCache(
372 cache_name,
373 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache,
374 weak_factory_.GetWeakPtr(),
375 cache_name,
376 callback));
377 }
378
379 void ServiceWorkerCacheStorage::OpenCache( 354 void ServiceWorkerCacheStorage::OpenCache(
380 const std::string& cache_name, 355 const std::string& cache_name,
381 const CacheAndErrorCallback& callback) { 356 const CacheAndErrorCallback& callback) {
382 DCHECK_CURRENTLY_ON(BrowserThread::IO); 357 DCHECK_CURRENTLY_ON(BrowserThread::IO);
383 358
384 if (!initialized_) { 359 if (!initialized_) {
385 LazyInit(base::Bind(&ServiceWorkerCacheStorage::OpenCache, 360 LazyInit(base::Bind(&ServiceWorkerCacheStorage::OpenCache,
386 weak_factory_.GetWeakPtr(), 361 weak_factory_.GetWeakPtr(),
387 cache_name, 362 cache_name,
388 callback)); 363 callback));
389 return; 364 return;
390 } 365 }
391 366
392 scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name); 367 scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name);
393 if (cache.get()) { 368 if (cache.get()) {
394 callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR); 369 callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR);
395 return; 370 return;
396 } 371 }
397 372
398 cache_loader_->CreateCache( 373 cache_loader_->CreateCache(
399 cache_name, 374 cache_name,
400 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache, 375 base::Bind(&ServiceWorkerCacheStorage::CreateCacheDidCreateCache,
401 weak_factory_.GetWeakPtr(), 376 weak_factory_.GetWeakPtr(),
402 cache_name, 377 cache_name,
403 callback)); 378 callback));
404 } 379 }
405 380
406 void ServiceWorkerCacheStorage::GetCache(
407 const std::string& cache_name,
408 const CacheAndErrorCallback& callback) {
409 DCHECK_CURRENTLY_ON(BrowserThread::IO);
410
411 if (!initialized_) {
412 LazyInit(base::Bind(&ServiceWorkerCacheStorage::GetCache,
413 weak_factory_.GetWeakPtr(),
414 cache_name,
415 callback));
416 return;
417 }
418
419 scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name);
420 if (!cache.get()) {
421 callback.Run(scoped_refptr<ServiceWorkerCache>(),
422 CACHE_STORAGE_ERROR_NOT_FOUND);
423 return;
424 }
425
426 callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR);
427 }
428
429 void ServiceWorkerCacheStorage::HasCache(const std::string& cache_name, 381 void ServiceWorkerCacheStorage::HasCache(const std::string& cache_name,
430 const BoolAndErrorCallback& callback) { 382 const BoolAndErrorCallback& callback) {
431 DCHECK_CURRENTLY_ON(BrowserThread::IO); 383 DCHECK_CURRENTLY_ON(BrowserThread::IO);
432 384
433 if (!initialized_) { 385 if (!initialized_) {
434 LazyInit(base::Bind(&ServiceWorkerCacheStorage::HasCache, 386 LazyInit(base::Bind(&ServiceWorkerCacheStorage::HasCache,
435 weak_factory_.GetWeakPtr(), 387 weak_factory_.GetWeakPtr(),
436 cache_name, 388 cache_name,
437 callback)); 389 callback));
438 return; 390 return;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 scoped_refptr<ServiceWorkerCache> new_cache = 565 scoped_refptr<ServiceWorkerCache> new_cache =
614 cache_loader_->CreateServiceWorkerCache(cache_name); 566 cache_loader_->CreateServiceWorkerCache(cache_name);
615 map_iter->second = new_cache->AsWeakPtr(); 567 map_iter->second = new_cache->AsWeakPtr();
616 return new_cache; 568 return new_cache;
617 } 569 }
618 570
619 return make_scoped_refptr(cache.get()); 571 return make_scoped_refptr(cache.get());
620 } 572 }
621 573
622 } // namespace content 574 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698