Chromium Code Reviews| 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/service_worker/service_worker_script_cache_map.h" | 5 #include "content/browser/service_worker/service_worker_script_cache_map.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 9 #include "content/browser/service_worker/service_worker_storage.h" | 9 #include "content/browser/service_worker/service_worker_storage.h" |
| 10 #include "content/browser/service_worker/service_worker_version.h" | 10 #include "content/browser/service_worker/service_worker_version.h" |
| 11 #include "content/common/service_worker/service_worker_types.h" | 11 #include "content/common/service_worker/service_worker_types.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap( | 15 ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap( |
| 16 ServiceWorkerVersion* owner, | 16 ServiceWorkerVersion* owner, |
| 17 base::WeakPtr<ServiceWorkerContextCore> context) | 17 base::WeakPtr<ServiceWorkerContextCore> context) |
| 18 : owner_(owner), | 18 : owner_(owner), |
| 19 context_(context) { | 19 context_(context) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { | 22 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) { | 25 int64 ServiceWorkerScriptCacheMap::LookupResourceId(const GURL& url) { |
| 26 ResourceIDMap::const_iterator found = resource_ids_.find(url); | 26 ResourceMap::const_iterator found = resource_map_.find(url); |
| 27 if (found == resource_ids_.end()) | 27 if (found == resource_map_.end()) |
| 28 return kInvalidServiceWorkerResponseId; | 28 return kInvalidServiceWorkerResponseId; |
| 29 return found->second; | 29 return found->second.resource_id; |
| 30 } | |
| 31 | |
| 32 int64 ServiceWorkerScriptCacheMap::LookupResourceSize(const GURL& url) { | |
| 33 ResourceMap::const_iterator found = resource_map_.find(url); | |
| 34 if (found == resource_map_.end()) | |
| 35 return kInvalidServiceWorkerResponseId; | |
| 36 return found->second.size_bytes; | |
| 30 } | 37 } |
| 31 | 38 |
| 32 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( | 39 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( |
| 33 const GURL& url, int64 resource_id) { | 40 const GURL& url, int64 resource_id) { |
| 34 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); | 41 DCHECK_EQ(kInvalidServiceWorkerResponseId, LookupResourceId(url)); |
| 35 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | 42 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
| 36 owner_->status() == ServiceWorkerVersion::INSTALLING); | 43 owner_->status() == ServiceWorkerVersion::INSTALLING); |
| 37 resource_ids_[url] = resource_id; | 44 resource_map_[url] = |
| 45 ServiceWorkerDatabase::ResourceRecord(resource_id, url, -1); | |
| 38 context_->storage()->StoreUncommittedResponseId(resource_id); | 46 context_->storage()->StoreUncommittedResponseId(resource_id); |
| 39 } | 47 } |
| 40 | 48 |
| 41 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( | 49 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( |
| 42 const GURL& url, const net::URLRequestStatus& status) { | 50 const GURL& url, |
| 43 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); | 51 int64 size_bytes, |
| 52 const net::URLRequestStatus& status) { | |
| 53 DCHECK_NE(kInvalidServiceWorkerResponseId, LookupResourceId(url)); | |
| 44 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | 54 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
| 45 owner_->status() == ServiceWorkerVersion::INSTALLING); | 55 owner_->status() == ServiceWorkerVersion::INSTALLING); |
| 46 if (!status.is_success()) { | 56 if (!status.is_success()) { |
| 47 context_->storage()->DoomUncommittedResponse(Lookup(url)); | 57 context_->storage()->DoomUncommittedResponse(LookupResourceId(url)); |
| 48 resource_ids_.erase(url); | 58 resource_map_.erase(url); |
| 49 if (owner_->script_url() == url) | 59 if (owner_->script_url() == url) |
| 50 main_script_status_ = status; | 60 main_script_status_ = status; |
| 61 } else { | |
| 62 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.
| |
| 51 } | 63 } |
| 52 } | 64 } |
| 53 | 65 |
| 54 void ServiceWorkerScriptCacheMap::GetResources( | 66 void ServiceWorkerScriptCacheMap::GetResources( |
| 55 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) { | 67 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) { |
| 56 DCHECK(resources->empty()); | 68 DCHECK(resources->empty()); |
| 57 for (ResourceIDMap::const_iterator it = resource_ids_.begin(); | 69 for (ResourceMap::const_iterator it = resource_map_.begin(); |
| 58 it != resource_ids_.end(); ++it) { | 70 it != resource_map_.end(); |
| 59 resources->push_back( | 71 ++it) { |
| 60 ServiceWorkerDatabase::ResourceRecord(it->second, it->first)); | 72 resources->push_back(it->second); |
| 61 } | 73 } |
| 62 } | 74 } |
| 63 | 75 |
| 64 void ServiceWorkerScriptCacheMap::SetResources( | 76 void ServiceWorkerScriptCacheMap::SetResources( |
| 65 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { | 77 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { |
| 66 DCHECK(resource_ids_.empty()); | 78 DCHECK(resource_map_.empty()); |
| 67 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; | 79 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; |
| 68 for (RecordVector::const_iterator it = resources.begin(); | 80 for (RecordVector::const_iterator it = resources.begin(); |
| 69 it != resources.end(); ++it) { | 81 it != resources.end(); ++it) { |
| 70 resource_ids_[it->url] = it->resource_id; | 82 resource_map_[it->url] = *it; |
| 71 } | 83 } |
| 72 } | 84 } |
| 73 | 85 |
| 74 } // namespace content | 86 } // namespace content |
| OLD | NEW |