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

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

Issue 139923005: Implement ServiceWorkerVersion::SendMessage() (for dispatching events etc) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 6 years, 10 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"
(...skipping 26 matching lines...) Expand all
37 STARTING, 37 STARTING,
38 RUNNING, 38 RUNNING,
39 STOPPING, 39 STOPPING,
40 }; 40 };
41 41
42 class Observer { 42 class Observer {
43 public: 43 public:
44 virtual ~Observer() {} 44 virtual ~Observer() {}
45 virtual void OnStarted() = 0; 45 virtual void OnStarted() = 0;
46 virtual void OnStopped() = 0; 46 virtual void OnStopped() = 0;
47 virtual void OnMessageReceived(const IPC::Message& message) = 0; 47 virtual void OnMessageReceived(int request_id,
48 const IPC::Message& message) = 0;
48 }; 49 };
49 50
50 ~EmbeddedWorkerInstance(); 51 ~EmbeddedWorkerInstance();
51 52
52 // Starts the worker. It is invalid to call this when the worker is 53 // Starts the worker. It is invalid to call this when the worker is
53 // not in STOPPED status. 54 // not in STOPPED status.
54 ServiceWorkerStatusCode Start(int64 service_worker_version_id, 55 ServiceWorkerStatusCode Start(int64 service_worker_version_id,
55 const GURL& script_url); 56 const GURL& script_url);
56 57
57 // 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
58 // not in STARTING or RUNNING status. 59 // not in STARTING or RUNNING status.
59 // 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
60 // IPC couldn't be sent to the worker. 61 // IPC couldn't be sent to the worker.
61 ServiceWorkerStatusCode Stop(); 62 ServiceWorkerStatusCode Stop();
62 63
63 // Sends |message| to the embedded worker running in the child process. 64 // Sends |message| to the embedded worker running in the child process.
64 // It is invalid to call this while the worker is not in RUNNING status. 65 // It is invalid to call this while the worker is not in RUNNING status.
65 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); 66 // |request_id| can be optionally used to establish 2-way request-response
67 // messaging (e.g. the receiver can send back a response using the same
68 // request_id).
69 ServiceWorkerStatusCode SendMessage(
70 int request_id, const IPC::Message& message);
66 71
67 // Add or remove |process_id| to the internal process set where this 72 // Add or remove |process_id| to the internal process set where this
68 // worker can be started. 73 // worker can be started.
69 void AddProcessReference(int process_id); 74 void AddProcessReference(int process_id);
70 void ReleaseProcessReference(int process_id); 75 void ReleaseProcessReference(int process_id);
71 76
72 int embedded_worker_id() const { return embedded_worker_id_; } 77 int embedded_worker_id() const { return embedded_worker_id_; }
73 Status status() const { return status_; } 78 Status status() const { return status_; }
74 int process_id() const { return process_id_; } 79 int process_id() const { return process_id_; }
75 int thread_id() const { return thread_id_; } 80 int thread_id() const { return thread_id_; }
(...skipping 19 matching lines...) Expand all
95 void OnStarted(int thread_id); 100 void OnStarted(int thread_id);
96 101
97 // Called back from Registry when the worker instance has ack'ed that 102 // Called back from Registry when the worker instance has ack'ed that
98 // its WorkerGlobalScope is actually stopped in the child process. 103 // its WorkerGlobalScope is actually stopped in the child process.
99 // This will change the internal status from STARTING or RUNNING to 104 // This will change the internal status from STARTING or RUNNING to
100 // STOPPED. 105 // STOPPED.
101 void OnStopped(); 106 void OnStopped();
102 107
103 // Called back from Registry when the worker instance sends message 108 // Called back from Registry when the worker instance sends message
104 // to the browser (i.e. EmbeddedWorker observers). 109 // to the browser (i.e. EmbeddedWorker observers).
105 void OnMessageReceived(const IPC::Message& message); 110 void OnMessageReceived(int request_id, const IPC::Message& message);
106 111
107 // Chooses a process to start this worker and populate process_id_. 112 // Chooses a process to start this worker and populate process_id_.
108 // Returns false when no process is available. 113 // Returns false when no process is available.
109 bool ChooseProcess(); 114 bool ChooseProcess();
110 115
111 scoped_refptr<EmbeddedWorkerRegistry> registry_; 116 scoped_refptr<EmbeddedWorkerRegistry> registry_;
112 const int embedded_worker_id_; 117 const int embedded_worker_id_;
113 Status status_; 118 Status status_;
114 119
115 // Current running information. -1 indicates the worker is not running. 120 // Current running information. -1 indicates the worker is not running.
116 int process_id_; 121 int process_id_;
117 int thread_id_; 122 int thread_id_;
118 123
119 ProcessRefMap process_refs_; 124 ProcessRefMap process_refs_;
120 ObserverList<Observer> observer_list_; 125 ObserverList<Observer> observer_list_;
121 126
122 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 127 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
123 }; 128 };
124 129
125 } // namespace content 130 } // namespace content
126 131
127 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 132 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698