OLD | NEW |
---|---|
(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::NotifyStartedCaching( | |
33 const GURL& url, int64 resource_id) { | |
34 DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); | |
35 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | |
36 owner_->status() == ServiceWorkerVersion::INSTALLING); | |
37 DCHECK(!is_eval_complete_); | |
38 resource_ids_[url] = resource_id; | |
39 ++resources_started_; | |
40 } | |
41 | |
42 void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( | |
43 const GURL& url, bool success) { | |
44 DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); | |
45 DCHECK(owner_->status() == ServiceWorkerVersion::NEW || | |
46 owner_->status() == ServiceWorkerVersion::INSTALLING); | |
47 ++resources_finished_; | |
48 if (!success) | |
49 has_error_ = true; | |
50 if (url == owner_->script_url()) | |
51 owner_->NotifyMainScriptCached(success); | |
52 if (is_eval_complete_ && resources_finished_ == resources_started_) | |
53 owner_->NotifyAllScriptsCached(has_error_); | |
54 } | |
55 | |
56 void ServiceWorkerScriptCacheMap::NotifyEvalCompletion() { | |
kinuko
2014/05/13 16:14:25
It's a bit questionable if we should cache scripts
michaeln
2014/05/13 22:41:11
Spec issue is right, this is a question for the re
| |
57 DCHECK(!is_eval_complete_); | |
58 is_eval_complete_ = true; | |
59 if (is_eval_complete_ && resources_finished_ == resources_started_) | |
nhiroki
2014/05/13 07:44:34
|is_eval_complete_| is always true here.
michaeln
2014/05/13 22:41:11
Done.
| |
60 owner_->NotifyAllScriptsCached(has_error_); | |
61 } | |
62 | |
63 } // namespace content | |
OLD | NEW |