OLD | NEW |
---|---|
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 |
36 void CloseAllCachesDidCloseCache(const scoped_refptr<CacheStorageCache>& cache, | 37 void CloseAllCachesDidCloseCache(const scoped_refptr<CacheStorageCache>& cache, |
37 const base::Closure& barrier_closure) { | 38 const base::Closure& barrier_closure) { |
38 barrier_closure.Run(); | 39 barrier_closure.Run(); |
39 } | 40 } |
40 | 41 |
42 std::string ReadFile(const base::FilePath& path) { | |
43 std::string body; | |
44 base::ReadFileToString(path, &body); | |
45 return body; | |
46 } | |
47 | |
41 } // namespace | 48 } // namespace |
42 | 49 |
50 class LegacyCacheDirectoryNameTest; | |
51 | |
43 const char CacheStorage::kIndexFileName[] = "index.txt"; | 52 const char CacheStorage::kIndexFileName[] = "index.txt"; |
44 | 53 |
45 // Handles the loading and clean up of CacheStorageCache objects. The | 54 // Handles the loading and clean up of CacheStorageCache objects. |
46 // callback of every public method is guaranteed to be called. | |
47 class CacheStorage::CacheLoader { | 55 class CacheStorage::CacheLoader { |
48 public: | 56 public: |
49 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&)> | 57 typedef base::Callback<void(const scoped_refptr<CacheStorageCache>&)> |
50 CacheCallback; | 58 CacheCallback; |
51 typedef base::Callback<void(bool)> BoolCallback; | 59 typedef base::Callback<void(bool)> BoolCallback; |
52 typedef base::Callback<void(scoped_ptr<std::vector<std::string>>)> | 60 typedef base::Callback<void(scoped_ptr<std::vector<std::string>>)> |
53 StringVectorCallback; | 61 StringVectorCallback; |
54 | 62 |
55 CacheLoader( | 63 CacheLoader( |
56 base::SequencedTaskRunner* cache_task_runner, | 64 base::SequencedTaskRunner* cache_task_runner, |
(...skipping 10 matching lines...) Expand all Loading... | |
67 } | 75 } |
68 | 76 |
69 virtual ~CacheLoader() {} | 77 virtual ~CacheLoader() {} |
70 | 78 |
71 // Creates a CacheStorageCache with the given name. It does not attempt to | 79 // Creates a CacheStorageCache with the given name. It does not attempt to |
72 // load the backend, that happens lazily when the cache is used. | 80 // load the backend, that happens lazily when the cache is used. |
73 virtual scoped_refptr<CacheStorageCache> CreateCache( | 81 virtual scoped_refptr<CacheStorageCache> CreateCache( |
74 const std::string& cache_name) = 0; | 82 const std::string& cache_name) = 0; |
75 | 83 |
76 // Deletes any pre-existing cache of the same name and then loads it. | 84 // Deletes any pre-existing cache of the same name and then loads it. |
77 virtual void CreateCache(const std::string& cache_name, | 85 virtual void PrepareNewCacheDestination(const std::string& cache_name, |
78 const CacheCallback& callback) = 0; | 86 const CacheCallback& callback) = 0; |
79 | 87 |
80 // After the backend has been deleted, do any extra house keeping such as | 88 // After the backend has been deleted, do any extra house keeping such as |
81 // removing the cache's directory. | 89 // removing the cache's directory. |
82 virtual void CleanUpDeletedCache(const std::string& key, | 90 virtual void CleanUpDeletedCache(const std::string& key, |
83 const BoolCallback& callback) = 0; | 91 const BoolCallback& callback) = 0; |
84 | 92 |
85 // Writes the cache names (and sizes) to disk if applicable. | 93 // Writes the cache names (and sizes) to disk if applicable. |
86 virtual void WriteIndex(const StringVector& cache_names, | 94 virtual void WriteIndex(const StringVector& cache_names, |
87 const BoolCallback& callback) = 0; | 95 const BoolCallback& callback) = 0; |
88 | 96 |
(...skipping 26 matching lines...) Expand all Loading... | |
115 quota_manager_proxy, | 123 quota_manager_proxy, |
116 blob_context, | 124 blob_context, |
117 origin) {} | 125 origin) {} |
118 | 126 |
119 scoped_refptr<CacheStorageCache> CreateCache( | 127 scoped_refptr<CacheStorageCache> CreateCache( |
120 const std::string& cache_name) override { | 128 const std::string& cache_name) override { |
121 return CacheStorageCache::CreateMemoryCache( | 129 return CacheStorageCache::CreateMemoryCache( |
122 origin_, request_context_getter_, quota_manager_proxy_, blob_context_); | 130 origin_, request_context_getter_, quota_manager_proxy_, blob_context_); |
123 } | 131 } |
124 | 132 |
125 void CreateCache(const std::string& cache_name, | 133 void PrepareNewCacheDestination(const std::string& cache_name, |
126 const CacheCallback& callback) override { | 134 const CacheCallback& callback) override { |
127 scoped_refptr<CacheStorageCache> cache = CreateCache(cache_name); | 135 scoped_refptr<CacheStorageCache> cache = CreateCache(cache_name); |
128 cache_refs_.insert(std::make_pair(cache_name, cache)); | 136 cache_refs_.insert(std::make_pair(cache_name, cache)); |
129 callback.Run(cache); | 137 callback.Run(cache); |
130 } | 138 } |
131 | 139 |
132 void CleanUpDeletedCache(const std::string& cache_name, | 140 void CleanUpDeletedCache(const std::string& cache_name, |
133 const BoolCallback& callback) override { | 141 const BoolCallback& callback) override { |
134 CacheRefMap::iterator it = cache_refs_.find(cache_name); | 142 CacheRefMap::iterator it = cache_refs_.find(cache_name); |
135 DCHECK(it != cache_refs_.end()); | 143 DCHECK(it != cache_refs_.end()); |
136 cache_refs_.erase(it); | 144 cache_refs_.erase(it); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 request_context, | 178 request_context, |
171 quota_manager_proxy, | 179 quota_manager_proxy, |
172 blob_context, | 180 blob_context, |
173 origin), | 181 origin), |
174 origin_path_(origin_path), | 182 origin_path_(origin_path), |
175 weak_ptr_factory_(this) {} | 183 weak_ptr_factory_(this) {} |
176 | 184 |
177 scoped_refptr<CacheStorageCache> CreateCache( | 185 scoped_refptr<CacheStorageCache> CreateCache( |
178 const std::string& cache_name) override { | 186 const std::string& cache_name) override { |
179 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 187 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
188 DCHECK(cache_name_to_cache_dir_.find(cache_name) != | |
jsbell
2015/10/22 16:38:52
Could use ContainsKey() from base/stl_util
jkarlin
2015/10/23 17:23:09
Done, thanks! Forgot about that function.
| |
189 cache_name_to_cache_dir_.end()); | |
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 static std::string PrepareNewCacheDirectoryInPool( |
jsbell
2015/10/22 16:38:52
Add comment that this is run on the cache_task_run
jkarlin
2015/10/23 17:23:09
Done.
| |
205 if (base::PathExists(cache_path)) | 211 const base::FilePath& origin_path) { |
206 base::DeleteFile(cache_path, /* recursive */ true); | 212 std::string cache_dir; |
207 return base::CreateDirectory(cache_path); | 213 base::FilePath cache_path; |
214 do { | |
215 cache_dir = base::GenerateGUID(); | |
216 cache_path = origin_path.AppendASCII(cache_dir); | |
217 } while (base::PathExists(cache_path)); | |
218 | |
219 return base::CreateDirectory(cache_path) ? cache_dir : ""; | |
208 } | 220 } |
209 | 221 |
210 static void CreateCachePreppedDir(const std::string& cache_name, | 222 void PrepareNewCacheCreateCache(const std::string& cache_name, |
211 const CacheCallback& callback, | 223 const CacheCallback& callback, |
212 base::WeakPtr<SimpleCacheLoader> loader, | 224 const std::string& cache_dir) { |
213 bool success) { | 225 if (cache_dir.empty()) { |
214 if (!success || !loader) { | |
215 callback.Run(scoped_refptr<CacheStorageCache>()); | 226 callback.Run(scoped_refptr<CacheStorageCache>()); |
216 return; | 227 return; |
217 } | 228 } |
218 | 229 |
219 callback.Run(loader->CreateCache(cache_name)); | 230 cache_name_to_cache_dir_[cache_name] = cache_dir; |
231 callback.Run(CreateCache(cache_name)); | |
220 } | 232 } |
221 | 233 |
222 void CleanUpDeletedCache(const std::string& cache_name, | 234 void CleanUpDeletedCache(const std::string& cache_name, |
223 const BoolCallback& callback) override { | 235 const BoolCallback& callback) override { |
224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 236 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
225 | 237 DCHECK(cache_name_to_cache_dir_.find(cache_name) != |
jsbell
2015/10/22 16:38:52
Could use ContainsKey()
jkarlin
2015/10/23 17:23:09
Done.
| |
226 // 1. Delete the cache's directory. (CleanUpDeleteCacheDirInPool) | 238 cache_name_to_cache_dir_.end()); |
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(cache_name_to_cache_dir_.find(cache_names[i]) != | |
jsbell
2015/10/22 16:38:52
ContainsKey()
jkarlin
2015/10/23 17:23:09
Done.
| |
270 cache_name_to_cache_dir_.end()); | |
271 | |
255 CacheStorageIndex::Cache* index_cache = index.add_cache(); | 272 CacheStorageIndex::Cache* index_cache = index.add_cache(); |
256 index_cache->set_name(cache_names[i]); | 273 index_cache->set_name(cache_names[i]); |
274 index_cache->set_cache_dir(cache_name_to_cache_dir_[cache_names[i]]); | |
257 } | 275 } |
258 | 276 |
259 std::string serialized; | 277 std::string serialized; |
260 bool success = index.SerializeToString(&serialized); | 278 bool success = index.SerializeToString(&serialized); |
261 DCHECK(success); | 279 DCHECK(success); |
262 | 280 |
263 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); | 281 base::FilePath tmp_path = origin_path_.AppendASCII("index.txt.tmp"); |
264 base::FilePath index_path = | 282 base::FilePath index_path = |
265 origin_path_.AppendASCII(CacheStorage::kIndexFileName); | 283 origin_path_.AppendASCII(CacheStorage::kIndexFileName); |
266 | 284 |
(...skipping 23 matching lines...) Expand all Loading... | |
290 void LoadIndex(scoped_ptr<std::vector<std::string>> names, | 308 void LoadIndex(scoped_ptr<std::vector<std::string>> names, |
291 const StringVectorCallback& callback) override { | 309 const StringVectorCallback& callback) override { |
292 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 310 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
293 | 311 |
294 // 1. Read the file from disk. (LoadIndexReadFileInPool) | 312 // 1. Read the file from disk. (LoadIndexReadFileInPool) |
295 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile) | 313 // 2. Parse file and return the names of the caches (LoadIndexDidReadFile) |
296 | 314 |
297 base::FilePath index_path = | 315 base::FilePath index_path = |
298 origin_path_.AppendASCII(CacheStorage::kIndexFileName); | 316 origin_path_.AppendASCII(CacheStorage::kIndexFileName); |
299 | 317 |
300 cache_task_runner_->PostTask( | 318 PostTaskAndReplyWithResult( |
301 FROM_HERE, base::Bind(&SimpleCacheLoader::LoadIndexReadFileInPool, | 319 cache_task_runner_.get(), FROM_HERE, base::Bind(&ReadFile, index_path), |
302 index_path, base::Passed(names.Pass()), callback, | 320 base::Bind(&SimpleCacheLoader::LoadIndexDidReadFile, |
303 base::ThreadTaskRunnerHandle::Get())); | 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); |
328 names->push_back(cache.name()); | 334 names->push_back(cache.name()); |
335 // Before randomly generated cache directory names were used, the hexed | |
336 // hash of the cache name was used. For backwards compatibility, use the | |
337 // hexed hash as the directory name for protobufs that don't have a | |
338 // directory name. | |
339 std::string cache_dir = | |
340 cache.has_cache_dir() ? cache.cache_dir() : HexedHash(cache.name()); | |
341 cache_name_to_cache_dir_[cache.name()] = cache_dir; | |
329 } | 342 } |
330 } | 343 } |
331 | 344 |
332 // TODO(jkarlin): Delete caches that are in the directory and not returned | 345 // TODO(jkarlin): Delete caches that are in the directory and not returned |
333 // in LoadIndex. | 346 // in LoadIndex. |
334 callback.Run(names.Pass()); | 347 callback.Run(names.Pass()); |
335 } | 348 } |
336 | 349 |
337 private: | 350 private: |
351 friend class LegacyCacheDirectoryNameTest; | |
338 ~SimpleCacheLoader() override {} | 352 ~SimpleCacheLoader() override {} |
339 | 353 |
340 static std::string HexedHash(const std::string& value) { | 354 static std::string HexedHash(const std::string& value) { |
341 std::string value_hash = base::SHA1HashString(value); | 355 std::string value_hash = base::SHA1HashString(value); |
342 std::string valued_hexed_hash = base::ToLowerASCII( | 356 std::string valued_hexed_hash = base::ToLowerASCII( |
343 base::HexEncode(value_hash.c_str(), value_hash.length())); | 357 base::HexEncode(value_hash.c_str(), value_hash.length())); |
344 return valued_hexed_hash; | 358 return valued_hexed_hash; |
345 } | 359 } |
346 | 360 |
347 static base::FilePath CreatePersistentCachePath( | |
348 const base::FilePath& origin_path, | |
349 const std::string& cache_name) { | |
350 return origin_path.AppendASCII(HexedHash(cache_name)); | |
351 } | |
352 | |
353 const base::FilePath origin_path_; | 361 const base::FilePath origin_path_; |
362 std::map<std::string, std::string> cache_name_to_cache_dir_; | |
354 | 363 |
355 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_; | 364 base::WeakPtrFactory<SimpleCacheLoader> weak_ptr_factory_; |
356 }; | 365 }; |
357 | 366 |
358 CacheStorage::CacheStorage( | 367 CacheStorage::CacheStorage( |
359 const base::FilePath& path, | 368 const base::FilePath& path, |
360 bool memory_only, | 369 bool memory_only, |
361 base::SequencedTaskRunner* cache_task_runner, | 370 base::SequencedTaskRunner* cache_task_runner, |
362 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 371 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
363 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, | 372 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 } | 571 } |
563 | 572 |
564 void CacheStorage::OpenCacheImpl(const std::string& cache_name, | 573 void CacheStorage::OpenCacheImpl(const std::string& cache_name, |
565 const CacheAndErrorCallback& callback) { | 574 const CacheAndErrorCallback& callback) { |
566 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); | 575 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); |
567 if (cache.get()) { | 576 if (cache.get()) { |
568 callback.Run(cache, CACHE_STORAGE_OK); | 577 callback.Run(cache, CACHE_STORAGE_OK); |
569 return; | 578 return; |
570 } | 579 } |
571 | 580 |
572 cache_loader_->CreateCache( | 581 cache_loader_->PrepareNewCacheDestination( |
573 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, | 582 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, |
574 weak_factory_.GetWeakPtr(), cache_name, callback)); | 583 weak_factory_.GetWeakPtr(), cache_name, callback)); |
575 } | 584 } |
576 | 585 |
577 void CacheStorage::CreateCacheDidCreateCache( | 586 void CacheStorage::CreateCacheDidCreateCache( |
578 const std::string& cache_name, | 587 const std::string& cache_name, |
579 const CacheAndErrorCallback& callback, | 588 const CacheAndErrorCallback& callback, |
580 const scoped_refptr<CacheStorageCache>& cache) { | 589 const scoped_refptr<CacheStorageCache>& cache) { |
581 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 590 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
582 | 591 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 scoped_ptr<ServiceWorkerResponse> response, | 865 scoped_ptr<ServiceWorkerResponse> response, |
857 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 866 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
858 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | 867 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); |
859 | 868 |
860 callback.Run(error, response.Pass(), blob_data_handle.Pass()); | 869 callback.Run(error, response.Pass(), blob_data_handle.Pass()); |
861 if (cache_storage) | 870 if (cache_storage) |
862 scheduler_->CompleteOperationAndRunNext(); | 871 scheduler_->CompleteOperationAndRunNext(); |
863 } | 872 } |
864 | 873 |
865 } // namespace content | 874 } // namespace content |
OLD | NEW |