Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: content/browser/service_worker/service_worker_script_cache_map.cc

Issue 369063004: ServiceWorker: SWRegisterJob should manage status of SWVersion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ServiceWorkerVersionBrowserTest Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) { 26 int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) {
27 ResourceIDMap::const_iterator found = resource_ids_.find(url); 27 ResourceIDMap::const_iterator found = resource_ids_.find(url);
28 if (found == resource_ids_.end()) 28 if (found == resource_ids_.end())
29 return kInvalidServiceWorkerResponseId; 29 return kInvalidServiceWorkerResponseId;
30 return found->second; 30 return found->second;
31 } 31 }
32 32
33 void ServiceWorkerScriptCacheMap::NotifyStartedCaching( 33 void ServiceWorkerScriptCacheMap::NotifyStartedCaching(
34 const GURL& url, int64 resource_id) { 34 const GURL& url, int64 resource_id) {
35 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); 35 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url));
36 DCHECK(owner_->status() == ServiceWorkerVersion::NEW); 36 DCHECK(owner_->status() == ServiceWorkerVersion::NEW ||
37 owner_->status() == ServiceWorkerVersion::INSTALLING);
37 resource_ids_[url] = resource_id; 38 resource_ids_[url] = resource_id;
38 context_->storage()->StoreUncommittedReponseId(resource_id); 39 context_->storage()->StoreUncommittedReponseId(resource_id);
39 } 40 }
40 41
41 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( 42 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching(
42 const GURL& url, bool success) { 43 const GURL& url, bool success) {
43 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); 44 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url));
44 DCHECK(owner_->status() == ServiceWorkerVersion::NEW); 45 DCHECK(owner_->status() == ServiceWorkerVersion::NEW ||
46 owner_->status() == ServiceWorkerVersion::INSTALLING);
45 if (!success) { 47 if (!success) {
46 context_->storage()->DoomUncommittedResponse(Lookup(url)); 48 context_->storage()->DoomUncommittedResponse(Lookup(url));
47 has_error_ = true; 49 has_error_ = true;
48 resource_ids_.erase(url); 50 resource_ids_.erase(url);
49 } 51 }
50 } 52 }
51 53
52 void ServiceWorkerScriptCacheMap::GetResources( 54 void ServiceWorkerScriptCacheMap::GetResources(
53 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) { 55 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources) {
54 DCHECK(resources->empty()); 56 DCHECK(resources->empty());
55 for (ResourceIDMap::const_iterator it = resource_ids_.begin(); 57 for (ResourceIDMap::const_iterator it = resource_ids_.begin();
56 it != resource_ids_.end(); ++it) { 58 it != resource_ids_.end(); ++it) {
57 resources->push_back( 59 resources->push_back(
58 ServiceWorkerDatabase::ResourceRecord(it->second, it->first)); 60 ServiceWorkerDatabase::ResourceRecord(it->second, it->first));
59 } 61 }
60 } 62 }
61 63
62 void ServiceWorkerScriptCacheMap::SetResources( 64 void ServiceWorkerScriptCacheMap::SetResources(
63 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { 65 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) {
64 DCHECK(resource_ids_.empty()); 66 DCHECK(resource_ids_.empty());
65 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; 67 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector;
66 for (RecordVector::const_iterator it = resources.begin(); 68 for (RecordVector::const_iterator it = resources.begin();
67 it != resources.end(); ++it) { 69 it != resources.end(); ++it) {
68 resource_ids_[it->url] = it->resource_id; 70 resource_ids_[it->url] = it->resource_id;
69 } 71 }
70 } 72 }
71 73
72 } // namespace content 74 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698