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

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

Issue 145033012: Make ServiceWorkerVersion::{Start,Stop}Worker take callback (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_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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h"
9 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "content/browser/service_worker/embedded_worker_instance.h"
12 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/common/service_worker/service_worker_status_code.h"
13 16
14 class GURL; 17 class GURL;
15 18
16 namespace content { 19 namespace content {
17 20
18 class EmbeddedWorkerInstance;
19 class EmbeddedWorkerRegistry; 21 class EmbeddedWorkerRegistry;
20 class ServiceWorkerProviderHost; 22 class ServiceWorkerProviderHost;
21 class ServiceWorkerRegistration; 23 class ServiceWorkerRegistration;
22 struct ServiceWorkerFetchRequest; 24 struct ServiceWorkerFetchRequest;
23 25
24 // This class corresponds to a specific version of a ServiceWorker 26 // This class corresponds to a specific version of a ServiceWorker
25 // script for a given pattern. When a script is upgraded, there may be 27 // script for a given pattern. When a script is upgraded, there may be
26 // more than one ServiceWorkerVersion "running" at a time, but only 28 // more than one ServiceWorkerVersion "running" at a time, but only
27 // one of them is active. This class connects the actual script with a 29 // one of them is active. This class connects the actual script with a
28 // running worker. 30 // running worker.
(...skipping 20 matching lines...) Expand all
49 // events. During the Active state, it can receive other events such 51 // events. During the Active state, it can receive other events such
50 // as 'fetch'. 52 // as 'fetch'.
51 // 53 //
52 // And finally, is_shutdown_ is detects the live-ness of the object 54 // And finally, is_shutdown_ is detects the live-ness of the object
53 // itself. If the object is shut down, then it is in the process of 55 // itself. If the object is shut down, then it is in the process of
54 // being deleted from memory. This happens when a version is replaced 56 // being deleted from memory. This happens when a version is replaced
55 // as well as at browser shutdown. 57 // as well as at browser shutdown.
56 class CONTENT_EXPORT ServiceWorkerVersion 58 class CONTENT_EXPORT ServiceWorkerVersion
57 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>) { 59 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>) {
58 public: 60 public:
61 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
62
63 enum Status {
64 STOPPED = EmbeddedWorkerInstance::STOPPED,
65 STARTING = EmbeddedWorkerInstance::STARTING,
66 RUNNING = EmbeddedWorkerInstance::RUNNING,
67 STOPPING = EmbeddedWorkerInstance::STOPPING,
68 };
69
59 ServiceWorkerVersion( 70 ServiceWorkerVersion(
60 ServiceWorkerRegistration* registration, 71 ServiceWorkerRegistration* registration,
61 EmbeddedWorkerRegistry* worker_registry, 72 EmbeddedWorkerRegistry* worker_registry,
62 int64 version_id); 73 int64 version_id);
63 74
64 int64 version_id() const { return version_id_; } 75 int64 version_id() const { return version_id_; }
65 76
66 void Shutdown(); 77 void Shutdown();
67 bool is_shutdown() const { return is_shutdown_; } 78 bool is_shutdown() const { return is_shutdown_; }
68 79
69 // Starts and stops an embedded worker for this version. 80 Status status() const {
70 void StartWorker(); 81 return static_cast<Status>(embedded_worker_->status());
71 void StopWorker(); 82 }
83
84 // Starts an embedded worker for this version.
85 // It is not valid to call this while there's other inflight start or
86 // stop process running.
87 // This returns OK (success) if the worker is already running.
88 void StartWorker(const StatusCallback& callback);
89
90 // Starts an embedded worker for this version.
91 // It is not valid to call this while there's other inflight start or
92 // stop process running.
93 // This returns OK (success) if the worker is already stopped.
94 void StopWorker(const StatusCallback& callback);
72 95
73 // Sends fetch event to the associated embedded worker. 96 // Sends fetch event to the associated embedded worker.
74 // This immediately returns false if the worker is not running 97 // This immediately returns false if the worker is not running
75 // or sending a message to the child process fails. 98 // or sending a message to the child process fails.
99 // TODO(kinuko): Make this take callback as well.
76 bool DispatchFetchEvent(const ServiceWorkerFetchRequest& request); 100 bool DispatchFetchEvent(const ServiceWorkerFetchRequest& request);
77 101
78 // Called when this version is associated to a provider host. 102 // These are expected to be called when a renderer process host for the
79 // Non-null |provider_host| must be given. 103 // same-origin as for this ServiceWorkerVersion is created. The added
80 void OnAssociateProvider(ServiceWorkerProviderHost* provider_host); 104 // processes are used to run an in-renderer embedded worker.
81 void OnUnassociateProvider(ServiceWorkerProviderHost* provider_host); 105 void AddProcessToWorker(int process_id);
106 void RemoveProcessToWorker(int process_id);
107
108 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); }
82 109
83 private: 110 private:
84 friend class base::RefCounted<ServiceWorkerVersion>; 111 friend class base::RefCounted<ServiceWorkerVersion>;
85 112
113 // Embedded worker observer classes.
114 class WorkerObserverBase;
115 class StartObserver;
116 class StopObserver;
117
86 ~ServiceWorkerVersion(); 118 ~ServiceWorkerVersion();
87 119
88 const int64 version_id_; 120 const int64 version_id_;
89 121
90 bool is_shutdown_; 122 bool is_shutdown_;
91 scoped_refptr<ServiceWorkerRegistration> registration_; 123 scoped_refptr<ServiceWorkerRegistration> registration_;
92 124
93 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; 125 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
126 scoped_ptr<EmbeddedWorkerInstance::Observer> observer_;
94 127
95 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 128 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
96 }; 129 };
97 130
98 } // namespace content 131 } // namespace content
99 132
100 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 133 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_browsertest.cc ('k') | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698