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

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

Issue 1414033002: [CacheStorage] Give cache directories unique names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 5 years, 1 month 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 <string> 7 #include <string>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/memory_mapped_file.h" 11 #include "base/files/memory_mapped_file.h"
12 #include "base/guid.h"
12 #include "base/location.h" 13 #include "base/location.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
15 #include "base/numerics/safe_conversions.h" 16 #include "base/numerics/safe_conversions.h"
16 #include "base/sha1.h" 17 #include "base/sha1.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
22 #include "content/browser/cache_storage/cache_storage.pb.h" 23 #include "content/browser/cache_storage/cache_storage.pb.h"
23 #include "content/browser/cache_storage/cache_storage_cache.h" 24 #include "content/browser/cache_storage/cache_storage_cache.h"
24 #include "content/browser/cache_storage/cache_storage_scheduler.h" 25 #include "content/browser/cache_storage/cache_storage_scheduler.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "net/base/directory_lister.h" 27 #include "net/base/directory_lister.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 #include "net/url_request/url_request_context_getter.h" 29 #include "net/url_request/url_request_context_getter.h"
29 #include "storage/browser/blob/blob_storage_context.h" 30 #include "storage/browser/blob/blob_storage_context.h"
30 #include "storage/browser/quota/quota_manager_proxy.h" 31 #include "storage/browser/quota/quota_manager_proxy.h"
31 32
32 namespace content { 33 namespace content {
33 34
34 namespace { 35 namespace {
35 36
37 std::string HexedHash(const std::string& value) {
38 std::string value_hash = base::SHA1HashString(value);
39 std::string valued_hexed_hash = base::ToLowerASCII(
40 base::HexEncode(value_hash.c_str(), value_hash.length()));
41 return valued_hexed_hash;
42 }
43
36 void CloseAllCachesDidCloseCache(const scoped_refptr<CacheStorageCache>& cache, 44 void CloseAllCachesDidCloseCache(const scoped_refptr<CacheStorageCache>& cache,
37 const base::Closure& barrier_closure) { 45 const base::Closure& barrier_closure) {
38 barrier_closure.Run(); 46 barrier_closure.Run();
39 } 47 }
40 48
41 } // namespace 49 } // namespace
42 50
51 class MigratedLegacyCacheDirectoryNameTest;
jsbell 2015/10/23 21:09:59 Is this actually needed? (forward decls for friend
jkarlin 2015/10/23 22:57:41 Done.
52
43 const char CacheStorage::kIndexFileName[] = "index.txt"; 53 const char CacheStorage::kIndexFileName[] = "index.txt";
44 54
45 // Handles the loading and clean up of CacheStorageCache objects. The 55 // Handles the loading and clean up of CacheStorageCache objects.
46 // callback of every public method is guaranteed to be called.
47 class CacheStorage::CacheLoader { 56 class CacheStorage::CacheLoader {
48 public: 57 public:
49 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&)> 58 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&)>
50 CacheCallback; 59 CacheCallback;
51 typedef base::Callback<void(bool)> BoolCallback; 60 typedef base::Callback<void(bool)> BoolCallback;
52 typedef base::Callback<void(scoped_ptr<std::vector<std::string>>)> 61 typedef base::Callback<void(scoped_ptr<std::vector<std::string>>)>
53 StringVectorCallback; 62 StringVectorCallback;
54 63
55 CacheLoader( 64 CacheLoader(
56 base::SequencedTaskRunner* cache_task_runner, 65 base::SequencedTaskRunner* cache_task_runner,
(...skipping 10 matching lines...) Expand all
67 } 76 }
68 77
69 virtual ~CacheLoader() {} 78 virtual ~CacheLoader() {}
70 79
71 // Creates a CacheStorageCache with the given name. It does not attempt to 80 // Creates a CacheStorageCache with the given name. It does not attempt to
72 // load the backend, that happens lazily when the cache is used. 81 // load the backend, that happens lazily when the cache is used.
73 virtual scoped_refptr<CacheStorageCache> CreateCache( 82 virtual scoped_refptr<CacheStorageCache> CreateCache(
74 const std::string& cache_name) = 0; 83 const std::string& cache_name) = 0;
75 84
76 // Deletes any pre-existing cache of the same name and then loads it. 85 // Deletes any pre-existing cache of the same name and then loads it.
77 virtual void CreateCache(const std::string& cache_name, 86 virtual void PrepareNewCacheDestination(const std::string& cache_name,
78 const CacheCallback& callback) = 0; 87 const CacheCallback& callback) = 0;
79 88
80 // After the backend has been deleted, do any extra house keeping such as 89 // After the backend has been deleted, do any extra house keeping such as
81 // removing the cache's directory. 90 // removing the cache's directory.
82 virtual void CleanUpDeletedCache(const std::string& key, 91 virtual void CleanUpDeletedCache(const std::string& key,
83 const BoolCallback& callback) = 0; 92 const BoolCallback& callback) = 0;
84 93
85 // Writes the cache names (and sizes) to disk if applicable. 94 // Writes the cache names (and sizes) to disk if applicable.
86 virtual void WriteIndex(const StringVector& cache_names, 95 virtual void WriteIndex(const StringVector& cache_names,
87 const BoolCallback& callback) = 0; 96 const BoolCallback& callback) = 0;
88 97
(...skipping 26 matching lines...) Expand all
115 quota_manager_proxy, 124 quota_manager_proxy,
116 blob_context, 125 blob_context,
117 origin) {} 126 origin) {}
118 127
119 scoped_refptr<CacheStorageCache> CreateCache( 128 scoped_refptr<CacheStorageCache> CreateCache(
120 const std::string& cache_name) override { 129 const std::string& cache_name) override {
121 return CacheStorageCache::CreateMemoryCache( 130 return CacheStorageCache::CreateMemoryCache(
122 origin_, request_context_getter_, quota_manager_proxy_, blob_context_); 131 origin_, request_context_getter_, quota_manager_proxy_, blob_context_);
123 } 132 }
124 133
125 void CreateCache(const std::string& cache_name, 134 void PrepareNewCacheDestination(const std::string& cache_name,
126 const CacheCallback& callback) override { 135 const CacheCallback& callback) override {
127 scoped_refptr<CacheStorageCache> cache = CreateCache(cache_name); 136 scoped_refptr<CacheStorageCache> cache = CreateCache(cache_name);
128 cache_refs_.insert(std::make_pair(cache_name, cache)); 137 cache_refs_.insert(std::make_pair(cache_name, cache));
129 callback.Run(cache); 138 callback.Run(cache);
130 } 139 }
131 140
132 void CleanUpDeletedCache(const std::string& cache_name, 141 void CleanUpDeletedCache(const std::string& cache_name,
133 const BoolCallback& callback) override { 142 const BoolCallback& callback) override {
134 CacheRefMap::iterator it = cache_refs_.find(cache_name); 143 CacheRefMap::iterator it = cache_refs_.find(cache_name);
135 DCHECK(it != cache_refs_.end()); 144 DCHECK(it != cache_refs_.end());
136 cache_refs_.erase(it); 145 cache_refs_.erase(it);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 request_context, 179 request_context,
171 quota_manager_proxy, 180 quota_manager_proxy,
172 blob_context, 181 blob_context,
173 origin), 182 origin),
174 origin_path_(origin_path), 183 origin_path_(origin_path),
175 weak_ptr_factory_(this) {} 184 weak_ptr_factory_(this) {}
176 185
177 scoped_refptr<CacheStorageCache> CreateCache( 186 scoped_refptr<CacheStorageCache> CreateCache(
178 const std::string& cache_name) override { 187 const std::string& cache_name) override {
179 DCHECK_CURRENTLY_ON(BrowserThread::IO); 188 DCHECK_CURRENTLY_ON(BrowserThread::IO);
189 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name));
180 190
191 std::string cache_dir = cache_name_to_cache_dir_[cache_name];
192 base::FilePath cache_path = origin_path_.AppendASCII(cache_dir);
181 return CacheStorageCache::CreatePersistentCache( 193 return CacheStorageCache::CreatePersistentCache(
182 origin_, CreatePersistentCachePath(origin_path_, cache_name), 194 origin_, cache_path, request_context_getter_, quota_manager_proxy_,
183 request_context_getter_, quota_manager_proxy_, blob_context_); 195 blob_context_);
184 } 196 }
185 197
186 void CreateCache(const std::string& cache_name, 198 void PrepareNewCacheDestination(const std::string& cache_name,
187 const CacheCallback& callback) override { 199 const CacheCallback& callback) override {
188 DCHECK_CURRENTLY_ON(BrowserThread::IO); 200 DCHECK_CURRENTLY_ON(BrowserThread::IO);
189 201
190 // 1. Delete the cache's directory if it exists.
191 // (CreateCacheDeleteFilesInPool)
192 // 2. Load the cache. (LoadCreateDirectoryInPool)
193
194 base::FilePath cache_path =
195 CreatePersistentCachePath(origin_path_, cache_name);
196
197 PostTaskAndReplyWithResult( 202 PostTaskAndReplyWithResult(
198 cache_task_runner_.get(), FROM_HERE, 203 cache_task_runner_.get(), FROM_HERE,
199 base::Bind(&SimpleCacheLoader::CreateCachePrepDirInPool, cache_path), 204 base::Bind(&SimpleCacheLoader::PrepareNewCacheDirectoryInPool,
200 base::Bind(&SimpleCacheLoader::CreateCachePreppedDir, cache_name, 205 origin_path_),
201 callback, weak_ptr_factory_.GetWeakPtr())); 206 base::Bind(&SimpleCacheLoader::PrepareNewCacheCreateCache,
207 weak_ptr_factory_.GetWeakPtr(), cache_name, callback));
202 } 208 }
203 209
204 static bool CreateCachePrepDirInPool(const base::FilePath& cache_path) { 210 // Runs on the cache_task_runner_.
205 if (base::PathExists(cache_path)) 211 static std::string PrepareNewCacheDirectoryInPool(
206 base::DeleteFile(cache_path, /* recursive */ true); 212 const base::FilePath& origin_path) {
207 return base::CreateDirectory(cache_path); 213 std::string cache_dir;
214 base::FilePath cache_path;
215 do {
216 cache_dir = base::GenerateGUID();
217 cache_path = origin_path.AppendASCII(cache_dir);
218 } while (base::PathExists(cache_path));
219
220 return base::CreateDirectory(cache_path) ? cache_dir : "";
208 } 221 }
209 222
210 static void CreateCachePreppedDir(const std::string& cache_name, 223 void PrepareNewCacheCreateCache(const std::string& cache_name,
211 const CacheCallback& callback, 224 const CacheCallback& callback,
212 base::WeakPtr<SimpleCacheLoader> loader, 225 const std::string& cache_dir) {
213 bool success) { 226 if (cache_dir.empty()) {
214 if (!success || !loader) {
215 callback.Run(scoped_refptr<CacheStorageCache>()); 227 callback.Run(scoped_refptr<CacheStorageCache>());
216 return; 228 return;
217 } 229 }
218 230
219 callback.Run(loader->CreateCache(cache_name)); 231 cache_name_to_cache_dir_[cache_name] = cache_dir;
232 callback.Run(CreateCache(cache_name));
220 } 233 }
221 234
222 void CleanUpDeletedCache(const std::string& cache_name, 235 void CleanUpDeletedCache(const std::string& cache_name,
223 const BoolCallback& callback) override { 236 const BoolCallback& callback) override {
224 DCHECK_CURRENTLY_ON(BrowserThread::IO); 237 DCHECK_CURRENTLY_ON(BrowserThread::IO);
225 238 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name));
226 // 1. Delete the cache's directory. (CleanUpDeleteCacheDirInPool)
227 239
228 base::FilePath cache_path = 240 base::FilePath cache_path =
229 CreatePersistentCachePath(origin_path_, cache_name); 241 origin_path_.AppendASCII(cache_name_to_cache_dir_[cache_name]);
242 cache_name_to_cache_dir_.erase(cache_name);
243
230 cache_task_runner_->PostTask( 244 cache_task_runner_->PostTask(
231 FROM_HERE, 245 FROM_HERE,
232 base::Bind(&SimpleCacheLoader::CleanUpDeleteCacheDirInPool, cache_path, 246 base::Bind(&SimpleCacheLoader::CleanUpDeleteCacheDirInPool, cache_path,
233 callback, base::ThreadTaskRunnerHandle::Get())); 247 callback, base::ThreadTaskRunnerHandle::Get()));
234 } 248 }
235 249
236 static void CleanUpDeleteCacheDirInPool( 250 static void CleanUpDeleteCacheDirInPool(
237 const base::FilePath& cache_path, 251 const base::FilePath& cache_path,
238 const BoolCallback& callback, 252 const BoolCallback& callback,
239 const scoped_refptr<base::SingleThreadTaskRunner>& original_task_runner) { 253 const scoped_refptr<base::SingleThreadTaskRunner>& original_task_runner) {
240 bool rv = base::DeleteFile(cache_path, true); 254 bool rv = base::DeleteFile(cache_path, true);
241 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, rv)); 255 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, rv));
242 } 256 }
243 257
244 void WriteIndex(const StringVector& cache_names, 258 void WriteIndex(const StringVector& cache_names,
245 const BoolCallback& callback) override { 259 const BoolCallback& callback) override {
246 DCHECK_CURRENTLY_ON(BrowserThread::IO); 260 DCHECK_CURRENTLY_ON(BrowserThread::IO);
247 261
248 // 1. Create the index file as a string. (WriteIndex) 262 // 1. Create the index file as a string. (WriteIndex)
249 // 2. Write the file to disk. (WriteIndexWriteToFileInPool) 263 // 2. Write the file to disk. (WriteIndexWriteToFileInPool)
250 264
251 CacheStorageIndex index; 265 CacheStorageIndex index;
252 index.set_origin(origin_.spec()); 266 index.set_origin(origin_.spec());
253 267
254 for (size_t i = 0u, max = cache_names.size(); i < max; ++i) { 268 for (size_t i = 0u, max = cache_names.size(); i < max; ++i) {
269 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_names[i]));
270
255 CacheStorageIndex::Cache* index_cache = index.add_cache(); 271 CacheStorageIndex::Cache* index_cache = index.add_cache();
256 index_cache->set_name(cache_names[i]); 272 index_cache->set_name(cache_names[i]);
273 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_names[i]]);
257 } 274 }
258 275
259 std::string serialized; 276 std::string serialized;
260 bool success = index.SerializeToString(&serialized); 277 bool success = index.SerializeToString(&serialized);
261 DCHECK(success); 278 DCHECK(success);
262 279
263 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); 280 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp");
264 base::FilePath index_path = 281 base::FilePath index_path =
265 origin_path_.AppendASCII(CacheStorage::kIndexFileName); 282 origin_path_.AppendASCII(CacheStorage::kIndexFileName);
266 283
(...skipping 23 matching lines...) Expand all
290 void LoadIndex(scoped_ptr<std::vector<std::string>> names, 307 void LoadIndex(scoped_ptr<std::vector<std::string>> names,
291 const StringVectorCallback& callback) override { 308 const StringVectorCallback& callback) override {
292 DCHECK_CURRENTLY_ON(BrowserThread::IO); 309 DCHECK_CURRENTLY_ON(BrowserThread::IO);
293 310
294 // 1. Read the file from disk. (LoadIndexReadFileInPool) 311 // 1. Read the file from disk. (LoadIndexReadFileInPool)
295 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile) 312 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile)
296 313
297 base::FilePath index_path = 314 base::FilePath index_path =
298 origin_path_.AppendASCII(CacheStorage::kIndexFileName); 315 origin_path_.AppendASCII(CacheStorage::kIndexFileName);
299 316
300 cache_task_runner_->PostTask( 317 PostTaskAndReplyWithResult(
301 FROM_HERE, base::Bind(&SimpleCacheLoader::LoadIndexReadFileInPool, 318 cache_task_runner_.get(), FROM_HERE,
302 index_path, base::Passed(names.Pass()), callback, 319 base::Bind(&SimpleCacheLoader::ReadAndMigrateIndexInPool, index_path),
303 base::ThreadTaskRunnerHandle::Get())); 320 base::Bind(&SimpleCacheLoader::LoadIndexDidReadFile,
321 weak_ptr_factory_.GetWeakPtr(), base::Passed(&names),
322 callback));
304 } 323 }
305 324
306 static void LoadIndexReadFileInPool( 325 void LoadIndexDidReadFile(scoped_ptr<std::vector<std::string>> names,
307 const base::FilePath& index_path, 326 const StringVectorCallback& callback,
308 scoped_ptr<std::vector<std::string>> names, 327 const std::string& serialized) {
309 const StringVectorCallback& callback,
310 const scoped_refptr<base::SingleThreadTaskRunner>& original_task_runner) {
311 std::string body;
312 base::ReadFileToString(index_path, &body);
313
314 original_task_runner->PostTask(
315 FROM_HERE, base::Bind(&SimpleCacheLoader::LoadIndexDidReadFile,
316 base::Passed(names.Pass()), callback, body));
317 }
318
319 static void LoadIndexDidReadFile(scoped_ptr<std::vector<std::string>> names,
320 const StringVectorCallback& callback,
321 const std::string& serialized) {
322 DCHECK_CURRENTLY_ON(BrowserThread::IO); 328 DCHECK_CURRENTLY_ON(BrowserThread::IO);
323 329
324 CacheStorageIndex index; 330 CacheStorageIndex index;
325 if (index.ParseFromString(serialized)) { 331 if (index.ParseFromString(serialized)) {
326 for (int i = 0, max = index.cache_size(); i < max; ++i) { 332 for (int i = 0, max = index.cache_size(); i < max; ++i) {
327 const CacheStorageIndex::Cache& cache = index.cache(i); 333 const CacheStorageIndex::Cache& cache = index.cache(i);
334 DCHECK(cache.has_cache_dir());
328 names->push_back(cache.name()); 335 names->push_back(cache.name());
336 cache_name_to_cache_dir_[cache.name()] = cache.cache_dir();
329 } 337 }
330 } 338 }
331 339
332 // TODO(jkarlin): Delete caches that are in the directory and not returned 340 // TODO(jkarlin): Delete caches that are in the directory and not returned
333 // in LoadIndex. 341 // in LoadIndex.
334 callback.Run(names.Pass()); 342 callback.Run(names.Pass());
335 } 343 }
336 344
337 private: 345 private:
346 friend class MigratedLegacyCacheDirectoryNameTest;
338 ~SimpleCacheLoader() override {} 347 ~SimpleCacheLoader() override {}
339 348
340 static std::string HexedHash(const std::string& value) { 349 // Runs on cache_task_runner_
341 std::string value_hash = base::SHA1HashString(value); 350 static std::string MigrateCachesIfNecessaryInPool(
342 std::string valued_hexed_hash = base::ToLowerASCII( 351 const std::string& body,
343 base::HexEncode(value_hash.c_str(), value_hash.length())); 352 const base::FilePath& index_path) {
344 return valued_hexed_hash; 353 CacheStorageIndex index;
354 base::FilePath origin_path = index_path.DirName();
355
356 if (!index.ParseFromString(body))
357 return body;
358
359 bool index_is_dirty = false;
360
361 // Look for caches that have no cache_dir. Give any such caches a directory
362 // with a random name and move them there. Then, rewrite the index file.
363 for (int i = 0, max = index.cache_size(); i < max; ++i) {
364 const CacheStorageIndex::Cache& cache = index.cache(i);
365 if (!cache.has_cache_dir()) {
366 // find a new home for the cache.
jsbell 2015/10/23 21:09:59 Nit: Capitalize.
jkarlin 2015/10/23 22:57:41 Done.
367 base::FilePath legacy_cache_path =
368 origin_path.AppendASCII(HexedHash(cache.name()));
369 std::string cache_dir;
370 base::FilePath cache_path;
371 do {
372 cache_dir = base::GenerateGUID();
373 cache_path = origin_path.AppendASCII(cache_dir);
374 } while (base::PathExists(cache_path));
375
376 if (!base::Move(legacy_cache_path, cache_path))
377 return "";
jsbell 2015/10/23 21:09:59 At this point, some caches may have been moved so
jkarlin 2015/10/23 22:57:41 Done.
378
379 index.mutable_cache(0)->set_cache_dir(cache_dir);
380 index_is_dirty = true;
381 }
382 }
383
384 if (index_is_dirty) {
385 std::string new_body;
386 if (!index.SerializeToString(&new_body))
387 return "";
388 if (base::WriteFile(index_path, new_body.c_str(), new_body.size()) !=
389 base::checked_cast<int>(new_body.size()))
390 return "";
391 return new_body;
392 }
393
394 return body;
345 } 395 }
346 396
347 static base::FilePath CreatePersistentCachePath( 397 // Runs on cache_task_runner_
348 const base::FilePath& origin_path, 398 static std::string ReadAndMigrateIndexInPool(
349 const std::string& cache_name) { 399 const base::FilePath& index_path) {
350 return origin_path.AppendASCII(HexedHash(cache_name)); 400 std::string body;
401 base::ReadFileToString(index_path, &body);
402
403 return MigrateCachesIfNecessaryInPool(body, index_path);
351 } 404 }
352 405
353 const base::FilePath origin_path_; 406 const base::FilePath origin_path_;
407 std::map<std::string, std::string> cache_name_to_cache_dir_;
354 408
355 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_; 409 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_;
356 }; 410 };
357 411
358 CacheStorage::CacheStorage( 412 CacheStorage::CacheStorage(
359 const base::FilePath& path, 413 const base::FilePath& path,
360 bool memory_only, 414 bool memory_only,
361 base::SequencedTaskRunner* cache_task_runner, 415 base::SequencedTaskRunner* cache_task_runner,
362 const scoped_refptr<net::URLRequestContextGetter>& request_context, 416 const scoped_refptr<net::URLRequestContextGetter>& request_context,
363 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 417 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 616 }
563 617
564 void CacheStorage::OpenCacheImpl(const std::string& cache_name, 618 void CacheStorage::OpenCacheImpl(const std::string& cache_name,
565 const CacheAndErrorCallback& callback) { 619 const CacheAndErrorCallback& callback) {
566 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 620 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
567 if (cache.get()) { 621 if (cache.get()) {
568 callback.Run(cache, CACHE_STORAGE_OK); 622 callback.Run(cache, CACHE_STORAGE_OK);
569 return; 623 return;
570 } 624 }
571 625
572 cache_loader_->CreateCache( 626 cache_loader_->PrepareNewCacheDestination(
573 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, 627 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache,
574 weak_factory_.GetWeakPtr(), cache_name, callback)); 628 weak_factory_.GetWeakPtr(), cache_name, callback));
575 } 629 }
576 630
577 void CacheStorage::CreateCacheDidCreateCache( 631 void CacheStorage::CreateCacheDidCreateCache(
578 const std::string& cache_name, 632 const std::string& cache_name,
579 const CacheAndErrorCallback& callback, 633 const CacheAndErrorCallback& callback,
580 const scoped_refptr<CacheStorageCache>& cache) { 634 const scoped_refptr<CacheStorageCache>& cache) {
581 DCHECK_CURRENTLY_ON(BrowserThread::IO); 635 DCHECK_CURRENTLY_ON(BrowserThread::IO);
582 636
(...skipping 22 matching lines...) Expand all
605 DCHECK_CURRENTLY_ON(BrowserThread::IO); 659 DCHECK_CURRENTLY_ON(BrowserThread::IO);
606 DCHECK(cache.get()); 660 DCHECK(cache.get());
607 661
608 // TODO(jkarlin): Handle !success. 662 // TODO(jkarlin): Handle !success.
609 663
610 callback.Run(cache, CACHE_STORAGE_OK); 664 callback.Run(cache, CACHE_STORAGE_OK);
611 } 665 }
612 666
613 void CacheStorage::HasCacheImpl(const std::string& cache_name, 667 void CacheStorage::HasCacheImpl(const std::string& cache_name,
614 const BoolAndErrorCallback& callback) { 668 const BoolAndErrorCallback& callback) {
615 bool has_cache = cache_map_.find(cache_name) != cache_map_.end(); 669 bool has_cache = ContainsKey(cache_map_, cache_name);
616
617 callback.Run(has_cache, CACHE_STORAGE_OK); 670 callback.Run(has_cache, CACHE_STORAGE_OK);
618 } 671 }
619 672
620 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, 673 void CacheStorage::DeleteCacheImpl(const std::string& cache_name,
621 const BoolAndErrorCallback& callback) { 674 const BoolAndErrorCallback& callback) {
622 CacheMap::iterator it = cache_map_.find(cache_name); 675 CacheMap::iterator it = cache_map_.find(cache_name);
623 if (it == cache_map_.end()) { 676 if (it == cache_map_.end()) {
624 callback.Run(false, CACHE_STORAGE_ERROR_NOT_FOUND); 677 callback.Run(false, CACHE_STORAGE_ERROR_NOT_FOUND);
625 return; 678 return;
626 } 679 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 scoped_ptr<ServiceWorkerResponse> response, 909 scoped_ptr<ServiceWorkerResponse> response,
857 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 910 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
858 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); 911 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr();
859 912
860 callback.Run(error, response.Pass(), blob_data_handle.Pass()); 913 callback.Run(error, response.Pass(), blob_data_handle.Pass());
861 if (cache_storage) 914 if (cache_storage)
862 scheduler_->CompleteOperationAndRunNext(); 915 scheduler_->CompleteOperationAndRunNext();
863 } 916 }
864 917
865 } // namespace content 918 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698