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

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.h

Issue 140893002: Adding slightly clearer separation between SW and EmbeddedWorker (still incomplete) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 #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 17
18 class GURL; 18 class GURL;
19 19
20 namespace IPC {
21 class Message;
22 }
23
20 namespace content { 24 namespace content {
21 25
22 class EmbeddedWorkerRegistry; 26 class EmbeddedWorkerRegistry;
23 struct ServiceWorkerFetchRequest; 27 struct ServiceWorkerFetchRequest;
24 28
25 // This gives an interface to control one EmbeddedWorker instance, which 29 // This gives an interface to control one EmbeddedWorker instance, which
26 // may be 'in-waiting' or running in one of the child processes added by 30 // may be 'in-waiting' or running in one of the child processes added by
27 // AddProcessReference(). 31 // AddProcessReference().
28 class CONTENT_EXPORT EmbeddedWorkerInstance { 32 class CONTENT_EXPORT EmbeddedWorkerInstance {
29 public: 33 public:
30 enum Status { 34 enum Status {
31 STOPPED, 35 STOPPED,
32 STARTING, 36 STARTING,
33 RUNNING, 37 RUNNING,
34 STOPPING, 38 STOPPING,
35 }; 39 };
36 40
37 class Observer { 41 class Observer {
38 public: 42 public:
39 virtual ~Observer() {} 43 virtual ~Observer() {}
40 virtual void OnStarted() = 0; 44 virtual void OnStarted() = 0;
41 virtual void OnStopped() = 0; 45 virtual void OnStopped() = 0;
46 virtual void OnMessageReceived(const IPC::Message& message) = 0;
42 }; 47 };
43 48
44 ~EmbeddedWorkerInstance(); 49 ~EmbeddedWorkerInstance();
45 50
46 // Starts the worker. It is invalid to call this when the worker is 51 // Starts the worker. It is invalid to call this when the worker is
47 // not in STOPPED status. 52 // not in STOPPED status.
48 // This returns false if starting a worker fails immediately, e.g. when 53 // This returns false if starting a worker fails immediately, e.g. when
49 // IPC couldn't be sent to the worker or no process was available. 54 // IPC couldn't be sent to the worker or no process was available.
50 bool Start(int64 service_worker_version_id, 55 bool Start(int64 service_worker_version_id,
51 const GURL& script_url); 56 const GURL& script_url);
52 57
53 // Stops the worker. It is invalid to call this when the worker is 58 // Stops the worker. It is invalid to call this when the worker is
54 // not in STARTING or RUNNING status. 59 // not in STARTING or RUNNING status.
55 // This returns false if stopping a worker fails immediately, e.g. when 60 // This returns false if stopping a worker fails immediately, e.g. when
56 // IPC couldn't be sent to the worker. 61 // IPC couldn't be sent to the worker.
57 bool Stop(); 62 bool Stop();
58 63
59 // Sends |request| to the embedded worker running in the child process. 64 // Sends |message| to the embedded worker running in the child process.
60 // This returns false if sending IPC fails. 65 // This returns false if sending IPC fails.
61 // It is invalid to call this while the worker is not in RUNNING status. 66 // It is invalid to call this while the worker is not in RUNNING status.
62 bool SendFetchRequest(const ServiceWorkerFetchRequest& request); 67 bool SendMessage(const IPC::Message& message);
63 68
64 // Add or remove |process_id| to the internal process set where this 69 // Add or remove |process_id| to the internal process set where this
65 // worker can be started. 70 // worker can be started.
66 void AddProcessReference(int process_id); 71 void AddProcessReference(int process_id);
67 void ReleaseProcessReference(int process_id); 72 void ReleaseProcessReference(int process_id);
68 73
69 int embedded_worker_id() const { return embedded_worker_id_; } 74 int embedded_worker_id() const { return embedded_worker_id_; }
70 Status status() const { return status_; } 75 Status status() const { return status_; }
71 int process_id() const { return process_id_; } 76 int process_id() const { return process_id_; }
72 int thread_id() const { return thread_id_; } 77 int thread_id() const { return thread_id_; }
(...skipping 17 matching lines...) Expand all
90 // child process. 95 // child process.
91 // This will change the internal status from STARTING to RUNNING. 96 // This will change the internal status from STARTING to RUNNING.
92 void OnStarted(int thread_id); 97 void OnStarted(int thread_id);
93 98
94 // Called back from Registry when the worker instance has ack'ed that 99 // Called back from Registry when the worker instance has ack'ed that
95 // its WorkerGlobalScope is actually stopped in the child process. 100 // its WorkerGlobalScope is actually stopped in the child process.
96 // This will change the internal status from STARTING or RUNNING to 101 // This will change the internal status from STARTING or RUNNING to
97 // STOPPED. 102 // STOPPED.
98 void OnStopped(); 103 void OnStopped();
99 104
105 // Called back from Registry when the worker instance sends message
106 // to the browser (i.e. EmbeddedWorker observers).
107 void OnMessageReceived(const IPC::Message& message);
108
100 // Chooses a process to start this worker and populate process_id_. 109 // Chooses a process to start this worker and populate process_id_.
101 // Returns false when no process is available. 110 // Returns false when no process is available.
102 bool ChooseProcess(); 111 bool ChooseProcess();
103 112
104 scoped_refptr<EmbeddedWorkerRegistry> registry_; 113 scoped_refptr<EmbeddedWorkerRegistry> registry_;
105 const int embedded_worker_id_; 114 const int embedded_worker_id_;
106 Status status_; 115 Status status_;
107 116
108 // Current running information. -1 indicates the worker is not running. 117 // Current running information. -1 indicates the worker is not running.
109 int process_id_; 118 int process_id_;
110 int thread_id_; 119 int thread_id_;
111 120
112 ProcessRefMap process_refs_; 121 ProcessRefMap process_refs_;
113 ObserverList<Observer> observer_list_; 122 ObserverList<Observer> observer_list_;
114 123
115 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 124 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
116 }; 125 };
117 126
118 } // namespace content 127 } // namespace content
119 128
120 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 129 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698