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

Side by Side Diff: content/browser/cache_storage/cache_storage.cc

Issue 1751833002: Use string16 for cache_name in the back end of CacheStorage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment and test Created 4 years, 9 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/cache_storage/cache_storage.h" 5 #include "content/browser/cache_storage/cache_storage.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/barrier_closure.h" 12 #include "base/barrier_closure.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/memory_mapped_file.h" 14 #include "base/files/memory_mapped_file.h"
15 #include "base/guid.h" 15 #include "base/guid.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
19 #include "base/numerics/safe_conversions.h" 19 #include "base/numerics/safe_conversions.h"
20 #include "base/sha1.h" 20 #include "base/sha1.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/stl_util.h" 22 #include "base/stl_util.h"
23 #include "base/strings/string16.h"
23 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h"
25 #include "base/thread_task_runner_handle.h" 27 #include "base/thread_task_runner_handle.h"
26 #include "content/browser/cache_storage/cache_storage.pb.h" 28 #include "content/browser/cache_storage/cache_storage.pb.h"
27 #include "content/browser/cache_storage/cache_storage_cache.h" 29 #include "content/browser/cache_storage/cache_storage_cache.h"
28 #include "content/browser/cache_storage/cache_storage_scheduler.h" 30 #include "content/browser/cache_storage/cache_storage_scheduler.h"
29 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
30 #include "net/base/directory_lister.h" 32 #include "net/base/directory_lister.h"
31 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
32 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
33 #include "storage/browser/blob/blob_storage_context.h" 35 #include "storage/browser/blob/blob_storage_context.h"
34 #include "storage/browser/quota/quota_manager_proxy.h" 36 #include "storage/browser/quota/quota_manager_proxy.h"
(...skipping 28 matching lines...) Expand all
63 } // namespace 65 } // namespace
64 66
65 const char CacheStorage::kIndexFileName[] = "index.txt"; 67 const char CacheStorage::kIndexFileName[] = "index.txt";
66 68
67 // Handles the loading and clean up of CacheStorageCache objects. 69 // Handles the loading and clean up of CacheStorageCache objects.
68 class CacheStorage::CacheLoader { 70 class CacheStorage::CacheLoader {
69 public: 71 public:
70 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&)> 72 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&)>
71 CacheCallback; 73 CacheCallback;
72 typedef base::Callback<void(bool)> BoolCallback; 74 typedef base::Callback<void(bool)> BoolCallback;
73 typedef base::Callback<void(scoped_ptr<std::vector<std::string>>)> 75 typedef base::Callback<void(scoped_ptr<std::vector<base::string16>>)>
74 StringVectorCallback; 76 StringVectorCallback;
75 77
76 CacheLoader( 78 CacheLoader(
77 base::SequencedTaskRunner* cache_task_runner, 79 base::SequencedTaskRunner* cache_task_runner,
78 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 80 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
79 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 81 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
80 base::WeakPtr<storage::BlobStorageContext> blob_context, 82 base::WeakPtr<storage::BlobStorageContext> blob_context,
81 const GURL& origin) 83 const GURL& origin)
82 : cache_task_runner_(cache_task_runner), 84 : cache_task_runner_(cache_task_runner),
83 request_context_getter_(request_context_getter), 85 request_context_getter_(request_context_getter),
84 quota_manager_proxy_(quota_manager_proxy), 86 quota_manager_proxy_(quota_manager_proxy),
85 blob_context_(blob_context), 87 blob_context_(blob_context),
86 origin_(origin) { 88 origin_(origin) {
87 DCHECK(!origin_.is_empty()); 89 DCHECK(!origin_.is_empty());
88 } 90 }
89 91
90 virtual ~CacheLoader() {} 92 virtual ~CacheLoader() {}
91 93
92 // Creates a CacheStorageCache with the given name. It does not attempt to 94 // Creates a CacheStorageCache with the given name. It does not attempt to
93 // load the backend, that happens lazily when the cache is used. 95 // load the backend, that happens lazily when the cache is used.
94 virtual scoped_refptr<CacheStorageCache> CreateCache( 96 virtual scoped_refptr<CacheStorageCache> CreateCache(
95 const std::string& cache_name) = 0; 97 const base::string16& cache_name) = 0;
96 98
97 // Deletes any pre-existing cache of the same name and then loads it. 99 // Deletes any pre-existing cache of the same name and then loads it.
98 virtual void PrepareNewCacheDestination(const std::string& cache_name, 100 virtual void PrepareNewCacheDestination(const base::string16& cache_name,
99 const CacheCallback& callback) = 0; 101 const CacheCallback& callback) = 0;
100 102
101 // After the backend has been deleted, do any extra house keeping such as 103 // After the backend has been deleted, do any extra house keeping such as
102 // removing the cache's directory. 104 // removing the cache's directory.
103 virtual void CleanUpDeletedCache(const std::string& key, 105 virtual void CleanUpDeletedCache(const base::string16& cache_name,
104 const BoolCallback& callback) = 0; 106 const BoolCallback& callback) = 0;
105 107
106 // Writes the cache names (and sizes) to disk if applicable. 108 // Writes the cache names (and sizes) to disk if applicable.
107 virtual void WriteIndex(const StringVector& cache_names, 109 virtual void WriteIndex(const StringVector& cache_names,
108 const BoolCallback& callback) = 0; 110 const BoolCallback& callback) = 0;
109 111
110 // Loads the cache names from disk if applicable. 112 // Loads the cache names from disk if applicable.
111 virtual void LoadIndex(scoped_ptr<std::vector<std::string>> cache_names, 113 virtual void LoadIndex(scoped_ptr<std::vector<base::string16>> cache_names,
112 const StringVectorCallback& callback) = 0; 114 const StringVectorCallback& callback) = 0;
113 115
114 protected: 116 protected:
115 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; 117 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
116 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 118 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
117 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; 119 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
118 base::WeakPtr<storage::BlobStorageContext> blob_context_; 120 base::WeakPtr<storage::BlobStorageContext> blob_context_;
119 GURL origin_; 121 GURL origin_;
120 }; 122 };
121 123
122 // Creates memory-only ServiceWorkerCaches. Because these caches have no 124 // Creates memory-only ServiceWorkerCaches. Because these caches have no
123 // persistent storage it is not safe to free them from memory if they might be 125 // persistent storage it is not safe to free them from memory if they might be
124 // used again. Therefore this class holds a reference to each cache until the 126 // used again. Therefore this class holds a reference to each cache until the
125 // cache is deleted. 127 // cache is deleted.
126 class CacheStorage::MemoryLoader : public CacheStorage::CacheLoader { 128 class CacheStorage::MemoryLoader : public CacheStorage::CacheLoader {
127 public: 129 public:
128 MemoryLoader( 130 MemoryLoader(
129 base::SequencedTaskRunner* cache_task_runner, 131 base::SequencedTaskRunner* cache_task_runner,
130 const scoped_refptr<net::URLRequestContextGetter>& request_context, 132 const scoped_refptr<net::URLRequestContextGetter>& request_context,
131 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 133 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
132 base::WeakPtr<storage::BlobStorageContext> blob_context, 134 base::WeakPtr<storage::BlobStorageContext> blob_context,
133 const GURL& origin) 135 const GURL& origin)
134 : CacheLoader(cache_task_runner, 136 : CacheLoader(cache_task_runner,
135 request_context, 137 request_context,
136 quota_manager_proxy, 138 quota_manager_proxy,
137 blob_context, 139 blob_context,
138 origin) {} 140 origin) {}
139 141
140 scoped_refptr<CacheStorageCache> CreateCache( 142 scoped_refptr<CacheStorageCache> CreateCache(
141 const std::string& cache_name) override { 143 const base::string16& cache_name) override {
142 return CacheStorageCache::CreateMemoryCache( 144 return CacheStorageCache::CreateMemoryCache(
143 origin_, request_context_getter_, quota_manager_proxy_, blob_context_); 145 origin_, request_context_getter_, quota_manager_proxy_, blob_context_);
144 } 146 }
145 147
146 void PrepareNewCacheDestination(const std::string& cache_name, 148 void PrepareNewCacheDestination(const base::string16& cache_name,
147 const CacheCallback& callback) override { 149 const CacheCallback& callback) override {
148 scoped_refptr<CacheStorageCache> cache = CreateCache(cache_name); 150 scoped_refptr<CacheStorageCache> cache = CreateCache(cache_name);
149 cache_refs_.insert(std::make_pair(cache_name, cache)); 151 cache_refs_.insert(std::make_pair(cache_name, cache));
150 callback.Run(cache); 152 callback.Run(cache);
151 } 153 }
152 154
153 void CleanUpDeletedCache(const std::string& cache_name, 155 void CleanUpDeletedCache(const base::string16& cache_name,
154 const BoolCallback& callback) override { 156 const BoolCallback& callback) override {
155 CacheRefMap::iterator it = cache_refs_.find(cache_name); 157 CacheRefMap::iterator it = cache_refs_.find(cache_name);
156 DCHECK(it != cache_refs_.end()); 158 DCHECK(it != cache_refs_.end());
157 cache_refs_.erase(it); 159 cache_refs_.erase(it);
158 callback.Run(true); 160 callback.Run(true);
159 } 161 }
160 162
161 void WriteIndex(const StringVector& cache_names, 163 void WriteIndex(const StringVector& cache_names,
162 const BoolCallback& callback) override { 164 const BoolCallback& callback) override {
163 callback.Run(false); 165 callback.Run(false);
164 } 166 }
165 167
166 void LoadIndex(scoped_ptr<std::vector<std::string>> cache_names, 168 void LoadIndex(scoped_ptr<std::vector<base::string16>> cache_names,
167 const StringVectorCallback& callback) override { 169 const StringVectorCallback& callback) override {
168 callback.Run(std::move(cache_names)); 170 callback.Run(std::move(cache_names));
169 } 171 }
170 172
171 private: 173 private:
172 typedef std::map<std::string, scoped_refptr<CacheStorageCache>> CacheRefMap; 174 typedef std::map<base::string16, scoped_refptr<CacheStorageCache>>
175 CacheRefMap;
173 ~MemoryLoader() override {} 176 ~MemoryLoader() override {}
174 177
175 // Keep a reference to each cache to ensure that it's not freed before the 178 // Keep a reference to each cache to ensure that it's not freed before the
176 // client calls CacheStorage::Delete or the CacheStorage is 179 // client calls CacheStorage::Delete or the CacheStorage is
177 // freed. 180 // freed.
178 CacheRefMap cache_refs_; 181 CacheRefMap cache_refs_;
179 }; 182 };
180 183
181 class CacheStorage::SimpleCacheLoader : public CacheStorage::CacheLoader { 184 class CacheStorage::SimpleCacheLoader : public CacheStorage::CacheLoader {
182 public: 185 public:
183 SimpleCacheLoader( 186 SimpleCacheLoader(
184 const base::FilePath& origin_path, 187 const base::FilePath& origin_path,
185 base::SequencedTaskRunner* cache_task_runner, 188 base::SequencedTaskRunner* cache_task_runner,
186 const scoped_refptr<net::URLRequestContextGetter>& request_context, 189 const scoped_refptr<net::URLRequestContextGetter>& request_context,
187 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 190 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
188 base::WeakPtr<storage::BlobStorageContext> blob_context, 191 base::WeakPtr<storage::BlobStorageContext> blob_context,
189 const GURL& origin) 192 const GURL& origin)
190 : CacheLoader(cache_task_runner, 193 : CacheLoader(cache_task_runner,
191 request_context, 194 request_context,
192 quota_manager_proxy, 195 quota_manager_proxy,
193 blob_context, 196 blob_context,
194 origin), 197 origin),
195 origin_path_(origin_path), 198 origin_path_(origin_path),
196 weak_ptr_factory_(this) {} 199 weak_ptr_factory_(this) {}
197 200
198 scoped_refptr<CacheStorageCache> CreateCache( 201 scoped_refptr<CacheStorageCache> CreateCache(
199 const std::string& cache_name) override { 202 const base::string16& cache_name) override {
200 DCHECK_CURRENTLY_ON(BrowserThread::IO); 203 DCHECK_CURRENTLY_ON(BrowserThread::IO);
201 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name)); 204 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name));
202 205
203 std::string cache_dir = cache_name_to_cache_dir_[cache_name]; 206 std::string cache_dir = cache_name_to_cache_dir_[cache_name];
204 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir); 207 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir);
205 return CacheStorageCache::CreatePersistentCache( 208 return CacheStorageCache::CreatePersistentCache(
206 origin_, cache_path, request_context_getter_, quota_manager_proxy_, 209 origin_, cache_path, request_context_getter_, quota_manager_proxy_,
207 blob_context_); 210 blob_context_);
208 } 211 }
209 212
210 void PrepareNewCacheDestination(const std::string& cache_name, 213 void PrepareNewCacheDestination(const base::string16& cache_name,
211 const CacheCallback& callback) override { 214 const CacheCallback& callback) override {
212 DCHECK_CURRENTLY_ON(BrowserThread::IO); 215 DCHECK_CURRENTLY_ON(BrowserThread::IO);
213 216
214 PostTaskAndReplyWithResult( 217 PostTaskAndReplyWithResult(
215 cache_task_runner_.get(), FROM_HERE, 218 cache_task_runner_.get(), FROM_HERE,
216 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool, 219 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool,
217 origin_path_), 220 origin_path_),
218 base::Bind(&SimpleCacheLoader::PrepareNewCacheCreateCache, 221 base::Bind(&SimpleCacheLoader::PrepareNewCacheCreateCache,
219 weak_ptr_factory_.GetWeakPtr(), cache_name, callback)); 222 weak_ptr_factory_.GetWeakPtr(), cache_name, callback));
220 } 223 }
221 224
222 // Runs on the cache_task_runner_. 225 // Runs on the cache_task_runner_.
223 static std::string PrepareNewCacheDirectoryInPool( 226 static std::string PrepareNewCacheDirectoryInPool(
224 const base::FilePath& origin_path) { 227 const base::FilePath& origin_path) {
225 std::string cache_dir; 228 std::string cache_dir;
226 base::FilePath cache_path; 229 base::FilePath cache_path;
227 do { 230 do {
228 cache_dir = base::GenerateGUID(); 231 cache_dir = base::GenerateGUID();
229 cache_path = origin_path.AppendASCII(cache_dir); 232 cache_path = origin_path.AppendASCII(cache_dir);
230 } while (base::PathExists(cache_path)); 233 } while (base::PathExists(cache_path));
231 234
232 return base::CreateDirectory(cache_path) ? cache_dir : ""; 235 return base::CreateDirectory(cache_path) ? cache_dir : "";
233 } 236 }
234 237
235 void PrepareNewCacheCreateCache(const std::string& cache_name, 238 void PrepareNewCacheCreateCache(const base::string16& cache_name,
236 const CacheCallback& callback, 239 const CacheCallback& callback,
237 const std::string& cache_dir) { 240 const std::string& cache_dir) {
238 if (cache_dir.empty()) { 241 if (cache_dir.empty()) {
239 callback.Run(scoped_refptr<CacheStorageCache>()); 242 callback.Run(scoped_refptr<CacheStorageCache>());
240 return; 243 return;
241 } 244 }
242 245
243 cache_name_to_cache_dir_[cache_name] = cache_dir; 246 cache_name_to_cache_dir_[cache_name] = cache_dir;
244 callback.Run(CreateCache(cache_name)); 247 callback.Run(CreateCache(cache_name));
245 } 248 }
246 249
247 void CleanUpDeletedCache(const std::string& cache_name, 250 void CleanUpDeletedCache(const base::string16& cache_name,
248 const BoolCallback& callback) override { 251 const BoolCallback& callback) override {
249 DCHECK_CURRENTLY_ON(BrowserThread::IO); 252 DCHECK_CURRENTLY_ON(BrowserThread::IO);
250 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name)); 253 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name));
251 254
252 base::FilePath cache_path = 255 base::FilePath cache_path =
253 origin_path_.AppendASCII(cache_name_to_cache_dir_[cache_name]); 256 origin_path_.AppendASCII(cache_name_to_cache_dir_[cache_name]);
254 cache_name_to_cache_dir_.erase(cache_name); 257 cache_name_to_cache_dir_.erase(cache_name);
255 258
256 cache_task_runner_->PostTask( 259 cache_task_runner_->PostTask(
257 FROM_HERE, 260 FROM_HERE,
(...skipping 16 matching lines...) Expand all
274 // 1. Create the index file as a string. (WriteIndex) 277 // 1. Create the index file as a string. (WriteIndex)
275 // 2. Write the file to disk. (WriteIndexWriteToFileInPool) 278 // 2. Write the file to disk. (WriteIndexWriteToFileInPool)
276 279
277 CacheStorageIndex index; 280 CacheStorageIndex index;
278 index.set_origin(origin_.spec()); 281 index.set_origin(origin_.spec());
279 282
280 for (size_t i = 0u, max = cache_names.size(); i < max; ++i) { 283 for (size_t i = 0u, max = cache_names.size(); i < max; ++i) {
281 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_names[i])); 284 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_names[i]));
282 285
283 CacheStorageIndex::Cache* index_cache = index.add_cache(); 286 CacheStorageIndex::Cache* index_cache = index.add_cache();
284 index_cache->set_name(cache_names[i]); 287 // We use |name_utf16| to store the cache name. But we set |name| here for
288 // forward compatibility.
289 // TODO(horo): Stop setting |name| when M51 becomes stable.
290 index_cache->set_name(base::UTF16ToUTF8(cache_names[i]));
285 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_names[i]]); 291 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_names[i]]);
292 index_cache->set_name_utf16(
293 cache_names[i].data(),
294 cache_names[i].length() * sizeof(base::char16));
286 } 295 }
287 296
288 std::string serialized; 297 std::string serialized;
289 bool success = index.SerializeToString(&serialized); 298 bool success = index.SerializeToString(&serialized);
290 DCHECK(success); 299 DCHECK(success);
291 300
292 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); 301 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp");
293 base::FilePath index_path = 302 base::FilePath index_path =
294 origin_path_.AppendASCII(CacheStorage::kIndexFileName); 303 origin_path_.AppendASCII(CacheStorage::kIndexFileName);
295 304
(...skipping 13 matching lines...) Expand all
309 if (bytes_written != base::checked_cast<int>(data.size())) { 318 if (bytes_written != base::checked_cast<int>(data.size())) {
310 base::DeleteFile(tmp_path, /* recursive */ false); 319 base::DeleteFile(tmp_path, /* recursive */ false);
311 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, false)); 320 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, false));
312 } 321 }
313 322
314 // Atomically rename the temporary index file to become the real one. 323 // Atomically rename the temporary index file to become the real one.
315 bool rv = base::ReplaceFile(tmp_path, index_path, NULL); 324 bool rv = base::ReplaceFile(tmp_path, index_path, NULL);
316 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, rv)); 325 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, rv));
317 } 326 }
318 327
319 void LoadIndex(scoped_ptr<std::vector<std::string>> names, 328 void LoadIndex(scoped_ptr<std::vector<base::string16>> names,
320 const StringVectorCallback& callback) override { 329 const StringVectorCallback& callback) override {
321 DCHECK_CURRENTLY_ON(BrowserThread::IO); 330 DCHECK_CURRENTLY_ON(BrowserThread::IO);
322 331
323 // 1. Read the file from disk. (LoadIndexReadFileInPool) 332 // 1. Read the file from disk. (LoadIndexReadFileInPool)
324 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile) 333 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile)
325 334
326 base::FilePath index_path = 335 base::FilePath index_path =
327 origin_path_.AppendASCII(CacheStorage::kIndexFileName); 336 origin_path_.AppendASCII(CacheStorage::kIndexFileName);
328 337
329 PostTaskAndReplyWithResult( 338 PostTaskAndReplyWithResult(
330 cache_task_runner_.get(), FROM_HERE, 339 cache_task_runner_.get(), FROM_HERE,
331 base::Bind(&SimpleCacheLoader::ReadAndMigrateIndexInPool, index_path), 340 base::Bind(&SimpleCacheLoader::ReadAndMigrateIndexInPool, index_path),
332 base::Bind(&SimpleCacheLoader::LoadIndexDidReadFile, 341 base::Bind(&SimpleCacheLoader::LoadIndexDidReadFile,
333 weak_ptr_factory_.GetWeakPtr(), base::Passed(&names), 342 weak_ptr_factory_.GetWeakPtr(), base::Passed(&names),
334 callback)); 343 callback));
335 } 344 }
336 345
337 void LoadIndexDidReadFile(scoped_ptr<std::vector<std::string>> names, 346 void LoadIndexDidReadFile(scoped_ptr<std::vector<base::string16>> names,
338 const StringVectorCallback& callback, 347 const StringVectorCallback& callback,
339 const std::string& serialized) { 348 const std::string& serialized) {
340 DCHECK_CURRENTLY_ON(BrowserThread::IO); 349 DCHECK_CURRENTLY_ON(BrowserThread::IO);
341 350
342 scoped_ptr<std::set<std::string>> cache_dirs(new std::set<std::string>); 351 scoped_ptr<std::set<std::string>> cache_dirs(new std::set<std::string>);
343 352
344 CacheStorageIndex index; 353 CacheStorageIndex index;
345 if (index.ParseFromString(serialized)) { 354 if (index.ParseFromString(serialized)) {
346 for (int i = 0, max = index.cache_size(); i < max; ++i) { 355 for (int i = 0, max = index.cache_size(); i < max; ++i) {
347 const CacheStorageIndex::Cache& cache = index.cache(i); 356 const CacheStorageIndex::Cache& cache = index.cache(i);
348 DCHECK(cache.has_cache_dir()); 357 DCHECK(cache.has_cache_dir());
349 names->push_back(cache.name()); 358 // After M51 we use |name_utf16| instead of |name|. We check |name|
350 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir(); 359 // first for backward compatibility.
360 base::string16 cache_name(base::UTF8ToUTF16(cache.name()));
361 if (cache.has_name_utf16()) {
362 cache_name = base::string16(
363 reinterpret_cast<const base::char16*>(cache.name_utf16().data()),
364 cache.name_utf16().size() / sizeof(base::char16));
365 }
366 names->push_back(cache_name);
367 cache_name_to_cache_dir_[cache_name] = cache.cache_dir();
351 cache_dirs->insert(cache.cache_dir()); 368 cache_dirs->insert(cache.cache_dir());
352 } 369 }
353 } 370 }
354 371
355 cache_task_runner_->PostTask( 372 cache_task_runner_->PostTask(
356 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_, 373 FROM_HERE, base::Bind(&DeleteUnreferencedCachesInPool, origin_path_,
357 base::Passed(&cache_dirs))); 374 base::Passed(&cache_dirs)));
358 callback.Run(std::move(names)); 375 callback.Run(std::move(names));
359 } 376 }
360 377
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // Runs on cache_task_runner_ 452 // Runs on cache_task_runner_
436 static std::string ReadAndMigrateIndexInPool( 453 static std::string ReadAndMigrateIndexInPool(
437 const base::FilePath& index_path) { 454 const base::FilePath& index_path) {
438 std::string body; 455 std::string body;
439 base::ReadFileToString(index_path, &body); 456 base::ReadFileToString(index_path, &body);
440 457
441 return MigrateCachesIfNecessaryInPool(body, index_path); 458 return MigrateCachesIfNecessaryInPool(body, index_path);
442 } 459 }
443 460
444 const base::FilePath origin_path_; 461 const base::FilePath origin_path_;
445 std::map<std::string, std::string> cache_name_to_cache_dir_; 462 std::map<base::string16, std::string> cache_name_to_cache_dir_;
446 463
447 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_; 464 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_;
448 }; 465 };
449 466
450 CacheStorage::CacheStorage( 467 CacheStorage::CacheStorage(
451 const base::FilePath& path, 468 const base::FilePath& path,
452 bool memory_only, 469 bool memory_only,
453 base::SequencedTaskRunner* cache_task_runner, 470 base::SequencedTaskRunner* cache_task_runner,
454 const scoped_refptr<net::URLRequestContextGetter>& request_context, 471 const scoped_refptr<net::URLRequestContextGetter>& request_context,
455 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 472 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
(...skipping 14 matching lines...) Expand all
470 blob_context, origin)); 487 blob_context, origin));
471 else 488 else
472 cache_loader_.reset(new SimpleCacheLoader( 489 cache_loader_.reset(new SimpleCacheLoader(
473 origin_path_, cache_task_runner_.get(), request_context, 490 origin_path_, cache_task_runner_.get(), request_context,
474 quota_manager_proxy, blob_context, origin)); 491 quota_manager_proxy, blob_context, origin));
475 } 492 }
476 493
477 CacheStorage::~CacheStorage() { 494 CacheStorage::~CacheStorage() {
478 } 495 }
479 496
480 void CacheStorage::OpenCache(const std::string& cache_name, 497 void CacheStorage::OpenCache(const base::string16& cache_name,
481 const CacheAndErrorCallback& callback) { 498 const CacheAndErrorCallback& callback) {
482 DCHECK_CURRENTLY_ON(BrowserThread::IO); 499 DCHECK_CURRENTLY_ON(BrowserThread::IO);
483 500
484 if (!initialized_) 501 if (!initialized_)
485 LazyInit(); 502 LazyInit();
486 503
487 CacheAndErrorCallback pending_callback = 504 CacheAndErrorCallback pending_callback =
488 base::Bind(&CacheStorage::PendingCacheAndErrorCallback, 505 base::Bind(&CacheStorage::PendingCacheAndErrorCallback,
489 weak_factory_.GetWeakPtr(), callback); 506 weak_factory_.GetWeakPtr(), callback);
490 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::OpenCacheImpl, 507 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::OpenCacheImpl,
491 weak_factory_.GetWeakPtr(), 508 weak_factory_.GetWeakPtr(),
492 cache_name, pending_callback)); 509 cache_name, pending_callback));
493 } 510 }
494 511
495 void CacheStorage::HasCache(const std::string& cache_name, 512 void CacheStorage::HasCache(const base::string16& cache_name,
496 const BoolAndErrorCallback& callback) { 513 const BoolAndErrorCallback& callback) {
497 DCHECK_CURRENTLY_ON(BrowserThread::IO); 514 DCHECK_CURRENTLY_ON(BrowserThread::IO);
498 515
499 if (!initialized_) 516 if (!initialized_)
500 LazyInit(); 517 LazyInit();
501 518
502 BoolAndErrorCallback pending_callback = 519 BoolAndErrorCallback pending_callback =
503 base::Bind(&CacheStorage::PendingBoolAndErrorCallback, 520 base::Bind(&CacheStorage::PendingBoolAndErrorCallback,
504 weak_factory_.GetWeakPtr(), callback); 521 weak_factory_.GetWeakPtr(), callback);
505 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::HasCacheImpl, 522 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::HasCacheImpl,
506 weak_factory_.GetWeakPtr(), 523 weak_factory_.GetWeakPtr(),
507 cache_name, pending_callback)); 524 cache_name, pending_callback));
508 } 525 }
509 526
510 void CacheStorage::DeleteCache(const std::string& cache_name, 527 void CacheStorage::DeleteCache(const base::string16& cache_name,
511 const BoolAndErrorCallback& callback) { 528 const BoolAndErrorCallback& callback) {
512 DCHECK_CURRENTLY_ON(BrowserThread::IO); 529 DCHECK_CURRENTLY_ON(BrowserThread::IO);
513 530
514 if (!initialized_) 531 if (!initialized_)
515 LazyInit(); 532 LazyInit();
516 533
517 BoolAndErrorCallback pending_callback = 534 BoolAndErrorCallback pending_callback =
518 base::Bind(&CacheStorage::PendingBoolAndErrorCallback, 535 base::Bind(&CacheStorage::PendingBoolAndErrorCallback,
519 weak_factory_.GetWeakPtr(), callback); 536 weak_factory_.GetWeakPtr(), callback);
520 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::DeleteCacheImpl, 537 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::DeleteCacheImpl,
521 weak_factory_.GetWeakPtr(), 538 weak_factory_.GetWeakPtr(),
522 cache_name, pending_callback)); 539 cache_name, pending_callback));
523 } 540 }
524 541
525 void CacheStorage::EnumerateCaches(const StringsAndErrorCallback& callback) { 542 void CacheStorage::EnumerateCaches(const StringsAndErrorCallback& callback) {
526 DCHECK_CURRENTLY_ON(BrowserThread::IO); 543 DCHECK_CURRENTLY_ON(BrowserThread::IO);
527 544
528 if (!initialized_) 545 if (!initialized_)
529 LazyInit(); 546 LazyInit();
530 547
531 StringsAndErrorCallback pending_callback = 548 StringsAndErrorCallback pending_callback =
532 base::Bind(&CacheStorage::PendingStringsAndErrorCallback, 549 base::Bind(&CacheStorage::PendingStringsAndErrorCallback,
533 weak_factory_.GetWeakPtr(), callback); 550 weak_factory_.GetWeakPtr(), callback);
534 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::EnumerateCachesImpl, 551 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::EnumerateCachesImpl,
535 weak_factory_.GetWeakPtr(), 552 weak_factory_.GetWeakPtr(),
536 pending_callback)); 553 pending_callback));
537 } 554 }
538 555
539 void CacheStorage::MatchCache( 556 void CacheStorage::MatchCache(
540 const std::string& cache_name, 557 const base::string16& cache_name,
541 scoped_ptr<ServiceWorkerFetchRequest> request, 558 scoped_ptr<ServiceWorkerFetchRequest> request,
542 const CacheStorageCache::ResponseCallback& callback) { 559 const CacheStorageCache::ResponseCallback& callback) {
543 DCHECK_CURRENTLY_ON(BrowserThread::IO); 560 DCHECK_CURRENTLY_ON(BrowserThread::IO);
544 561
545 if (!initialized_) 562 if (!initialized_)
546 LazyInit(); 563 LazyInit();
547 564
548 CacheStorageCache::ResponseCallback pending_callback = 565 CacheStorageCache::ResponseCallback pending_callback =
549 base::Bind(&CacheStorage::PendingResponseCallback, 566 base::Bind(&CacheStorage::PendingResponseCallback,
550 weak_factory_.GetWeakPtr(), callback); 567 weak_factory_.GetWeakPtr(), callback);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 void CacheStorage::LazyInitImpl() { 639 void CacheStorage::LazyInitImpl() {
623 DCHECK_CURRENTLY_ON(BrowserThread::IO); 640 DCHECK_CURRENTLY_ON(BrowserThread::IO);
624 DCHECK(!initialized_); 641 DCHECK(!initialized_);
625 DCHECK(initializing_); 642 DCHECK(initializing_);
626 643
627 // 1. Get the list of cache names (async call) 644 // 1. Get the list of cache names (async call)
628 // 2. For each cache name, load the cache (async call) 645 // 2. For each cache name, load the cache (async call)
629 // 3. Once each load is complete, update the map variables. 646 // 3. Once each load is complete, update the map variables.
630 // 4. Call the list of waiting callbacks. 647 // 4. Call the list of waiting callbacks.
631 648
632 scoped_ptr<std::vector<std::string>> indexed_cache_names( 649 scoped_ptr<std::vector<base::string16>> indexed_cache_names(
633 new std::vector<std::string>()); 650 new std::vector<base::string16>());
634 651
635 cache_loader_->LoadIndex(std::move(indexed_cache_names), 652 cache_loader_->LoadIndex(std::move(indexed_cache_names),
636 base::Bind(&CacheStorage::LazyInitDidLoadIndex, 653 base::Bind(&CacheStorage::LazyInitDidLoadIndex,
637 weak_factory_.GetWeakPtr())); 654 weak_factory_.GetWeakPtr()));
638 } 655 }
639 656
640 void CacheStorage::LazyInitDidLoadIndex( 657 void CacheStorage::LazyInitDidLoadIndex(
641 scoped_ptr<std::vector<std::string>> indexed_cache_names) { 658 scoped_ptr<std::vector<base::string16>> indexed_cache_names) {
642 DCHECK_CURRENTLY_ON(BrowserThread::IO); 659 DCHECK_CURRENTLY_ON(BrowserThread::IO);
643 660
644 for (size_t i = 0u, max = indexed_cache_names->size(); i < max; ++i) { 661 for (size_t i = 0u, max = indexed_cache_names->size(); i < max; ++i) {
645 cache_map_.insert(std::make_pair(indexed_cache_names->at(i), 662 cache_map_.insert(std::make_pair(indexed_cache_names->at(i),
646 base::WeakPtr<CacheStorageCache>())); 663 base::WeakPtr<CacheStorageCache>()));
647 ordered_cache_names_.push_back(indexed_cache_names->at(i)); 664 ordered_cache_names_.push_back(indexed_cache_names->at(i));
648 } 665 }
649 666
650 initializing_ = false; 667 initializing_ = false;
651 initialized_ = true; 668 initialized_ = true;
652 669
653 scheduler_->CompleteOperationAndRunNext(); 670 scheduler_->CompleteOperationAndRunNext();
654 } 671 }
655 672
656 void CacheStorage::OpenCacheImpl(const std::string& cache_name, 673 void CacheStorage::OpenCacheImpl(const base::string16& cache_name,
657 const CacheAndErrorCallback& callback) { 674 const CacheAndErrorCallback& callback) {
658 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 675 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
659 if (cache.get()) { 676 if (cache.get()) {
660 callback.Run(cache, CACHE_STORAGE_OK); 677 callback.Run(cache, CACHE_STORAGE_OK);
661 return; 678 return;
662 } 679 }
663 680
664 cache_loader_->PrepareNewCacheDestination( 681 cache_loader_->PrepareNewCacheDestination(
665 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, 682 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache,
666 weak_factory_.GetWeakPtr(), cache_name, callback)); 683 weak_factory_.GetWeakPtr(), cache_name, callback));
667 } 684 }
668 685
669 void CacheStorage::CreateCacheDidCreateCache( 686 void CacheStorage::CreateCacheDidCreateCache(
670 const std::string& cache_name, 687 const base::string16& cache_name,
671 const CacheAndErrorCallback& callback, 688 const CacheAndErrorCallback& callback,
672 const scoped_refptr<CacheStorageCache>& cache) { 689 const scoped_refptr<CacheStorageCache>& cache) {
673 DCHECK_CURRENTLY_ON(BrowserThread::IO); 690 DCHECK_CURRENTLY_ON(BrowserThread::IO);
674 691
675 UMA_HISTOGRAM_BOOLEAN("ServiceWorkerCache.CreateCacheStorageResult", 692 UMA_HISTOGRAM_BOOLEAN("ServiceWorkerCache.CreateCacheStorageResult",
676 cache != nullptr); 693 cache != nullptr);
677 694
678 if (!cache.get()) { 695 if (!cache.get()) {
679 callback.Run(scoped_refptr<CacheStorageCache>(), 696 callback.Run(scoped_refptr<CacheStorageCache>(),
680 CACHE_STORAGE_ERROR_STORAGE); 697 CACHE_STORAGE_ERROR_STORAGE);
(...skipping 16 matching lines...) Expand all
697 const scoped_refptr<CacheStorageCache>& cache, 714 const scoped_refptr<CacheStorageCache>& cache,
698 bool success) { 715 bool success) {
699 DCHECK_CURRENTLY_ON(BrowserThread::IO); 716 DCHECK_CURRENTLY_ON(BrowserThread::IO);
700 DCHECK(cache.get()); 717 DCHECK(cache.get());
701 718
702 // TODO(jkarlin): Handle !success. 719 // TODO(jkarlin): Handle !success.
703 720
704 callback.Run(cache, CACHE_STORAGE_OK); 721 callback.Run(cache, CACHE_STORAGE_OK);
705 } 722 }
706 723
707 void CacheStorage::HasCacheImpl(const std::string& cache_name, 724 void CacheStorage::HasCacheImpl(const base::string16& cache_name,
708 const BoolAndErrorCallback& callback) { 725 const BoolAndErrorCallback& callback) {
709 bool has_cache = ContainsKey(cache_map_, cache_name); 726 bool has_cache = ContainsKey(cache_map_, cache_name);
710 callback.Run(has_cache, CACHE_STORAGE_OK); 727 callback.Run(has_cache, CACHE_STORAGE_OK);
711 } 728 }
712 729
713 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, 730 void CacheStorage::DeleteCacheImpl(const base::string16& cache_name,
714 const BoolAndErrorCallback& callback) { 731 const BoolAndErrorCallback& callback) {
715 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 732 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
716 if (!cache.get()) { 733 if (!cache.get()) {
717 base::ThreadTaskRunnerHandle::Get()->PostTask( 734 base::ThreadTaskRunnerHandle::Get()->PostTask(
718 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); 735 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND));
719 return; 736 return;
720 } 737 }
721 738
722 CacheMap::iterator map_iter = cache_map_.find(cache_name); 739 CacheMap::iterator map_iter = cache_map_.find(cache_name);
723 cache_map_.erase(map_iter); 740 cache_map_.erase(map_iter);
724 741
725 // Delete the name from ordered_cache_names_. 742 // Delete the name from ordered_cache_names_.
726 StringVector::iterator iter = std::find( 743 StringVector::iterator iter = std::find(
727 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name); 744 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name);
728 DCHECK(iter != ordered_cache_names_.end()); 745 DCHECK(iter != ordered_cache_names_.end());
729 ordered_cache_names_.erase(iter); 746 ordered_cache_names_.erase(iter);
730 747
731 cache->GetSizeThenClose(base::Bind(&CacheStorage::DeleteCacheDidClose, 748 cache->GetSizeThenClose(base::Bind(&CacheStorage::DeleteCacheDidClose,
732 weak_factory_.GetWeakPtr(), cache_name, 749 weak_factory_.GetWeakPtr(), cache_name,
733 callback, ordered_cache_names_, cache)); 750 callback, ordered_cache_names_, cache));
734 } 751 }
735 752
736 void CacheStorage::DeleteCacheDidClose( 753 void CacheStorage::DeleteCacheDidClose(
737 const std::string& cache_name, 754 const base::string16& cache_name,
738 const BoolAndErrorCallback& callback, 755 const BoolAndErrorCallback& callback,
739 const StringVector& ordered_cache_names, 756 const StringVector& ordered_cache_names,
740 const scoped_refptr<CacheStorageCache>& cache, 757 const scoped_refptr<CacheStorageCache>& cache,
741 int64_t cache_size) { 758 int64_t cache_size) {
742 cache_loader_->WriteIndex( 759 cache_loader_->WriteIndex(
743 ordered_cache_names, 760 ordered_cache_names,
744 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, 761 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex,
745 weak_factory_.GetWeakPtr(), cache_name, callback, cache_size)); 762 weak_factory_.GetWeakPtr(), cache_name, callback, cache_size));
746 } 763 }
747 764
748 void CacheStorage::DeleteCacheDidWriteIndex( 765 void CacheStorage::DeleteCacheDidWriteIndex(
749 const std::string& cache_name, 766 const base::string16& cache_name,
750 const BoolAndErrorCallback& callback, 767 const BoolAndErrorCallback& callback,
751 int cache_size, 768 int cache_size,
752 bool success) { 769 bool success) {
753 DCHECK_CURRENTLY_ON(BrowserThread::IO); 770 DCHECK_CURRENTLY_ON(BrowserThread::IO);
754 771
755 quota_manager_proxy_->NotifyStorageModified( 772 quota_manager_proxy_->NotifyStorageModified(
756 storage::QuotaClient::kServiceWorkerCache, origin_, 773 storage::QuotaClient::kServiceWorkerCache, origin_,
757 storage::kStorageTypeTemporary, -1 * cache_size); 774 storage::kStorageTypeTemporary, -1 * cache_size);
758 775
759 cache_loader_->CleanUpDeletedCache( 776 cache_loader_->CleanUpDeletedCache(
760 cache_name, base::Bind(&CacheStorage::DeleteCacheDidCleanUp, 777 cache_name, base::Bind(&CacheStorage::DeleteCacheDidCleanUp,
761 weak_factory_.GetWeakPtr(), callback)); 778 weak_factory_.GetWeakPtr(), callback));
762 } 779 }
763 780
764 void CacheStorage::DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, 781 void CacheStorage::DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback,
765 bool success) { 782 bool success) {
766 DCHECK_CURRENTLY_ON(BrowserThread::IO); 783 DCHECK_CURRENTLY_ON(BrowserThread::IO);
767 784
768 callback.Run(true, CACHE_STORAGE_OK); 785 callback.Run(true, CACHE_STORAGE_OK);
769 } 786 }
770 787
771 void CacheStorage::EnumerateCachesImpl( 788 void CacheStorage::EnumerateCachesImpl(
772 const StringsAndErrorCallback& callback) { 789 const StringsAndErrorCallback& callback) {
773 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); 790 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK);
774 } 791 }
775 792
776 void CacheStorage::MatchCacheImpl( 793 void CacheStorage::MatchCacheImpl(
777 const std::string& cache_name, 794 const base::string16& cache_name,
778 scoped_ptr<ServiceWorkerFetchRequest> request, 795 scoped_ptr<ServiceWorkerFetchRequest> request,
779 const CacheStorageCache::ResponseCallback& callback) { 796 const CacheStorageCache::ResponseCallback& callback) {
780 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 797 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
781 798
782 if (!cache.get()) { 799 if (!cache.get()) {
783 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND, 800 callback.Run(CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND,
784 scoped_ptr<ServiceWorkerResponse>(), 801 scoped_ptr<ServiceWorkerResponse>(),
785 scoped_ptr<storage::BlobDataHandle>()); 802 scoped_ptr<storage::BlobDataHandle>());
786 return; 803 return;
787 } 804 }
(...skipping 20 matching lines...) Expand all
808 scoped_ptr<CacheStorageCache::ResponseCallback> callback_copy( 825 scoped_ptr<CacheStorageCache::ResponseCallback> callback_copy(
809 new CacheStorageCache::ResponseCallback(callback)); 826 new CacheStorageCache::ResponseCallback(callback));
810 827
811 CacheStorageCache::ResponseCallback* callback_ptr = callback_copy.get(); 828 CacheStorageCache::ResponseCallback* callback_ptr = callback_copy.get();
812 base::Closure barrier_closure = 829 base::Closure barrier_closure =
813 base::BarrierClosure(ordered_cache_names_.size(), 830 base::BarrierClosure(ordered_cache_names_.size(),
814 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll, 831 base::Bind(&CacheStorage::MatchAllCachesDidMatchAll,
815 weak_factory_.GetWeakPtr(), 832 weak_factory_.GetWeakPtr(),
816 base::Passed(std::move(callback_copy)))); 833 base::Passed(std::move(callback_copy))));
817 834
818 for (const std::string& cache_name : ordered_cache_names_) { 835 for (const base::string16& cache_name : ordered_cache_names_) {
819 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 836 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
820 DCHECK(cache.get()); 837 DCHECK(cache.get());
821 838
822 cache->Match(make_scoped_ptr(new ServiceWorkerFetchRequest(*request)), 839 cache->Match(make_scoped_ptr(new ServiceWorkerFetchRequest(*request)),
823 base::Bind(&CacheStorage::MatchAllCachesDidMatch, 840 base::Bind(&CacheStorage::MatchAllCachesDidMatch,
824 weak_factory_.GetWeakPtr(), cache, barrier_closure, 841 weak_factory_.GetWeakPtr(), cache, barrier_closure,
825 callback_ptr)); 842 callback_ptr));
826 } 843 }
827 } 844 }
828 845
(...skipping 17 matching lines...) Expand all
846 void CacheStorage::MatchAllCachesDidMatchAll( 863 void CacheStorage::MatchAllCachesDidMatchAll(
847 scoped_ptr<CacheStorageCache::ResponseCallback> callback) { 864 scoped_ptr<CacheStorageCache::ResponseCallback> callback) {
848 if (!callback->is_null()) { 865 if (!callback->is_null()) {
849 callback->Run(CACHE_STORAGE_ERROR_NOT_FOUND, 866 callback->Run(CACHE_STORAGE_ERROR_NOT_FOUND,
850 scoped_ptr<ServiceWorkerResponse>(), 867 scoped_ptr<ServiceWorkerResponse>(),
851 scoped_ptr<storage::BlobDataHandle>()); 868 scoped_ptr<storage::BlobDataHandle>());
852 } 869 }
853 } 870 }
854 871
855 scoped_refptr<CacheStorageCache> CacheStorage::GetLoadedCache( 872 scoped_refptr<CacheStorageCache> CacheStorage::GetLoadedCache(
856 const std::string& cache_name) { 873 const base::string16& cache_name) {
857 DCHECK_CURRENTLY_ON(BrowserThread::IO); 874 DCHECK_CURRENTLY_ON(BrowserThread::IO);
858 DCHECK(initialized_); 875 DCHECK(initialized_);
859 876
860 CacheMap::iterator map_iter = cache_map_.find(cache_name); 877 CacheMap::iterator map_iter = cache_map_.find(cache_name);
861 if (map_iter == cache_map_.end()) 878 if (map_iter == cache_map_.end())
862 return scoped_refptr<CacheStorageCache>(); 879 return scoped_refptr<CacheStorageCache>();
863 880
864 base::WeakPtr<CacheStorageCache> cache = map_iter->second; 881 base::WeakPtr<CacheStorageCache> cache = map_iter->second;
865 882
866 if (!cache) { 883 if (!cache) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 DCHECK(initialized_); 924 DCHECK(initialized_);
908 925
909 scoped_ptr<int64_t> accumulator(new int64_t(0)); 926 scoped_ptr<int64_t> accumulator(new int64_t(0));
910 int64_t* accumulator_ptr = accumulator.get(); 927 int64_t* accumulator_ptr = accumulator.get();
911 928
912 base::Closure barrier_closure = base::BarrierClosure( 929 base::Closure barrier_closure = base::BarrierClosure(
913 ordered_cache_names_.size(), 930 ordered_cache_names_.size(),
914 base::Bind(&SizeRetrievedFromAllCaches, 931 base::Bind(&SizeRetrievedFromAllCaches,
915 base::Passed(std::move(accumulator)), callback)); 932 base::Passed(std::move(accumulator)), callback));
916 933
917 for (const std::string& cache_name : ordered_cache_names_) { 934 for (const base::string16& cache_name : ordered_cache_names_) {
918 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 935 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
919 cache->GetSizeThenClose(base::Bind(&SizeRetrievedFromCache, cache, 936 cache->GetSizeThenClose(base::Bind(&SizeRetrievedFromCache, cache,
920 barrier_closure, accumulator_ptr)); 937 barrier_closure, accumulator_ptr));
921 } 938 }
922 } 939 }
923 940
924 void CacheStorage::SizeImpl(const SizeCallback& callback) { 941 void CacheStorage::SizeImpl(const SizeCallback& callback) {
925 DCHECK_CURRENTLY_ON(BrowserThread::IO); 942 DCHECK_CURRENTLY_ON(BrowserThread::IO);
926 DCHECK(initialized_); 943 DCHECK(initialized_);
927 944
928 scoped_ptr<int64_t> accumulator(new int64_t(0)); 945 scoped_ptr<int64_t> accumulator(new int64_t(0));
929 int64_t* accumulator_ptr = accumulator.get(); 946 int64_t* accumulator_ptr = accumulator.get();
930 947
931 base::Closure barrier_closure = base::BarrierClosure( 948 base::Closure barrier_closure = base::BarrierClosure(
932 ordered_cache_names_.size(), 949 ordered_cache_names_.size(),
933 base::Bind(&SizeRetrievedFromAllCaches, 950 base::Bind(&SizeRetrievedFromAllCaches,
934 base::Passed(std::move(accumulator)), callback)); 951 base::Passed(std::move(accumulator)), callback));
935 952
936 for (const std::string& cache_name : ordered_cache_names_) { 953 for (const base::string16& cache_name : ordered_cache_names_) {
937 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 954 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
938 cache->Size(base::Bind(&SizeRetrievedFromCache, cache, barrier_closure, 955 cache->Size(base::Bind(&SizeRetrievedFromCache, cache, barrier_closure,
939 accumulator_ptr)); 956 accumulator_ptr));
940 } 957 }
941 } 958 }
942 959
943 void CacheStorage::PendingClosure(const base::Closure& callback) { 960 void CacheStorage::PendingClosure(const base::Closure& callback) {
944 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); 961 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr();
945 962
946 callback.Run(); 963 callback.Run();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 void CacheStorage::PendingSizeCallback(const SizeCallback& callback, 1013 void CacheStorage::PendingSizeCallback(const SizeCallback& callback,
997 int64_t size) { 1014 int64_t size) {
998 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); 1015 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr();
999 1016
1000 callback.Run(size); 1017 callback.Run(size);
1001 if (cache_storage) 1018 if (cache_storage)
1002 scheduler_->CompleteOperationAndRunNext(); 1019 scheduler_->CompleteOperationAndRunNext();
1003 } 1020 }
1004 1021
1005 } // namespace content 1022 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage.h ('k') | content/browser/cache_storage/cache_storage.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698