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