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

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

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 | Annotate | Revision Log
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/service_worker/service_worker_cache.h" 15 #include "content/browser/service_worker/service_worker_cache.h"
16 #include "content/browser/service_worker/service_worker_cache.pb.h" 16 #include "content/browser/service_worker/service_worker_cache.pb.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "net/base/directory_lister.h" 18 #include "net/base/directory_lister.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "webkit/browser/blob/blob_storage_context.h" 20 #include "storage/browser/blob/blob_storage_context.h"
21 21
22 namespace content { 22 namespace content {
23 23
24 // Handles the loading and clean up of ServiceWorkerCache objects. 24 // Handles the loading and clean up of ServiceWorkerCache objects.
25 class ServiceWorkerCacheStorage::CacheLoader 25 class ServiceWorkerCacheStorage::CacheLoader
26 : public base::RefCountedThreadSafe< 26 : public base::RefCountedThreadSafe<
27 ServiceWorkerCacheStorage::CacheLoader> { 27 ServiceWorkerCacheStorage::CacheLoader> {
28 public: 28 public:
29 typedef base::Callback<void(scoped_ptr<ServiceWorkerCache>)> CacheCallback; 29 typedef base::Callback<void(scoped_ptr<ServiceWorkerCache>)> CacheCallback;
30 typedef base::Callback<void(bool)> BoolCallback; 30 typedef base::Callback<void(bool)> BoolCallback;
31 typedef base::Callback<void(scoped_ptr<std::vector<std::string> >)> 31 typedef base::Callback<void(scoped_ptr<std::vector<std::string> >)>
32 StringsCallback; 32 StringsCallback;
33 33
34 CacheLoader( 34 CacheLoader(base::SequencedTaskRunner* cache_task_runner,
35 base::SequencedTaskRunner* cache_task_runner, 35 net::URLRequestContext* request_context,
36 net::URLRequestContext* request_context, 36 base::WeakPtr<storage::BlobStorageContext> blob_context)
37 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context)
38 : cache_task_runner_(cache_task_runner), 37 : cache_task_runner_(cache_task_runner),
39 request_context_(request_context), 38 request_context_(request_context),
40 blob_context_(blob_context) {} 39 blob_context_(blob_context) {}
41 40
42 // Loads the given cache_name, the cache is NULL if it fails. If the cache 41 // Loads the given cache_name, the cache is NULL if it fails. If the cache
43 // doesn't exist a new one is created. 42 // doesn't exist a new one is created.
44 virtual void LoadCache(const std::string& cache_name, 43 virtual void LoadCache(const std::string& cache_name,
45 const CacheCallback& callback) = 0; 44 const CacheCallback& callback) = 0;
46 45
47 // Deletes any pre-existing cache of the same name and then loads it. 46 // Deletes any pre-existing cache of the same name and then loads it.
(...skipping 14 matching lines...) Expand all
62 61
63 protected: 62 protected:
64 friend class base::RefCountedThreadSafe< 63 friend class base::RefCountedThreadSafe<
65 ServiceWorkerCacheStorage::CacheLoader>; 64 ServiceWorkerCacheStorage::CacheLoader>;
66 65
67 virtual ~CacheLoader() {}; 66 virtual ~CacheLoader() {};
68 virtual void LoadCacheImpl(const std::string&) {} 67 virtual void LoadCacheImpl(const std::string&) {}
69 68
70 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; 69 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
71 net::URLRequestContext* request_context_; 70 net::URLRequestContext* request_context_;
72 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context_; 71 base::WeakPtr<storage::BlobStorageContext> blob_context_;
73 }; 72 };
74 73
75 class ServiceWorkerCacheStorage::MemoryLoader 74 class ServiceWorkerCacheStorage::MemoryLoader
76 : public ServiceWorkerCacheStorage::CacheLoader { 75 : public ServiceWorkerCacheStorage::CacheLoader {
77 public: 76 public:
78 MemoryLoader( 77 MemoryLoader(base::SequencedTaskRunner* cache_task_runner,
79 base::SequencedTaskRunner* cache_task_runner, 78 net::URLRequestContext* request_context,
80 net::URLRequestContext* request_context, 79 base::WeakPtr<storage::BlobStorageContext> blob_context)
81 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context)
82 : CacheLoader(cache_task_runner, request_context, blob_context) {} 80 : CacheLoader(cache_task_runner, request_context, blob_context) {}
83 virtual void LoadCache(const std::string& cache_name, 81 virtual void LoadCache(const std::string& cache_name,
84 const CacheCallback& callback) OVERRIDE { 82 const CacheCallback& callback) OVERRIDE {
85 NOTREACHED(); 83 NOTREACHED();
86 } 84 }
87 85
88 virtual void CreateCache(const std::string& cache_name, 86 virtual void CreateCache(const std::string& cache_name,
89 const CacheCallback& callback) OVERRIDE { 87 const CacheCallback& callback) OVERRIDE {
90 scoped_ptr<ServiceWorkerCache> cache = 88 scoped_ptr<ServiceWorkerCache> cache =
91 ServiceWorkerCache::CreateMemoryCache( 89 ServiceWorkerCache::CreateMemoryCache(
(...skipping 19 matching lines...) Expand all
111 private: 109 private:
112 virtual ~MemoryLoader() {} 110 virtual ~MemoryLoader() {}
113 }; 111 };
114 112
115 class ServiceWorkerCacheStorage::SimpleCacheLoader 113 class ServiceWorkerCacheStorage::SimpleCacheLoader
116 : public ServiceWorkerCacheStorage::CacheLoader { 114 : public ServiceWorkerCacheStorage::CacheLoader {
117 public: 115 public:
118 SimpleCacheLoader(const base::FilePath& origin_path, 116 SimpleCacheLoader(const base::FilePath& origin_path,
119 base::SequencedTaskRunner* cache_task_runner, 117 base::SequencedTaskRunner* cache_task_runner,
120 net::URLRequestContext* request_context, 118 net::URLRequestContext* request_context,
121 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) 119 base::WeakPtr<storage::BlobStorageContext> blob_context)
122 : CacheLoader(cache_task_runner, request_context, blob_context), 120 : CacheLoader(cache_task_runner, request_context, blob_context),
123 origin_path_(origin_path) {} 121 origin_path_(origin_path) {}
124 122
125 virtual void LoadCache(const std::string& cache_name, 123 virtual void LoadCache(const std::string& cache_name,
126 const CacheCallback& callback) OVERRIDE { 124 const CacheCallback& callback) OVERRIDE {
127 DCHECK_CURRENTLY_ON(BrowserThread::IO); 125 DCHECK_CURRENTLY_ON(BrowserThread::IO);
128 126
129 // 1. Create the cache's directory if necessary. (LoadCreateDirectoryInPool) 127 // 1. Create the cache's directory if necessary. (LoadCreateDirectoryInPool)
130 // 2. Create the cache object. (LoadDidCreateDirectory) 128 // 2. Create the cache object. (LoadDidCreateDirectory)
131 129
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 370 }
373 371
374 const base::FilePath origin_path_; 372 const base::FilePath origin_path_;
375 }; 373 };
376 374
377 ServiceWorkerCacheStorage::ServiceWorkerCacheStorage( 375 ServiceWorkerCacheStorage::ServiceWorkerCacheStorage(
378 const base::FilePath& path, 376 const base::FilePath& path,
379 bool memory_only, 377 bool memory_only,
380 base::SequencedTaskRunner* cache_task_runner, 378 base::SequencedTaskRunner* cache_task_runner,
381 net::URLRequestContext* request_context, 379 net::URLRequestContext* request_context,
382 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) 380 base::WeakPtr<storage::BlobStorageContext> blob_context)
383 : initialized_(false), 381 : initialized_(false),
384 origin_path_(path), 382 origin_path_(path),
385 cache_task_runner_(cache_task_runner), 383 cache_task_runner_(cache_task_runner),
386 weak_factory_(this) { 384 weak_factory_(this) {
387 if (memory_only) 385 if (memory_only)
388 cache_loader_ = 386 cache_loader_ =
389 new MemoryLoader(cache_task_runner_, request_context, blob_context); 387 new MemoryLoader(cache_task_runner_, request_context, blob_context);
390 else 388 else
391 cache_loader_ = new SimpleCacheLoader( 389 cache_loader_ = new SimpleCacheLoader(
392 origin_path_, cache_task_runner_, request_context, blob_context); 390 origin_path_, cache_task_runner_, request_context, blob_context);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 NameMap::const_iterator it = name_map_.find(cache_name); 707 NameMap::const_iterator it = name_map_.find(cache_name);
710 if (it == name_map_.end()) 708 if (it == name_map_.end())
711 return NULL; 709 return NULL;
712 710
713 ServiceWorkerCache* cache = cache_map_.Lookup(it->second); 711 ServiceWorkerCache* cache = cache_map_.Lookup(it->second);
714 DCHECK(cache); 712 DCHECK(cache);
715 return cache; 713 return cache;
716 } 714 }
717 715
718 } // namespace content 716 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698