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/files/file_path.h" | |
11 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
13 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
15 #include "content/browser/shared_worker/shared_worker_instance.h" | 14 #include "content/browser/shared_worker/shared_worker_instance.h" |
16 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
17 | 16 |
18 class GURL; | 17 namespace content { |
19 | 18 |
20 namespace content { | |
21 class DevToolsAgentHost; | 19 class DevToolsAgentHost; |
20 class ServiceWorkerContextCore; | |
22 | 21 |
23 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when | 22 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when |
24 // "enable-embedded-shared-worker" flag is set. | 23 // "enable-embedded-shared-worker" flag is set. |
25 // This class lives on UI thread. | 24 // This class lives on UI thread. |
26 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { | 25 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { |
27 public: | 26 public: |
28 typedef std::pair<int, int> WorkerId; | 27 typedef std::pair<int, int> WorkerId; |
29 class EmbeddedWorkerDevToolsAgentHost; | 28 class EmbeddedWorkerDevToolsAgentHost; |
30 | 29 |
31 // Returns the EmbeddedWorkerDevToolsManager singleton. | 30 // Returns the EmbeddedWorkerDevToolsManager singleton. |
32 static EmbeddedWorkerDevToolsManager* GetInstance(); | 31 static EmbeddedWorkerDevToolsManager* GetInstance(); |
33 | 32 |
34 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | 33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
35 int worker_route_id); | 34 int worker_route_id); |
36 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( | 35 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( |
37 const base::FilePath& storage_partition_path, | 36 const ServiceWorkerContextCore* const service_worker_context_core, |
38 const GURL& service_worker_scope); | 37 int64 service_worker_version_id); |
39 | 38 |
40 // Returns true when the worker must be paused on start. | 39 // Returns true when the worker must be paused on start. |
41 bool SharedWorkerCreated(int worker_process_id, | 40 bool SharedWorkerCreated(int worker_process_id, |
42 int worker_route_id, | 41 int worker_route_id, |
43 const SharedWorkerInstance& instance); | 42 const SharedWorkerInstance& instance); |
44 // Returns true when the worker must be paused on start. | 43 // Returns true when the worker must be paused on start. |
45 // TODO(horo): Currently we identify ServiceWorkers with the path of storage | 44 // TODO(horo): Currently we identify ServiceWorkers with the pointer of |
46 // partition and the scope of ServiceWorker. Consider having a class like | 45 // ServiceWorkerContextCore and the version id of ServiceWorker. Consider |
yurys
2014/05/16 13:27:05
It may be a good time to fix this TODO.
horo
2014/05/16 14:43:14
Done.
| |
47 // SharedWorkerInstance instead of the pair. | 46 // having a class like SharedWorkerInstance instead of the pair. |
48 bool ServiceWorkerCreated(int worker_process_id, | 47 bool ServiceWorkerCreated( |
49 int worker_route_id, | 48 int worker_process_id, |
50 const base::FilePath& storage_partition_path, | 49 int worker_route_id, |
51 const GURL& service_worker_scope); | 50 const ServiceWorkerContextCore* const service_worker_context_core, |
51 int64 service_worker_version_id); | |
52 void WorkerContextStarted(int worker_process_id, int worker_route_id); | 52 void WorkerContextStarted(int worker_process_id, int worker_route_id); |
53 void WorkerDestroyed(int worker_process_id, int worker_route_id); | 53 void WorkerDestroyed(int worker_process_id, int worker_route_id); |
54 | 54 |
55 private: | 55 private: |
56 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; | 56 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; |
57 friend class EmbeddedWorkerDevToolsManagerTest; | 57 friend class EmbeddedWorkerDevToolsManagerTest; |
58 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); | 58 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); |
59 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); | 59 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); |
60 | 60 |
61 enum WorkerState { | 61 enum WorkerState { |
62 WORKER_UNINSPECTED, | 62 WORKER_UNINSPECTED, |
63 WORKER_INSPECTED, | 63 WORKER_INSPECTED, |
64 WORKER_TERMINATED, | 64 WORKER_TERMINATED, |
65 WORKER_PAUSED, | 65 WORKER_PAUSED, |
66 }; | 66 }; |
67 | 67 |
68 class WorkerInfo { | 68 class WorkerInfo { |
69 public: | 69 public: |
70 // Creates WorkerInfo for SharedWorker. | 70 // Creates WorkerInfo for SharedWorker. |
71 explicit WorkerInfo(const SharedWorkerInstance& instance); | 71 explicit WorkerInfo(const SharedWorkerInstance& instance); |
72 // Creates WorkerInfo for ServiceWorker. | 72 // Creates WorkerInfo for ServiceWorker. |
73 WorkerInfo(const base::FilePath& storage_partition_path, | 73 WorkerInfo(const ServiceWorkerContextCore* const service_worker_context, |
74 const GURL& service_worker_scope); | 74 int64 service_worker_version_id); |
75 ~WorkerInfo(); | 75 ~WorkerInfo(); |
76 | 76 |
77 WorkerState state() { return state_; } | 77 WorkerState state() { return state_; } |
78 void set_state(WorkerState new_state) { state_ = new_state; } | 78 void set_state(WorkerState new_state) { state_ = new_state; } |
79 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | 79 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } |
80 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { | 80 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { |
81 agent_host_ = agent_host; | 81 agent_host_ = agent_host; |
82 } | 82 } |
83 bool Matches(const SharedWorkerInstance& other); | 83 bool Matches(const SharedWorkerInstance& other); |
84 bool Matches(const base::FilePath& other_storage_partition_path, | 84 bool Matches(const ServiceWorkerContextCore* const service_worker_context, |
85 const GURL& other_service_worker_scope); | 85 int64 other_service_worker_version_id); |
86 | 86 |
87 private: | 87 private: |
88 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; | 88 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; |
89 scoped_ptr<base::FilePath> storage_partition_path_; | 89 const ServiceWorkerContextCore* const service_worker_context_; |
yurys
2014/05/16 13:27:05
Could you educate me on what the lifetime of Servi
horo
2014/05/16 14:43:14
ServiceWorkerContextCore is deleted after Profile
| |
90 scoped_ptr<GURL> service_worker_scope_; | 90 const int64 service_worker_version_id_; |
91 WorkerState state_; | 91 WorkerState state_; |
92 EmbeddedWorkerDevToolsAgentHost* agent_host_; | 92 EmbeddedWorkerDevToolsAgentHost* agent_host_; |
93 }; | 93 }; |
94 | 94 |
95 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | 95 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
96 | 96 |
97 EmbeddedWorkerDevToolsManager(); | 97 EmbeddedWorkerDevToolsManager(); |
98 virtual ~EmbeddedWorkerDevToolsManager(); | 98 virtual ~EmbeddedWorkerDevToolsManager(); |
99 | 99 |
100 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); | 100 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); |
101 | 101 |
102 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( | 102 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( |
103 const SharedWorkerInstance& instance); | 103 const SharedWorkerInstance& instance); |
104 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( | 104 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( |
105 const base::FilePath& storage_partition_path, | 105 const ServiceWorkerContextCore* const service_worker_context, |
106 const GURL& service_worker_scope); | 106 int64 service_worker_version_id); |
107 | 107 |
108 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); | 108 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); |
109 | 109 |
110 // Resets to its initial state as if newly created. | 110 // Resets to its initial state as if newly created. |
111 void ResetForTesting(); | 111 void ResetForTesting(); |
112 | 112 |
113 WorkerInfoMap workers_; | 113 WorkerInfoMap workers_; |
114 | 114 |
115 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); | 115 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); |
116 }; | 116 }; |
117 | 117 |
118 } // namespace content | 118 } // namespace content |
119 | 119 |
120 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 120 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |