| 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 has_error_(false) { | |
| 21 } | 20 } |
| 22 | 21 |
| 23 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { | 22 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { |
| 24 } | 23 } |
| 25 | 24 |
| 26 int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) { | 25 int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) { |
| 27 ResourceIDMap::const_iterator found = resource_ids_.find(url); | 26 ResourceIDMap::const_iterator found = resource_ids_.find(url); |
| 28 if (found == resource_ids_.end()) | 27 if (found == resource_ids_.end()) |
| 29 return kInvalidServiceWorkerResponseId; | 28 return kInvalidServiceWorkerResponseId; |
| 30 return found->second; | 29 return found->second; |
| 31 } | 30 } |
| 32 | 31 |
| 33 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( | 32 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( |
| 34 const GURL& url, int64 resource_id) { | 33 const GURL& url, int64 resource_id) { |
| 35 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); | 34 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); |
| 36 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | 35 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
| 37 owner_->status() == ServiceWorkerVersion::INSTALLING); | 36 owner_->status() == ServiceWorkerVersion::INSTALLING); |
| 38 resource_ids_[url] = resource_id; | 37 resource_ids_[url] = resource_id; |
| 39 context_->storage()->StoreUncommittedResponseId(resource_id); | 38 context_->storage()->StoreUncommittedResponseId(resource_id); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( | 41 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( |
| 43 const GURL& url, bool success) { | 42 const GURL& url, const net::URLRequestStatus& status) { |
| 44 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); | 43 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); |
| 45 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | 44 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
| 46 owner_->status() == ServiceWorkerVersion::INSTALLING); | 45 owner_->status() == ServiceWorkerVersion::INSTALLING); |
| 47 if (!success) { | 46 if (!status.is_success()) { |
| 48 context_->storage()->DoomUncommittedResponse(Lookup(url)); | 47 context_->storage()->DoomUncommittedResponse(Lookup(url)); |
| 49 has_error_ = true; | |
| 50 resource_ids_.erase(url); | 48 resource_ids_.erase(url); |
| 49 if (owner_->script_url() == url) |
| 50 main_script_status_ = status; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ServiceWorkerScriptCacheMap::GetResources( | 54 void ServiceWorkerScriptCacheMap::GetResources( |
| 55 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) { | 55 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) { |
| 56 DCHECK(resources->empty()); | 56 DCHECK(resources->empty()); |
| 57 for (ResourceIDMap::const_iterator it = resource_ids_.begin(); | 57 for (ResourceIDMap::const_iterator it = resource_ids_.begin(); |
| 58 it != resource_ids_.end(); ++it) { | 58 it != resource_ids_.end(); ++it) { |
| 59 resources->push_back( | 59 resources->push_back( |
| 60 ServiceWorkerDatabase::ResourceRecord(it->second, it->first)); | 60 ServiceWorkerDatabase::ResourceRecord(it->second, it->first)); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ServiceWorkerScriptCacheMap::SetResources( | 64 void ServiceWorkerScriptCacheMap::SetResources( |
| 65 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { | 65 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { |
| 66 DCHECK(resource_ids_.empty()); | 66 DCHECK(resource_ids_.empty()); |
| 67 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; | 67 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; |
| 68 for (RecordVector::const_iterator it = resources.begin(); | 68 for (RecordVector::const_iterator it = resources.begin(); |
| 69 it != resources.end(); ++it) { | 69 it != resources.end(); ++it) { |
| 70 resource_ids_[it->url] = it->resource_id; | 70 resource_ids_[it->url] = it->resource_id; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace content | 74 } // namespace content |
| OLD | NEW |