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

Unified Diff: content/browser/service_worker/embedded_worker_registry.h

Issue 85023003: EmbeddedWorker, browser side code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 1 month 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/embedded_worker_registry.h
diff --git a/content/browser/service_worker/embedded_worker_registry.h b/content/browser/service_worker/embedded_worker_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..7c13a5008158c6160ea80058fef80888d8e96bcc
--- /dev/null
+++ b/content/browser/service_worker/embedded_worker_registry.h
@@ -0,0 +1,75 @@
+// Copyright 2013 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.
+
+#ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
+#define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+
+class GURL;
+
+namespace IPC {
+class Message;
+class Sender;
+}
+
+namespace content {
+
+class EmbeddedWorkerInstance;
+class ServiceWorkerContextCore;
+
+// Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance,
+// which sends/receives messages to/from each EmbeddedWorker in child process.
+//
+// Hangs off ServiceWorkerContextCore (its reference is also held by each
+// EmbeddedWorkerInstance). Operated only on IO thread.
+class EmbeddedWorkerRegistry
+ : public base::RefCounted<EmbeddedWorkerRegistry> {
+ public:
+ explicit EmbeddedWorkerRegistry(
+ base::WeakPtr<ServiceWorkerContextCore> context);
+
+ // Creates and removes a new worker instance entry for bookkeeping.
+ // This doesn't actually start or stop the worker.
+ scoped_ptr<EmbeddedWorkerInstance> CreateWorker();
+ void RemoveWorker(int embedded_worker_id);
+
+ // Called from EmbeddedWorkerInstance, relayed to the child process.
+ bool StartWorker(int process_id,
+ int embedded_worker_id,
+ int64 service_worker_version_id,
+ const GURL& script_url);
+ bool StopWorker(int process_id,
+ int embedded_worker_id);
+
+ // Keeps a map from process_id to sender information.
+ void AddChildProcessSender(int process_id, IPC::Sender* sender);
+ void RemoveChildProcessSender(int process_id);
+
+ private:
+ friend class RefCounted<EmbeddedWorkerRegistry>;
+
+ ~EmbeddedWorkerRegistry();
+ bool Send(int process_id, IPC::Message* message);
+
+ typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap;
+ typedef std::map<int, IPC::Sender*> ProcessToSenderMap;
+
+ base::WeakPtr<ServiceWorkerContextCore> context_;
+
+ WorkerInstanceMap worker_map_;
+ ProcessToSenderMap process_sender_map_;
+
+ int next_embedded_worker_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698