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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 if (found == resource_map_.end()) | 34 if (found == resource_map_.end()) |
35 return kInvalidServiceWorkerResponseId; | 35 return kInvalidServiceWorkerResponseId; |
36 return found->second.size_bytes; | 36 return found->second.size_bytes; |
37 } | 37 } |
38 | 38 |
39 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( | 39 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( |
40 const GURL& url, int64 resource_id) { | 40 const GURL& url, int64 resource_id) { |
41 DCHECK_EQ(kInvalidServiceWorkerResponseId, LookupResourceId(url)); | 41 DCHECK_EQ(kInvalidServiceWorkerResponseId, LookupResourceId(url)); |
42 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | 42 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
43 owner_->status() == ServiceWorkerVersion::INSTALLING); | 43 owner_->status() == ServiceWorkerVersion::INSTALLING); |
| 44 if (!context_) |
| 45 return; // Our storage has been wiped via DeleteAndStartOver. |
44 resource_map_[url] = | 46 resource_map_[url] = |
45 ServiceWorkerDatabase::ResourceRecord(resource_id, url, -1); | 47 ServiceWorkerDatabase::ResourceRecord(resource_id, url, -1); |
46 context_->storage()->StoreUncommittedResponseId(resource_id); | 48 context_->storage()->StoreUncommittedResponseId(resource_id); |
47 } | 49 } |
48 | 50 |
49 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( | 51 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( |
50 const GURL& url, | 52 const GURL& url, |
51 int64 size_bytes, | 53 int64 size_bytes, |
52 const net::URLRequestStatus& status) { | 54 const net::URLRequestStatus& status) { |
53 DCHECK_NE(kInvalidServiceWorkerResponseId, LookupResourceId(url)); | 55 DCHECK_NE(kInvalidServiceWorkerResponseId, LookupResourceId(url)); |
54 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | 56 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
55 owner_->status() == ServiceWorkerVersion::INSTALLING); | 57 owner_->status() == ServiceWorkerVersion::INSTALLING); |
| 58 if (!context_) |
| 59 return; // Our storage has been wiped via DeleteAndStartOver. |
56 if (!status.is_success()) { | 60 if (!status.is_success()) { |
57 context_->storage()->DoomUncommittedResponse(LookupResourceId(url)); | 61 context_->storage()->DoomUncommittedResponse(LookupResourceId(url)); |
58 resource_map_.erase(url); | 62 resource_map_.erase(url); |
59 if (owner_->script_url() == url) | 63 if (owner_->script_url() == url) |
60 main_script_status_ = status; | 64 main_script_status_ = status; |
61 } else { | 65 } else { |
62 resource_map_[url].size_bytes = size_bytes; | 66 resource_map_[url].size_bytes = size_bytes; |
63 } | 67 } |
64 } | 68 } |
65 | 69 |
(...skipping 11 matching lines...) Expand all Loading... |
77 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { | 81 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { |
78 DCHECK(resource_map_.empty()); | 82 DCHECK(resource_map_.empty()); |
79 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; | 83 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; |
80 for (RecordVector::const_iterator it = resources.begin(); | 84 for (RecordVector::const_iterator it = resources.begin(); |
81 it != resources.end(); ++it) { | 85 it != resources.end(); ++it) { |
82 resource_map_[it->url] = *it; | 86 resource_map_[it->url] = *it; |
83 } | 87 } |
84 } | 88 } |
85 | 89 |
86 } // namespace content | 90 } // namespace content |
OLD | NEW |