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

Side by Side Diff: content/browser/service_worker/service_worker_version.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
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
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 346 }
345 347
346 void ServiceWorkerVersion::AddListener(Listener* listener) { 348 void ServiceWorkerVersion::AddListener(Listener* listener) {
347 listeners_.AddObserver(listener); 349 listeners_.AddObserver(listener);
348 } 350 }
349 351
350 void ServiceWorkerVersion::RemoveListener(Listener* listener) { 352 void ServiceWorkerVersion::RemoveListener(Listener* listener) {
351 listeners_.RemoveObserver(listener); 353 listeners_.RemoveObserver(listener);
352 } 354 }
353 355
356 void ServiceWorkerVersion::NotifyMainScriptCached(bool success) {
357 FOR_EACH_OBSERVER(Listener, listeners_, OnMainScriptCached(this, success));
358 }
359
360 void ServiceWorkerVersion::NotifyAllScriptsCached(bool success) {
361 FOR_EACH_OBSERVER(Listener, listeners_, OnAllScriptsCached(this, success));
362 }
363
354 void ServiceWorkerVersion::OnStarted() { 364 void ServiceWorkerVersion::OnStarted() {
355 DCHECK_EQ(RUNNING, running_status()); 365 DCHECK_EQ(RUNNING, running_status());
356 // Fire all start callbacks. 366 // Fire all start callbacks.
357 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); 367 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK);
358 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStarted(this)); 368 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStarted(this));
359 } 369 }
360 370
361 void ServiceWorkerVersion::OnStopped() { 371 void ServiceWorkerVersion::OnStopped() {
362 DCHECK_EQ(STOPPED, running_status()); 372 DCHECK_EQ(STOPPED, running_status());
363 scoped_refptr<ServiceWorkerVersion> protect(this); 373 scoped_refptr<ServiceWorkerVersion> protect(this);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 if (!callback) { 553 if (!callback) {
544 NOTREACHED() << "Got unexpected message: " << request_id; 554 NOTREACHED() << "Got unexpected message: " << request_id;
545 return; 555 return;
546 } 556 }
547 557
548 scoped_refptr<ServiceWorkerVersion> protect(this); 558 scoped_refptr<ServiceWorkerVersion> protect(this);
549 callback->Run(SERVICE_WORKER_OK); 559 callback->Run(SERVICE_WORKER_OK);
550 sync_callbacks_.Remove(request_id); 560 sync_callbacks_.Remove(request_id);
551 } 561 }
552 562
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( 563 void ServiceWorkerVersion::OnPostMessageToDocument(
568 int client_id, 564 int client_id,
569 const base::string16& message, 565 const base::string16& message,
570 const std::vector<int>& sent_message_port_ids) { 566 const std::vector<int>& sent_message_port_ids) {
571 ServiceWorkerProviderHost* provider_host = 567 ServiceWorkerProviderHost* provider_host =
572 controllee_by_id_.Lookup(client_id); 568 controllee_by_id_.Lookup(client_id);
573 if (!provider_host) { 569 if (!provider_host) {
574 // The client may already have been closed, just ignore. 570 // The client may already have been closed, just ignore.
575 return; 571 return;
576 } 572 }
577 provider_host->PostMessage(message, sent_message_port_ids); 573 provider_host->PostMessage(message, sent_message_port_ids);
578 } 574 }
579 575
580 } // namespace content 576 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698