Chromium Code Reviews| Index: content/browser/service_worker/service_worker_script_cache_map.cc |
| diff --git a/content/browser/service_worker/service_worker_script_cache_map.cc b/content/browser/service_worker/service_worker_script_cache_map.cc |
| index 52a27588f9c2ae3fb5dd5bc380f3a3638ba2cfe6..f7a3ad48697dd40625620371e482c5c4adafc7c1 100644 |
| --- a/content/browser/service_worker/service_worker_script_cache_map.cc |
| +++ b/content/browser/service_worker/service_worker_script_cache_map.cc |
| @@ -22,52 +22,64 @@ ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap( |
| ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { |
| } |
| -int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) { |
| - ResourceIDMap::const_iterator found = resource_ids_.find(url); |
| - if (found == resource_ids_.end()) |
| +int64 ServiceWorkerScriptCacheMap::LookupResourceId(const GURL& url) { |
| + ResourceMap::const_iterator found = resource_map_.find(url); |
| + if (found == resource_map_.end()) |
| return kInvalidServiceWorkerResponseId; |
| - return found->second; |
| + return found->second.resource_id; |
| +} |
| + |
| +int64 ServiceWorkerScriptCacheMap::LookupResourceSize(const GURL& url) { |
| + ResourceMap::const_iterator found = resource_map_.find(url); |
| + if (found == resource_map_.end()) |
| + return kInvalidServiceWorkerResponseId; |
| + return found->second.size_bytes; |
| } |
| void ServiceWorkerScriptCacheMap::NotifyStartedCaching( |
| const GURL& url, int64 resource_id) { |
| - DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); |
| + DCHECK_EQ(kInvalidServiceWorkerResponseId, LookupResourceId(url)); |
| DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
| owner_->status() == ServiceWorkerVersion::INSTALLING); |
| - resource_ids_[url] = resource_id; |
| + resource_map_[url] = |
| + ServiceWorkerDatabase::ResourceRecord(resource_id, url, -1); |
| context_->storage()->StoreUncommittedResponseId(resource_id); |
| } |
| void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( |
| - const GURL& url, const net::URLRequestStatus& status) { |
| - DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); |
| + const GURL& url, |
| + int64 size_bytes, |
| + const net::URLRequestStatus& status) { |
| + DCHECK_NE(kInvalidServiceWorkerResponseId, LookupResourceId(url)); |
| DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
| owner_->status() == ServiceWorkerVersion::INSTALLING); |
| if (!status.is_success()) { |
| - context_->storage()->DoomUncommittedResponse(Lookup(url)); |
| - resource_ids_.erase(url); |
| + context_->storage()->DoomUncommittedResponse(LookupResourceId(url)); |
| + resource_map_.erase(url); |
| if (owner_->script_url() == url) |
| main_script_status_ = status; |
| + } else { |
| + resource_map_[url].size_bytes = static_cast<int64>(size_bytes); |
|
michaeln
2014/10/17 02:01:40
is the static_cast<> needed?
dmurph
2014/10/17 22:55:19
Nope not anymore, removed.
|
| } |
| } |
| void ServiceWorkerScriptCacheMap::GetResources( |
| std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) { |
| DCHECK(resources->empty()); |
| - for (ResourceIDMap::const_iterator it = resource_ids_.begin(); |
| - it != resource_ids_.end(); ++it) { |
| - resources->push_back( |
| - ServiceWorkerDatabase::ResourceRecord(it->second, it->first)); |
| + for (ResourceMap::const_iterator it = resource_map_.begin(); |
| + it != resource_map_.end(); |
| + ++it) { |
| + resources->push_back(it->second); |
| } |
| } |
| void ServiceWorkerScriptCacheMap::SetResources( |
| const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { |
| - DCHECK(resource_ids_.empty()); |
| + DCHECK(resource_map_.empty()); |
| typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; |
| for (RecordVector::const_iterator it = resources.begin(); |
| it != resources.end(); ++it) { |
| - resource_ids_[it->url] = it->resource_id; |
| + resource_map_[it->url] = *it; |
| } |
| } |