OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 ServiceWorkerVersion::ServiceWorkerVersion( | 83 ServiceWorkerVersion::ServiceWorkerVersion( |
84 ServiceWorkerRegistration* registration, | 84 ServiceWorkerRegistration* registration, |
85 int64 version_id, | 85 int64 version_id, |
86 base::WeakPtr<ServiceWorkerContextCore> context) | 86 base::WeakPtr<ServiceWorkerContextCore> context) |
87 : version_id_(version_id), | 87 : version_id_(version_id), |
88 registration_id_(kInvalidServiceWorkerVersionId), | 88 registration_id_(kInvalidServiceWorkerVersionId), |
89 status_(NEW), | 89 status_(NEW), |
90 context_(context), | 90 context_(context), |
| 91 script_cache_map_(this), |
91 weak_factory_(this) { | 92 weak_factory_(this) { |
92 DCHECK(context_); | 93 DCHECK(context_); |
| 94 DCHECK(registration); |
93 if (registration) { | 95 if (registration) { |
94 registration_id_ = registration->id(); | 96 registration_id_ = registration->id(); |
95 script_url_ = registration->script_url(); | 97 script_url_ = registration->script_url(); |
96 scope_ = registration->pattern(); | 98 scope_ = registration->pattern(); |
97 } | 99 } |
98 context_->AddLiveVersion(this); | 100 context_->AddLiveVersion(this); |
99 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 101 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
100 embedded_worker_->AddListener(this); | 102 embedded_worker_->AddListener(this); |
101 } | 103 } |
102 | 104 |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 if (!callback) { | 545 if (!callback) { |
544 NOTREACHED() << "Got unexpected message: " << request_id; | 546 NOTREACHED() << "Got unexpected message: " << request_id; |
545 return; | 547 return; |
546 } | 548 } |
547 | 549 |
548 scoped_refptr<ServiceWorkerVersion> protect(this); | 550 scoped_refptr<ServiceWorkerVersion> protect(this); |
549 callback->Run(SERVICE_WORKER_OK); | 551 callback->Run(SERVICE_WORKER_OK); |
550 sync_callbacks_.Remove(request_id); | 552 sync_callbacks_.Remove(request_id); |
551 } | 553 } |
552 | 554 |
553 void ServiceWorkerVersion::AddToScriptCache( | |
554 const GURL& url, int64 resource_id) { | |
555 DCHECK_EQ(kInvalidServiceWorkerResponseId, LookupInScriptCache(url)); | |
556 DCHECK_EQ(NEW, status_); | |
557 script_cache_map_[url] = resource_id; | |
558 } | |
559 | |
560 int64 ServiceWorkerVersion::LookupInScriptCache(const GURL& url) { | |
561 ResourceIDMap::const_iterator found = script_cache_map_.find(url); | |
562 if (found == script_cache_map_.end()) | |
563 return kInvalidServiceWorkerResponseId; | |
564 return found->second; | |
565 } | |
566 | |
567 void ServiceWorkerVersion::OnPostMessageToDocument( | 555 void ServiceWorkerVersion::OnPostMessageToDocument( |
568 int client_id, | 556 int client_id, |
569 const base::string16& message, | 557 const base::string16& message, |
570 const std::vector<int>& sent_message_port_ids) { | 558 const std::vector<int>& sent_message_port_ids) { |
571 ServiceWorkerProviderHost* provider_host = | 559 ServiceWorkerProviderHost* provider_host = |
572 controllee_by_id_.Lookup(client_id); | 560 controllee_by_id_.Lookup(client_id); |
573 if (!provider_host) { | 561 if (!provider_host) { |
574 // The client may already have been closed, just ignore. | 562 // The client may already have been closed, just ignore. |
575 return; | 563 return; |
576 } | 564 } |
577 provider_host->PostMessage(message, sent_message_port_ids); | 565 provider_host->PostMessage(message, sent_message_port_ids); |
578 } | 566 } |
579 | 567 |
580 } // namespace content | 568 } // namespace content |
OLD | NEW |