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

Unified Diff: content/browser/service_worker/service_worker_provider_host_registry.cc

Issue 325173002: ServiceWorker: Confirm the liveness of the associated context before handling message (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_provider_host_registry.cc
diff --git a/content/browser/service_worker/service_worker_provider_host_registry.cc b/content/browser/service_worker/service_worker_provider_host_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6c57edee79fe0775fbf2678df4510fc404c46218
--- /dev/null
+++ b/content/browser/service_worker/service_worker_provider_host_registry.cc
@@ -0,0 +1,119 @@
+// 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_provider_host_registry.h"
+
+#include "content/browser/service_worker/service_worker_provider_host.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace content {
+
+ServiceWorkerProviderHostRegistry::Iterator::~Iterator() {}
+
+ServiceWorkerProviderHost*
+ServiceWorkerProviderHostRegistry::Iterator::GetProviderHost() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(!IsAtEnd());
+ return provider_host_iterator_->GetCurrentValue();
+}
+
+void ServiceWorkerProviderHostRegistry::Iterator::Advance() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(!IsAtEnd());
+ DCHECK(!provider_host_iterator_->IsAtEnd());
+ DCHECK(!provider_iterator_->IsAtEnd());
+
+ // Advance the inner iterator. If an element is reached, we're done.
+ provider_host_iterator_->Advance();
+ if (!provider_host_iterator_->IsAtEnd())
+ return;
+
+ // Advance the outer iterator until an element is reached, or end is hit.
+ while (true) {
+ provider_iterator_->Advance();
+ if (provider_iterator_->IsAtEnd())
+ return;
+ ProviderMap* provider_map = provider_iterator_->GetCurrentValue();
+ provider_host_iterator_.reset(new ProviderMap::iterator(provider_map));
+ if (!provider_host_iterator_->IsAtEnd())
+ return;
+ }
+}
+
+bool ServiceWorkerProviderHostRegistry::Iterator::IsAtEnd() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ return provider_iterator_->IsAtEnd() &&
+ (!provider_host_iterator_ || provider_host_iterator_->IsAtEnd());
+}
+
+ServiceWorkerProviderHostRegistry::Iterator::Iterator(
+ ProcessToProviderMap* map)
+ : map_(map) {
+ DCHECK(map);
+ Initialize();
+}
+
+void ServiceWorkerProviderHostRegistry::Iterator::Initialize() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ provider_iterator_.reset(new ProcessToProviderMap::iterator(map_));
+ // Advance to the first element.
+ while (!provider_iterator_->IsAtEnd()) {
+ ProviderMap* provider_map = provider_iterator_->GetCurrentValue();
+ provider_host_iterator_.reset(new ProviderMap::iterator(provider_map));
+ if (!provider_host_iterator_->IsAtEnd())
+ return;
+ provider_iterator_->Advance();
+ }
+}
+
+ServiceWorkerProviderHostRegistry::ServiceWorkerProviderHostRegistry() {
+}
+
+ServiceWorkerProviderHostRegistry::~ServiceWorkerProviderHostRegistry() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+}
+
+ServiceWorkerProviderHost* ServiceWorkerProviderHostRegistry::GetProviderHost(
+ int process_id, int provider_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ProviderMap* map = GetProviderMapForProcess(process_id);
+ if (!map)
+ return NULL;
+ return map->Lookup(provider_id);
+}
+
+void ServiceWorkerProviderHostRegistry::AddProviderHost(
+ scoped_ptr<ServiceWorkerProviderHost> host) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ServiceWorkerProviderHost* host_ptr = host.release(); // we take ownership
+ ProviderMap* map = GetProviderMapForProcess(host_ptr->process_id());
+ if (!map) {
+ map = new ProviderMap;
+ providers_.AddWithID(map, host_ptr->process_id());
+ }
+ map->AddWithID(host_ptr, host_ptr->provider_id());
+}
+
+void ServiceWorkerProviderHostRegistry::RemoveProviderHost(
+ int process_id, int provider_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ProviderMap* map = GetProviderMapForProcess(process_id);
+ DCHECK(map);
+ map->Remove(provider_id);
+}
+
+void ServiceWorkerProviderHostRegistry::RemoveAllProviderHostsForProcess(
+ int process_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (providers_.Lookup(process_id))
+ providers_.Remove(process_id);
+}
+
+scoped_ptr<ServiceWorkerProviderHostRegistry::Iterator>
+ServiceWorkerProviderHostRegistry::GetProviderHostIterator() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ return make_scoped_ptr(new Iterator(&providers_));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698