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

Side by Side Diff: content/browser/devtools/embedded_worker_devtools_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698