| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "content/browser/shared_worker/shared_worker_instance.h" | 14 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 class DevToolsAgentHost; | 19 class DevToolsAgentHost; |
| 20 class DevToolsTarget; |
| 20 class ServiceWorkerContextCore; | 21 class ServiceWorkerContextCore; |
| 21 | 22 |
| 22 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when | 23 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when |
| 23 // "enable-embedded-shared-worker" flag is set. | 24 // "enable-embedded-shared-worker" flag is set. |
| 24 // This class lives on UI thread. | 25 // This class lives on UI thread. |
| 25 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { | 26 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { |
| 26 public: | 27 public: |
| 27 typedef std::pair<int, int> WorkerId; | 28 typedef std::pair<int, int> WorkerId; |
| 28 class EmbeddedWorkerDevToolsAgentHost; | |
| 29 | 29 |
| 30 class ServiceWorkerIdentifier { | 30 class ServiceWorkerIdentifier { |
| 31 public: | 31 public: |
| 32 ServiceWorkerIdentifier( | 32 ServiceWorkerIdentifier( |
| 33 const ServiceWorkerContextCore* const service_worker_context, | 33 const ServiceWorkerContextCore* const service_worker_context, |
| 34 int64 service_worker_version_id); | 34 int64 service_worker_version_id); |
| 35 explicit ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); | 35 explicit ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); |
| 36 ~ServiceWorkerIdentifier() {} | 36 ~ServiceWorkerIdentifier() {} |
| 37 | 37 |
| 38 bool Matches(const ServiceWorkerIdentifier& other) const; | 38 bool Matches(const ServiceWorkerIdentifier& other) const; |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 friend class EmbeddedWorkerDevToolsManager; |
| 41 const ServiceWorkerContextCore* const service_worker_context_; | 42 const ServiceWorkerContextCore* const service_worker_context_; |
| 42 const int64 service_worker_version_id_; | 43 const int64 service_worker_version_id_; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 // Returns the EmbeddedWorkerDevToolsManager singleton. | 46 // Returns the EmbeddedWorkerDevToolsManager singleton. |
| 46 static EmbeddedWorkerDevToolsManager* GetInstance(); | 47 static EmbeddedWorkerDevToolsManager* GetInstance(); |
| 47 | 48 |
| 48 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | 49 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
| 49 int worker_route_id); | 50 int worker_route_id); |
| 50 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( | 51 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( |
| 51 const ServiceWorkerIdentifier& service_worker_id); | 52 const ServiceWorkerIdentifier& service_worker_id); |
| 52 | 53 |
| 54 std::vector<DevToolsTarget*> GetAllServiceWorkerTargets(); |
| 55 |
| 53 // Returns true when the worker must be paused on start because a DevTool | 56 // Returns true when the worker must be paused on start because a DevTool |
| 54 // window for the same former SharedWorkerInstance is still opened. | 57 // window for the same former SharedWorkerInstance is still opened. |
| 55 bool SharedWorkerCreated(int worker_process_id, | 58 bool SharedWorkerCreated(int worker_process_id, |
| 56 int worker_route_id, | 59 int worker_route_id, |
| 57 const SharedWorkerInstance& instance); | 60 const SharedWorkerInstance& instance); |
| 58 // Returns true when the worker must be paused on start because a DevTool | 61 // Returns true when the worker must be paused on start because a DevTool |
| 59 // window for the same former ServiceWorkerIdentifier is still opened or | 62 // window for the same former ServiceWorkerIdentifier is still opened or |
| 60 // debug-on-start is enabled in chrome://serviceworker-internals. | 63 // debug-on-start is enabled in chrome://serviceworker-internals. |
| 61 bool ServiceWorkerCreated(int worker_process_id, | 64 bool ServiceWorkerCreated(int worker_process_id, |
| 62 int worker_route_id, | 65 int worker_route_id, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); | 81 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); |
| 79 | 82 |
| 80 enum WorkerState { | 83 enum WorkerState { |
| 81 WORKER_UNINSPECTED, | 84 WORKER_UNINSPECTED, |
| 82 WORKER_INSPECTED, | 85 WORKER_INSPECTED, |
| 83 WORKER_TERMINATED, | 86 WORKER_TERMINATED, |
| 84 WORKER_PAUSED_FOR_DEBUG_ON_START, | 87 WORKER_PAUSED_FOR_DEBUG_ON_START, |
| 85 WORKER_PAUSED_FOR_REATTACH, | 88 WORKER_PAUSED_FOR_REATTACH, |
| 86 }; | 89 }; |
| 87 | 90 |
| 91 class EmbeddedWorkerDevToolsAgentHost; |
| 92 |
| 88 class WorkerInfo { | 93 class WorkerInfo { |
| 89 public: | 94 public: |
| 90 // Creates WorkerInfo for SharedWorker. | 95 // Creates WorkerInfo for SharedWorker. |
| 91 explicit WorkerInfo(const SharedWorkerInstance& instance); | 96 explicit WorkerInfo(const SharedWorkerInstance& instance); |
| 92 // Creates WorkerInfo for ServiceWorker. | 97 // Creates WorkerInfo for ServiceWorker. |
| 93 explicit WorkerInfo(const ServiceWorkerIdentifier& service_worker_id); | 98 explicit WorkerInfo(const ServiceWorkerIdentifier& service_worker_id); |
| 94 ~WorkerInfo(); | 99 ~WorkerInfo(); |
| 95 | 100 |
| 96 WorkerState state() { return state_; } | 101 WorkerState state() { return state_; } |
| 97 void set_state(WorkerState new_state) { state_ = new_state; } | 102 void set_state(WorkerState new_state) { state_ = new_state; } |
| 98 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | 103 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } |
| 99 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { | 104 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { |
| 100 agent_host_ = agent_host; | 105 agent_host_ = agent_host; |
| 101 } | 106 } |
| 102 bool Matches(const SharedWorkerInstance& other); | 107 bool Matches(const SharedWorkerInstance& other); |
| 103 bool Matches(const ServiceWorkerIdentifier& other); | 108 bool Matches(const ServiceWorkerIdentifier& other); |
| 109 ServiceWorkerIdentifier* service_worker_id() { |
| 110 return service_worker_id_.get(); |
| 111 } |
| 104 | 112 |
| 105 private: | 113 private: |
| 106 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; | 114 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; |
| 107 scoped_ptr<ServiceWorkerIdentifier> service_worker_id_; | 115 scoped_ptr<ServiceWorkerIdentifier> service_worker_id_; |
| 108 WorkerState state_; | 116 WorkerState state_; |
| 109 EmbeddedWorkerDevToolsAgentHost* agent_host_; | 117 EmbeddedWorkerDevToolsAgentHost* agent_host_; |
| 110 }; | 118 }; |
| 111 | 119 |
| 120 class ServiceWorkerTarget; |
| 121 |
| 112 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | 122 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
| 113 | 123 |
| 114 EmbeddedWorkerDevToolsManager(); | 124 EmbeddedWorkerDevToolsManager(); |
| 115 virtual ~EmbeddedWorkerDevToolsManager(); | 125 virtual ~EmbeddedWorkerDevToolsManager(); |
| 116 | 126 |
| 117 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); | 127 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); |
| 118 | 128 |
| 119 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( | 129 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( |
| 120 const SharedWorkerInstance& instance); | 130 const SharedWorkerInstance& instance); |
| 121 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( | 131 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( |
| 122 const ServiceWorkerIdentifier& service_worker_id); | 132 const ServiceWorkerIdentifier& service_worker_id); |
| 123 | 133 |
| 124 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); | 134 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); |
| 125 | 135 |
| 136 EmbeddedWorkerDevToolsAgentHost* GetOrCreateAgentHost(int worker_process_id, |
| 137 int worker_route_id); |
| 138 bool CloseServiceWorker(const WorkerId& id); |
| 139 |
| 126 // Resets to its initial state as if newly created. | 140 // Resets to its initial state as if newly created. |
| 127 void ResetForTesting(); | 141 void ResetForTesting(); |
| 128 | 142 |
| 129 WorkerInfoMap workers_; | 143 WorkerInfoMap workers_; |
| 130 | 144 |
| 131 bool debug_service_worker_on_start_; | 145 bool debug_service_worker_on_start_; |
| 132 | 146 |
| 133 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); | 147 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); |
| 134 }; | 148 }; |
| 135 | 149 |
| 136 } // namespace content | 150 } // namespace content |
| 137 | 151 |
| 138 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 152 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
| OLD | NEW |