| 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/common/service_worker/service_worker_status_code.h" |
| 17 | 18 |
| 18 class GURL; | 19 class GURL; |
| 19 | 20 |
| 20 namespace IPC { | 21 namespace IPC { |
| 21 class Message; | 22 class Message; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 class EmbeddedWorkerRegistry; | 27 class EmbeddedWorkerRegistry; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 virtual ~Observer() {} | 44 virtual ~Observer() {} |
| 44 virtual void OnStarted() = 0; | 45 virtual void OnStarted() = 0; |
| 45 virtual void OnStopped() = 0; | 46 virtual void OnStopped() = 0; |
| 46 virtual void OnMessageReceived(const IPC::Message& message) = 0; | 47 virtual void OnMessageReceived(const IPC::Message& message) = 0; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 ~EmbeddedWorkerInstance(); | 50 ~EmbeddedWorkerInstance(); |
| 50 | 51 |
| 51 // Starts the worker. It is invalid to call this when the worker is | 52 // Starts the worker. It is invalid to call this when the worker is |
| 52 // not in STOPPED status. | 53 // not in STOPPED status. |
| 53 // This returns false if starting a worker fails immediately, e.g. when | 54 ServiceWorkerStatusCode Start(int64 service_worker_version_id, |
| 54 // IPC couldn't be sent to the worker or no process was available. | 55 const GURL& script_url); |
| 55 bool Start(int64 service_worker_version_id, | |
| 56 const GURL& script_url); | |
| 57 | 56 |
| 58 // Stops the worker. It is invalid to call this when the worker is | 57 // Stops the worker. It is invalid to call this when the worker is |
| 59 // not in STARTING or RUNNING status. | 58 // not in STARTING or RUNNING status. |
| 60 // This returns false if stopping a worker fails immediately, e.g. when | 59 // This returns false if stopping a worker fails immediately, e.g. when |
| 61 // IPC couldn't be sent to the worker. | 60 // IPC couldn't be sent to the worker. |
| 62 bool Stop(); | 61 ServiceWorkerStatusCode Stop(); |
| 63 | 62 |
| 64 // Sends |message| to the embedded worker running in the child process. | 63 // Sends |message| to the embedded worker running in the child process. |
| 65 // This returns false if sending IPC fails. | |
| 66 // It is invalid to call this while the worker is not in RUNNING status. | 64 // It is invalid to call this while the worker is not in RUNNING status. |
| 67 bool SendMessage(const IPC::Message& message); | 65 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); |
| 68 | 66 |
| 69 // Add or remove |process_id| to the internal process set where this | 67 // Add or remove |process_id| to the internal process set where this |
| 70 // worker can be started. | 68 // worker can be started. |
| 71 void AddProcessReference(int process_id); | 69 void AddProcessReference(int process_id); |
| 72 void ReleaseProcessReference(int process_id); | 70 void ReleaseProcessReference(int process_id); |
| 73 | 71 |
| 74 int embedded_worker_id() const { return embedded_worker_id_; } | 72 int embedded_worker_id() const { return embedded_worker_id_; } |
| 75 Status status() const { return status_; } | 73 Status status() const { return status_; } |
| 76 int process_id() const { return process_id_; } | 74 int process_id() const { return process_id_; } |
| 77 int thread_id() const { return thread_id_; } | 75 int thread_id() const { return thread_id_; } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 118 |
| 121 ProcessRefMap process_refs_; | 119 ProcessRefMap process_refs_; |
| 122 ObserverList<Observer> observer_list_; | 120 ObserverList<Observer> observer_list_; |
| 123 | 121 |
| 124 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 122 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 125 }; | 123 }; |
| 126 | 124 |
| 127 } // namespace content | 125 } // namespace content |
| 128 | 126 |
| 129 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 127 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |