Index: content/browser/service_worker/service_worker_script_cache_map.cc |
diff --git a/content/browser/service_worker/service_worker_script_cache_map.cc b/content/browser/service_worker/service_worker_script_cache_map.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..78e0a5029c77e46bfc900be13ac0797f2410706d |
--- /dev/null |
+++ b/content/browser/service_worker/service_worker_script_cache_map.cc |
@@ -0,0 +1,63 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/service_worker/service_worker_script_cache_map.h" |
+ |
+#include "base/logging.h" |
+#include "content/browser/service_worker/service_worker_version.h" |
+#include "content/common/service_worker/service_worker_types.h" |
+ |
+namespace content { |
+ |
+ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap( |
+ ServiceWorkerVersion* owner) |
+ : owner_(owner), |
+ is_eval_complete_(false), |
+ resources_started_(0), |
+ resources_finished_(0), |
+ has_error_(false) { |
+} |
+ |
+ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { |
+} |
+ |
+int64 ServiceWorkerScriptCacheMap::Lookup(const GURL& url) { |
+ ResourceIDMap::const_iterator found = resource_ids_.find(url); |
+ if (found == resource_ids_.end()) |
+ return kInvalidServiceWorkerResponseId; |
+ return found->second; |
+} |
+ |
+void ServiceWorkerScriptCacheMap::NotifyStartedCaching( |
+ const GURL& url, int64 resource_id) { |
+ DCHECK_EQ(kInvalidServiceWorkerResponseId, Lookup(url)); |
+ DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
+ owner_->status() == ServiceWorkerVersion::INSTALLING); |
+ DCHECK(!is_eval_complete_); |
+ resource_ids_[url] = resource_id; |
+ ++resources_started_; |
+} |
+ |
+void ServiceWorkerScriptCacheMap::NotifyFinishedCaching( |
+ const GURL& url, bool success) { |
+ DCHECK_NE(kInvalidServiceWorkerResponseId, Lookup(url)); |
+ DCHECK(owner_->status() == ServiceWorkerVersion::NEW || |
+ owner_->status() == ServiceWorkerVersion::INSTALLING); |
+ ++resources_finished_; |
+ if (!success) |
+ has_error_ = true; |
+ if (url == owner_->script_url()) |
+ owner_->NotifyMainScriptCached(success); |
+ if (is_eval_complete_ && resources_finished_ == resources_started_) |
+ owner_->NotifyAllScriptsCached(has_error_); |
+} |
+ |
+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
|
+ DCHECK(!is_eval_complete_); |
+ is_eval_complete_ = true; |
+ 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.
|
+ owner_->NotifyAllScriptsCached(has_error_); |
+} |
+ |
+} // namespace content |