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

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

Issue 280423005: Adds class ServiceWorkerScriptCacheMap and new ServiceWorkerVersion::Listener methods related to sc… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/service_worker/service_worker_script_cache_map.h"
6
7 #include "base/logging.h"
8 #include "content/browser/service_worker/service_worker_version.h"
9 #include "content/common/service_worker/service_worker_types.h"
10
11 namespace content {
12
13 ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap(
14 ServiceWorkerVersion* owner)
15 : owner_(owner),
16 is_eval_complete_(false),
17 resources_started_(0),
18 resources_finished_(0),
19 has_error_(false) {
20 }
21
22 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() {
23 }
24
25 int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) {
26 ResourceIDMap::const_iterator found = resource_ids_.find(url);
27 if (found == resource_ids_.end())
28 return kInvalidServiceWorkerResponseId;
29 return found->second;
30 }
31
32 void ServiceWorkerScriptCacheMap::AddObserver(Observer* observer) {
33 observers_.AddObserver(observer);
34 }
35
36 void ServiceWorkerScriptCacheMap::RemoveObserver(Observer* observer) {
37 observers_.RemoveObserver(observer);
38 }
39
40 void ServiceWorkerScriptCacheMap::NotifyStartedCaching(
41 const GURL& url, int64 resource_id) {
42 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url));
43 DCHECK(owner_->status() == ServiceWorkerVersion::NEW ||
44 owner_->status() == ServiceWorkerVersion::INSTALLING);
45 DCHECK(!is_eval_complete_);
46 resource_ids_[url] = resource_id;
47 ++resources_started_;
48 }
49
50 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching(
51 const GURL& url, bool success) {
52 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url));
53 DCHECK(owner_->status() == ServiceWorkerVersion::NEW ||
54 owner_->status() == ServiceWorkerVersion::INSTALLING);
55 ++resources_finished_;
56 if (!success)
57 has_error_ = true;
58 if (url == owner_->script_url()) {
59 FOR_EACH_OBSERVER(Observer, observers_,
60 OnMainScriptCached(owner_, success));
61 }
62 if (is_eval_complete_ && resources_finished_ == resources_started_) {
63 FOR_EACH_OBSERVER(Observer, observers_,
64 OnAllScriptsCached(owner_, has_error_));
65 }
66 }
67
68 void ServiceWorkerScriptCacheMap::NotifyEvalCompletion() {
69 DCHECK(!is_eval_complete_);
70 is_eval_complete_ = true;
71 if (resources_finished_ == resources_started_) {
72 FOR_EACH_OBSERVER(Observer, observers_,
73 OnAllScriptsCached(owner_, has_error_));
74 }
75 }
76
77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698