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

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

Issue 465463002: Initial implementation of ServiceWorkerCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cache2
Patch Set: Nits Created 6 years, 4 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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/sha1.h" 12 #include "base/sha1.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "content/browser/fileapi/chrome_blob_storage_context.h"
michaeln 2014/08/14 22:59:00 is this needed or is the include for blob_storage_
jkarlin 2014/08/15 11:49:44 Done.
15 #include "content/browser/service_worker/service_worker_cache.h" 16 #include "content/browser/service_worker/service_worker_cache.h"
16 #include "content/browser/service_worker/service_worker_cache.pb.h" 17 #include "content/browser/service_worker/service_worker_cache.pb.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "net/base/directory_lister.h" 19 #include "net/base/directory_lister.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "webkit/browser/blob/blob_storage_context.h" 21 #include "webkit/browser/blob/blob_storage_context.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 // Handles the loading and clean up of ServiceWorkerCache objects. 25 // Handles the loading and clean up of ServiceWorkerCache objects.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 virtual void WriteIndex(CacheMap* caches, const BoolCallback& callback) = 0; 58 virtual void WriteIndex(CacheMap* caches, const BoolCallback& callback) = 0;
58 59
59 // Loads the cache names from disk if applicable. 60 // Loads the cache names from disk if applicable.
60 virtual void LoadIndex(scoped_ptr<std::vector<std::string> > cache_names, 61 virtual void LoadIndex(scoped_ptr<std::vector<std::string> > cache_names,
61 const StringsCallback& callback) = 0; 62 const StringsCallback& callback) = 0;
62 63
63 protected: 64 protected:
64 friend class base::RefCountedThreadSafe< 65 friend class base::RefCountedThreadSafe<
65 ServiceWorkerCacheStorage::CacheLoader>; 66 ServiceWorkerCacheStorage::CacheLoader>;
66 67
67 virtual ~CacheLoader() {}; 68 virtual ~CacheLoader() {}
68 virtual void LoadCacheImpl(const std::string&) {} 69 virtual void LoadCacheImpl(const std::string&) {}
69 70
70 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; 71 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
71 net::URLRequestContext* request_context_; 72 net::URLRequestContext* request_context_;
72 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context_; 73 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context_;
73 }; 74 };
74 75
75 class ServiceWorkerCacheStorage::MemoryLoader 76 class ServiceWorkerCacheStorage::MemoryLoader
76 : public ServiceWorkerCacheStorage::CacheLoader { 77 : public ServiceWorkerCacheStorage::CacheLoader {
77 public: 78 public:
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 ++it) { 529 ++it) {
529 names.push_back(it->first); 530 names.push_back(it->first);
530 } 531 }
531 532
532 callback.Run(names, CACHE_STORAGE_ERROR_NO_ERROR); 533 callback.Run(names, CACHE_STORAGE_ERROR_NO_ERROR);
533 } 534 }
534 535
535 void ServiceWorkerCacheStorage::DidCreateBackend( 536 void ServiceWorkerCacheStorage::DidCreateBackend(
536 base::WeakPtr<ServiceWorkerCache> cache, 537 base::WeakPtr<ServiceWorkerCache> cache,
537 const CacheAndErrorCallback& callback, 538 const CacheAndErrorCallback& callback,
538 bool success) { 539 ServiceWorkerCache::ErrorType error) {
539 DCHECK_CURRENTLY_ON(BrowserThread::IO); 540 DCHECK_CURRENTLY_ON(BrowserThread::IO);
540 541
541 if (!success || !cache) { 542 if (error != ServiceWorkerCache::ErrorTypeOK) {
542 // TODO(jkarlin): This should delete the directory and try again in case 543 // TODO(jkarlin): This should delete the directory and try again in case
543 // the cache is simply corrupt. 544 // the cache is simply corrupt.
544 callback.Run(0, CACHE_STORAGE_ERROR_STORAGE); 545 callback.Run(0, CACHE_STORAGE_ERROR_STORAGE);
545 return; 546 return;
546 } 547 }
547 callback.Run(cache->id(), CACHE_STORAGE_ERROR_NO_ERROR); 548 callback.Run(cache->id(), CACHE_STORAGE_ERROR_NO_ERROR);
548 } 549 }
549 550
550 // Init is run lazily so that it is called on the proper MessageLoop. 551 // Init is run lazily so that it is called on the proper MessageLoop.
551 void ServiceWorkerCacheStorage::LazyInit(const base::Closure& callback) { 552 void ServiceWorkerCacheStorage::LazyInit(const base::Closure& callback) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 NameMap::const_iterator it = name_map_.find(cache_name); 710 NameMap::const_iterator it = name_map_.find(cache_name);
710 if (it == name_map_.end()) 711 if (it == name_map_.end())
711 return NULL; 712 return NULL;
712 713
713 ServiceWorkerCache* cache = cache_map_.Lookup(it->second); 714 ServiceWorkerCache* cache = cache_map_.Lookup(it->second);
714 DCHECK(cache); 715 DCHECK(cache);
715 return cache; 716 return cache;
716 } 717 }
717 718
718 } // namespace content 719 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698