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

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

Issue 188283003: Add ServiceWorkerVersion::status() (which is to be persisted unlike running status) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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_SERVICE_WORKER_VERSION_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), 62 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>),
63 public EmbeddedWorkerInstance::Observer { 63 public EmbeddedWorkerInstance::Observer {
64 public: 64 public:
65 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; 65 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
66 typedef base::Callback<void(ServiceWorkerStatusCode, 66 typedef base::Callback<void(ServiceWorkerStatusCode,
67 const IPC::Message& message)> MessageCallback; 67 const IPC::Message& message)> MessageCallback;
68 typedef base::Callback<void(ServiceWorkerStatusCode, 68 typedef base::Callback<void(ServiceWorkerStatusCode,
69 const ServiceWorkerFetchResponse& response)> 69 const ServiceWorkerFetchResponse& response)>
70 FetchCallback; 70 FetchCallback;
71 71
72 enum Status { 72 enum RunningStatus {
73 STOPPED = EmbeddedWorkerInstance::STOPPED, 73 STOPPED = EmbeddedWorkerInstance::STOPPED,
74 STARTING = EmbeddedWorkerInstance::STARTING, 74 STARTING = EmbeddedWorkerInstance::STARTING,
75 RUNNING = EmbeddedWorkerInstance::RUNNING, 75 RUNNING = EmbeddedWorkerInstance::RUNNING,
76 STOPPING = EmbeddedWorkerInstance::STOPPING, 76 STOPPING = EmbeddedWorkerInstance::STOPPING,
77 }; 77 };
78 78
79 // Current version status; this status should be persisted unlike
80 // running status. Note that this class doesn't change status on its own,
81 // consumers of this class should explicitly set a new status by
82 // set_status().
83 enum Status {
84 NEW, // Just created but installation is not finished.
85 WAITING, // Installation is finished and is ready to be activated.
86 ACTIVE, // Activation is finished and can run as active.
michaeln 2014/03/06 19:49:54 Is there a state following ACTIVE to represent the
87 };
88
79 ServiceWorkerVersion( 89 ServiceWorkerVersion(
80 ServiceWorkerRegistration* registration, 90 ServiceWorkerRegistration* registration,
81 EmbeddedWorkerRegistry* worker_registry, 91 EmbeddedWorkerRegistry* worker_registry,
82 int64 version_id); 92 int64 version_id,
93 Status status);
83 94
84 int64 version_id() const { return version_id_; } 95 int64 version_id() const { return version_id_; }
85 96
86 void Shutdown(); 97 void Shutdown();
87 bool is_shutdown() const { return is_shutdown_; } 98 bool is_shutdown() const { return is_shutdown_; }
88 99
89 Status status() const { 100 RunningStatus running_status() const {
90 return static_cast<Status>(embedded_worker_->status()); 101 return static_cast<RunningStatus>(embedded_worker_->status());
91 } 102 }
92 103
104 Status status() const { return status_; }
105 void set_status(Status status) { status_ = status; }
106
93 // Starts an embedded worker for this version. 107 // Starts an embedded worker for this version.
94 // This returns OK (success) if the worker is already running. 108 // This returns OK (success) if the worker is already running.
95 void StartWorker(const StatusCallback& callback); 109 void StartWorker(const StatusCallback& callback);
96 110
97 // Starts an embedded worker for this version. 111 // Starts an embedded worker for this version.
98 // This returns OK (success) if the worker is already stopped. 112 // This returns OK (success) if the worker is already stopped.
99 void StopWorker(const StatusCallback& callback); 113 void StopWorker(const StatusCallback& callback);
100 114
101 // Sends an IPC message to the worker. 115 // Sends an IPC message to the worker.
102 // If the worker is not running this first tries to start it by 116 // If the worker is not running this first tries to start it by
(...skipping 11 matching lines...) Expand all
114 // If the worker is not running this first tries to start it by 128 // If the worker is not running this first tries to start it by
115 // calling StartWorker internally. 129 // calling StartWorker internally.
116 void SendMessageAndRegisterCallback(const IPC::Message& message, 130 void SendMessageAndRegisterCallback(const IPC::Message& message,
117 const MessageCallback& callback); 131 const MessageCallback& callback);
118 132
119 // Sends install event to the associated embedded worker and asynchronously 133 // Sends install event to the associated embedded worker and asynchronously
120 // calls |callback| when it errors out or it gets response from the worker 134 // calls |callback| when it errors out or it gets response from the worker
121 // to notify install completion. 135 // to notify install completion.
122 // |active_version_embedded_worker_id| must be a valid positive ID 136 // |active_version_embedded_worker_id| must be a valid positive ID
123 // if there's an active (previous) version running. 137 // if there's an active (previous) version running.
138 // Calling this while status is not NEW is not valid; will error out with
139 // SERVICE_WORKER_ERROR_FAILED.
124 void DispatchInstallEvent(int active_version_embedded_worker_id, 140 void DispatchInstallEvent(int active_version_embedded_worker_id,
125 const StatusCallback& callback); 141 const StatusCallback& callback);
126 142
127 // Sends fetch event to the associated embedded worker and calls 143 // Sends fetch event to the associated embedded worker and calls
128 // |callback| with the response from the worker. 144 // |callback| with the response from the worker.
145 // Calling this while status is not ACTIVE is not valid; will error out with
146 // SERVICE_WORKER_ERROR_FAILED.
129 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, 147 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request,
130 const FetchCallback& callback); 148 const FetchCallback& callback);
131 149
132 // These are expected to be called when a renderer process host for the 150 // These are expected to be called when a renderer process host for the
133 // same-origin as for this ServiceWorkerVersion is created. The added 151 // same-origin as for this ServiceWorkerVersion is created. The added
134 // processes are used to run an in-renderer embedded worker. 152 // processes are used to run an in-renderer embedded worker.
135 void AddProcessToWorker(int process_id); 153 void AddProcessToWorker(int process_id);
136 void RemoveProcessToWorker(int process_id); 154 void RemoveProcessToWorker(int process_id);
137 155
138 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } 156 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); }
139 157
140 // EmbeddedWorkerInstance::Observer overrides: 158 // EmbeddedWorkerInstance::Observer overrides:
141 virtual void OnStarted() OVERRIDE; 159 virtual void OnStarted() OVERRIDE;
142 virtual void OnStopped() OVERRIDE; 160 virtual void OnStopped() OVERRIDE;
143 virtual void OnMessageReceived(int request_id, 161 virtual void OnMessageReceived(int request_id,
144 const IPC::Message& message) OVERRIDE; 162 const IPC::Message& message) OVERRIDE;
145 163
146 private: 164 private:
147 typedef ServiceWorkerVersion self; 165 typedef ServiceWorkerVersion self;
148 friend class base::RefCounted<ServiceWorkerVersion>; 166 friend class base::RefCounted<ServiceWorkerVersion>;
149 167
150 virtual ~ServiceWorkerVersion(); 168 virtual ~ServiceWorkerVersion();
151 169
152 const int64 version_id_; 170 const int64 version_id_;
153 171
172 Status status_;
173
154 bool is_shutdown_; 174 bool is_shutdown_;
155 scoped_refptr<ServiceWorkerRegistration> registration_; 175 scoped_refptr<ServiceWorkerRegistration> registration_;
156 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; 176 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
157 177
158 // Pending callbacks. 178 // Pending callbacks.
159 std::vector<StatusCallback> start_callbacks_; 179 std::vector<StatusCallback> start_callbacks_;
160 std::vector<StatusCallback> stop_callbacks_; 180 std::vector<StatusCallback> stop_callbacks_;
161 181
162 IDMap<MessageCallback, IDMapOwnPointer> message_callbacks_; 182 IDMap<MessageCallback, IDMapOwnPointer> message_callbacks_;
163 183
164 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 184 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
165 185
166 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 186 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
167 }; 187 };
168 188
169 } // namespace content 189 } // namespace content
170 190
171 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 191 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698