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

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

Issue 962543005: Service Worker: Add metrics and timeout for starting a Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review Created 5 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
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 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 class CONTENT_EXPORT EmbeddedWorkerInstance { 46 class CONTENT_EXPORT EmbeddedWorkerInstance {
47 public: 47 public:
48 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; 48 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
49 enum Status { 49 enum Status {
50 STOPPED, 50 STOPPED,
51 STARTING, 51 STARTING,
52 RUNNING, 52 RUNNING,
53 STOPPING, 53 STOPPING,
54 }; 54 };
55 55
56 enum StartingPhase {
57 NOT_STARTING,
58 ALLOCATE_PROCESS,
59 REGISTER_TO_DEVTOOLS,
60 SEND_START_WORKER,
61 SCRIPT_DOWNLOAD,
62 SCRIPT_LOADED,
63 SCRIPT_EVALUATED,
64 STARTING_PHASE_MAX_VALUE,
65 };
66
56 class Listener { 67 class Listener {
57 public: 68 public:
58 virtual ~Listener() {} 69 virtual ~Listener() {}
59 virtual void OnScriptLoaded() {} 70 virtual void OnScriptLoaded() {}
60 virtual void OnStarted() {} 71 virtual void OnStarted() {}
61 virtual void OnStopped(Status old_status) {} 72 virtual void OnStopped(Status old_status) {}
62 virtual void OnPausedAfterDownload() {} 73 virtual void OnPausedAfterDownload() {}
63 virtual void OnReportException(const base::string16& error_message, 74 virtual void OnReportException(const base::string16& error_message,
64 int line_number, 75 int line_number,
65 int column_number, 76 int column_number,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 110
100 // Sends |message| to the embedded worker running in the child process. 111 // Sends |message| to the embedded worker running in the child process.
101 // It is invalid to call this while the worker is not in STARTING or RUNNING 112 // It is invalid to call this while the worker is not in STARTING or RUNNING
102 // status. 113 // status.
103 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); 114 ServiceWorkerStatusCode SendMessage(const IPC::Message& message);
104 115
105 void ResumeAfterDownload(); 116 void ResumeAfterDownload();
106 117
107 int embedded_worker_id() const { return embedded_worker_id_; } 118 int embedded_worker_id() const { return embedded_worker_id_; }
108 Status status() const { return status_; } 119 Status status() const { return status_; }
120 StartingPhase starting_phase() const {
121 DCHECK_EQ(STARTING, status());
122 return starting_phase_;
123 }
109 int process_id() const { return process_id_; } 124 int process_id() const { return process_id_; }
110 int thread_id() const { return thread_id_; } 125 int thread_id() const { return thread_id_; }
111 int worker_devtools_agent_route_id() const; 126 int worker_devtools_agent_route_id() const;
112 MessagePortMessageFilter* message_port_message_filter() const; 127 MessagePortMessageFilter* message_port_message_filter() const;
113 128
114 void AddListener(Listener* listener); 129 void AddListener(Listener* listener);
115 void RemoveListener(Listener* listener); 130 void RemoveListener(Listener* listener);
116 131
117 void set_devtools_attached(bool attached) { devtools_attached_ = attached; } 132 void set_devtools_attached(bool attached) { devtools_attached_ = attached; }
133 bool devtools_attached() const { return devtools_attached_; }
118 134
119 // Called when the script load request accessed the network. 135 // Called when the script load request accessed the network.
120 void OnNetworkAccessedForScriptLoad(); 136 void OnNetworkAccessedForScriptLoad();
121 137
138 static std::string StatusToString(Status status);
139 static std::string StartingPhaseToString(StartingPhase phase);
140
122 private: 141 private:
123 typedef ObserverList<Listener> ListenerList; 142 typedef ObserverList<Listener> ListenerList;
124 class DevToolsProxy; 143 class DevToolsProxy;
125 friend class EmbeddedWorkerRegistry; 144 friend class EmbeddedWorkerRegistry;
126 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); 145 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop);
127 146
128 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). 147 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker().
129 // This instance holds a ref of |registry|. 148 // This instance holds a ref of |registry|.
130 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, 149 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context,
131 int embedded_worker_id); 150 int embedded_worker_id);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void OnReportConsoleMessage(int source_identifier, 214 void OnReportConsoleMessage(int source_identifier,
196 int message_level, 215 int message_level,
197 const base::string16& message, 216 const base::string16& message,
198 int line_number, 217 int line_number,
199 const GURL& source_url); 218 const GURL& source_url);
200 219
201 base::WeakPtr<ServiceWorkerContextCore> context_; 220 base::WeakPtr<ServiceWorkerContextCore> context_;
202 scoped_refptr<EmbeddedWorkerRegistry> registry_; 221 scoped_refptr<EmbeddedWorkerRegistry> registry_;
203 const int embedded_worker_id_; 222 const int embedded_worker_id_;
204 Status status_; 223 Status status_;
224 StartingPhase starting_phase_;
205 225
206 // Current running information. -1 indicates the worker is not running. 226 // Current running information. -1 indicates the worker is not running.
207 int process_id_; 227 int process_id_;
208 int thread_id_; 228 int thread_id_;
209 229
210 // Whether devtools is attached or not. 230 // Whether devtools is attached or not.
211 bool devtools_attached_; 231 bool devtools_attached_;
212 232
213 // True if the script load request accessed the network. If the script was 233 // True if the script load request accessed the network. If the script was
214 // served from HTTPCache or ServiceWorkerDatabase this value is false. 234 // served from HTTPCache or ServiceWorkerDatabase this value is false.
215 bool network_accessed_for_script_; 235 bool network_accessed_for_script_;
216 236
217 StatusCallback start_callback_; 237 StatusCallback start_callback_;
218 ListenerList listener_list_; 238 ListenerList listener_list_;
219 scoped_ptr<DevToolsProxy> devtools_proxy_; 239 scoped_ptr<DevToolsProxy> devtools_proxy_;
220 240
221 base::TimeTicks start_timing_; 241 base::TimeTicks start_timing_;
222 242
223 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; 243 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
224 244
225 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 245 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
226 }; 246 };
227 247
228 } // namespace content 248 } // namespace content
229 249
230 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 250 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698