| 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_manager.h" | 5 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 scoped_ptr<CacheStorageManager> manager(new CacheStorageManager( | 119 scoped_ptr<CacheStorageManager> manager(new CacheStorageManager( |
| 120 old_manager->root_path(), old_manager->cache_task_runner(), | 120 old_manager->root_path(), old_manager->cache_task_runner(), |
| 121 old_manager->quota_manager_proxy_.get())); | 121 old_manager->quota_manager_proxy_.get())); |
| 122 // These values may be NULL, in which case this will be called again later by | 122 // These values may be NULL, in which case this will be called again later by |
| 123 // the dispatcher host per usual. | 123 // the dispatcher host per usual. |
| 124 manager->SetBlobParametersForCache(old_manager->url_request_context_getter(), | 124 manager->SetBlobParametersForCache(old_manager->url_request_context_getter(), |
| 125 old_manager->blob_storage_context()); | 125 old_manager->blob_storage_context()); |
| 126 return manager.Pass(); | 126 return manager.Pass(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 CacheStorageManager::~CacheStorageManager() { | 129 CacheStorageManager::~CacheStorageManager() = default; |
| 130 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 131 for (CacheStorageMap::iterator it = cache_storage_map_.begin(); | |
| 132 it != cache_storage_map_.end(); ++it) { | |
| 133 delete it->second; | |
| 134 } | |
| 135 } | |
| 136 | 130 |
| 137 void CacheStorageManager::OpenCache( | 131 void CacheStorageManager::OpenCache( |
| 138 const GURL& origin, | 132 const GURL& origin, |
| 139 const std::string& cache_name, | 133 const std::string& cache_name, |
| 140 const CacheStorage::CacheAndErrorCallback& callback) { | 134 const CacheStorage::CacheAndErrorCallback& callback) { |
| 141 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 135 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 142 | 136 |
| 143 CacheStorage* cache_storage = FindOrCreateCacheStorage(origin); | 137 CacheStorage* cache_storage = FindOrCreateCacheStorage(origin); |
| 144 | 138 |
| 145 cache_storage->OpenCache(cache_name, callback); | 139 cache_storage->OpenCache(cache_name, callback); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 cache_task_runner_.get(), FROM_HERE, | 281 cache_task_runner_.get(), FROM_HERE, |
| 288 base::Bind(&ListOriginsOnDisk, root_path_), | 282 base::Bind(&ListOriginsOnDisk, root_path_), |
| 289 base::Bind(&GetOriginsForHostDidListOrigins, host, callback)); | 283 base::Bind(&GetOriginsForHostDidListOrigins, host, callback)); |
| 290 } | 284 } |
| 291 | 285 |
| 292 void CacheStorageManager::DeleteOriginData( | 286 void CacheStorageManager::DeleteOriginData( |
| 293 const GURL& origin, | 287 const GURL& origin, |
| 294 const storage::QuotaClient::DeletionCallback& callback) { | 288 const storage::QuotaClient::DeletionCallback& callback) { |
| 295 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 289 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 296 | 290 |
| 297 CacheStorage* cache_storage = FindOrCreateCacheStorage(origin); | 291 CacheStorageMap::iterator it = cache_storage_map_.find(origin); |
| 292 if (it == cache_storage_map_.end()) { |
| 293 callback.Run(storage::kQuotaStatusOk); |
| 294 return; |
| 295 } |
| 296 |
| 297 CacheStorage* cache_storage = it->second.release(); |
| 298 cache_storage_map_.erase(origin); | 298 cache_storage_map_.erase(origin); |
| 299 cache_storage->CloseAllCaches( | 299 cache_storage->CloseAllCaches( |
| 300 base::Bind(&CacheStorageManager::DeleteOriginDidClose, origin, callback, | 300 base::Bind(&CacheStorageManager::DeleteOriginDidClose, origin, callback, |
| 301 base::Passed(make_scoped_ptr(cache_storage)), | 301 base::Passed(make_scoped_ptr(cache_storage)), |
| 302 weak_ptr_factory_.GetWeakPtr())); | 302 weak_ptr_factory_.GetWeakPtr())); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void CacheStorageManager::DeleteOriginData(const GURL& origin) { | 305 void CacheStorageManager::DeleteOriginData(const GURL& origin) { |
| 306 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 306 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 307 DeleteOriginData(origin, base::Bind(&EmptyQuotaStatusCallback)); | 307 DeleteOriginData(origin, base::Bind(&EmptyQuotaStatusCallback)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 const GURL& origin) { | 354 const GURL& origin) { |
| 355 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 355 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 356 DCHECK(request_context_getter_); | 356 DCHECK(request_context_getter_); |
| 357 CacheStorageMap::const_iterator it = cache_storage_map_.find(origin); | 357 CacheStorageMap::const_iterator it = cache_storage_map_.find(origin); |
| 358 if (it == cache_storage_map_.end()) { | 358 if (it == cache_storage_map_.end()) { |
| 359 MigrateOrigin(origin); | 359 MigrateOrigin(origin); |
| 360 CacheStorage* cache_storage = new CacheStorage( | 360 CacheStorage* cache_storage = new CacheStorage( |
| 361 ConstructOriginPath(root_path_, origin), IsMemoryBacked(), | 361 ConstructOriginPath(root_path_, origin), IsMemoryBacked(), |
| 362 cache_task_runner_.get(), request_context_getter_, quota_manager_proxy_, | 362 cache_task_runner_.get(), request_context_getter_, quota_manager_proxy_, |
| 363 blob_context_, origin); | 363 blob_context_, origin); |
| 364 // The map owns fetch_stores. | 364 cache_storage_map_.insert( |
| 365 cache_storage_map_.insert(std::make_pair(origin, cache_storage)); | 365 std::make_pair(origin, make_scoped_ptr(cache_storage))); |
| 366 return cache_storage; | 366 return cache_storage; |
| 367 } | 367 } |
| 368 return it->second; | 368 return it->second.get(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 // static | 371 // static |
| 372 base::FilePath CacheStorageManager::ConstructLegacyOriginPath( | 372 base::FilePath CacheStorageManager::ConstructLegacyOriginPath( |
| 373 const base::FilePath& root_path, | 373 const base::FilePath& root_path, |
| 374 const GURL& origin) { | 374 const GURL& origin) { |
| 375 const std::string origin_hash = base::SHA1HashString(origin.spec()); | 375 const std::string origin_hash = base::SHA1HashString(origin.spec()); |
| 376 const std::string origin_hash_hex = base::ToLowerASCII( | 376 const std::string origin_hash_hex = base::ToLowerASCII( |
| 377 base::HexEncode(origin_hash.c_str(), origin_hash.length())); | 377 base::HexEncode(origin_hash.c_str(), origin_hash.length())); |
| 378 return root_path.AppendASCII(origin_hash_hex); | 378 return root_path.AppendASCII(origin_hash_hex); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 405 const base::FilePath& old_path, | 405 const base::FilePath& old_path, |
| 406 const base::FilePath& new_path) { | 406 const base::FilePath& new_path) { |
| 407 if (base::PathExists(old_path)) { | 407 if (base::PathExists(old_path)) { |
| 408 if (!base::PathExists(new_path)) | 408 if (!base::PathExists(new_path)) |
| 409 base::Move(old_path, new_path); | 409 base::Move(old_path, new_path); |
| 410 base::DeleteFile(old_path, /*recursive*/ true); | 410 base::DeleteFile(old_path, /*recursive*/ true); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace content | 414 } // namespace content |
| OLD | NEW |