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_SHARED_WORKER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_SHARED_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 class GURL; | 17 class GURL; |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 class DevToolsAgentHost; | 20 class DevToolsAgentHost; |
21 | 21 |
22 // SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when | 22 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when |
23 // "enable-embedded-shared-worker" flag is set. | 23 // "enable-embedded-shared-worker" flag is set. |
24 // This class lives on UI thread. | 24 // This class lives on UI thread. |
25 class CONTENT_EXPORT SharedWorkerDevToolsManager { | 25 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { |
26 public: | 26 public: |
27 typedef std::pair<int, int> WorkerId; | 27 typedef std::pair<int, int> WorkerId; |
28 class SharedWorkerDevToolsAgentHost; | 28 class EmbeddedWorkerDevToolsAgentHost; |
29 | 29 |
30 // Returns the SharedWorkerDevToolsManager singleton. | 30 // Returns the EmbeddedWorkerDevToolsManager singleton. |
31 static SharedWorkerDevToolsManager* GetInstance(); | 31 static EmbeddedWorkerDevToolsManager* GetInstance(); |
32 | 32 |
33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | 33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
34 int worker_route_id); | 34 int worker_route_id); |
35 | 35 |
36 // Returns true when the worker must be paused on start. | 36 // Returns true when the worker must be paused on start. |
37 bool WorkerCreated(int worker_process_id, | 37 bool SharedWorkerCreated(int worker_process_id, |
38 int worker_route_id, | 38 int worker_route_id, |
39 const SharedWorkerInstance& instance); | 39 const SharedWorkerInstance& instance); |
40 void WorkerDestroyed(int worker_process_id, int worker_route_id); | 40 void WorkerDestroyed(int worker_process_id, int worker_route_id); |
41 void WorkerContextStarted(int worker_process_id, int worker_route_id); | 41 void WorkerContextStarted(int worker_process_id, int worker_route_id); |
42 | 42 |
43 private: | 43 private: |
44 friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>; | 44 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; |
45 friend class SharedWorkerDevToolsManagerTest; | 45 friend class EmbeddedWorkerDevToolsManagerTest; |
46 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, BasicTest); | 46 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); |
47 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, AttachTest); | 47 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); |
48 | 48 |
49 enum WorkerState { | 49 enum WorkerState { |
50 WORKER_UNINSPECTED, | 50 WORKER_UNINSPECTED, |
51 WORKER_INSPECTED, | 51 WORKER_INSPECTED, |
52 WORKER_TERMINATED, | 52 WORKER_TERMINATED, |
53 WORKER_PAUSED, | 53 WORKER_PAUSED, |
54 }; | 54 }; |
55 | 55 |
56 class WorkerInfo { | 56 class WorkerInfo { |
57 public: | 57 public: |
58 explicit WorkerInfo(const SharedWorkerInstance& instance) | 58 explicit WorkerInfo(const SharedWorkerInstance& instance) |
59 : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {} | 59 : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {} |
60 | 60 |
61 const SharedWorkerInstance& instance() const { return instance_; } | 61 const SharedWorkerInstance& instance() const { return instance_; } |
62 WorkerState state() { return state_; } | 62 WorkerState state() { return state_; } |
63 void set_state(WorkerState new_state) { state_ = new_state; } | 63 void set_state(WorkerState new_state) { state_ = new_state; } |
64 SharedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | 64 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } |
65 void set_agent_host(SharedWorkerDevToolsAgentHost* agent_host) { | 65 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { |
66 agent_host_ = agent_host; | 66 agent_host_ = agent_host; |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 const SharedWorkerInstance instance_; | 70 const SharedWorkerInstance instance_; |
71 WorkerState state_; | 71 WorkerState state_; |
72 SharedWorkerDevToolsAgentHost* agent_host_; | 72 EmbeddedWorkerDevToolsAgentHost* agent_host_; |
73 }; | 73 }; |
74 | 74 |
75 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | 75 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
76 | 76 |
77 SharedWorkerDevToolsManager(); | 77 EmbeddedWorkerDevToolsManager(); |
78 virtual ~SharedWorkerDevToolsManager(); | 78 virtual ~EmbeddedWorkerDevToolsManager(); |
79 | 79 |
80 void RemoveInspectedWorkerData(SharedWorkerDevToolsAgentHost* agent_host); | 80 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); |
81 | 81 |
82 WorkerInfoMap::iterator FindExistingWorkerInfo( | 82 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( |
83 const SharedWorkerInstance& instance); | 83 const SharedWorkerInstance& instance); |
84 | 84 |
85 // Resets to its initial state as if newly created. | 85 // Resets to its initial state as if newly created. |
86 void ResetForTesting(); | 86 void ResetForTesting(); |
87 | 87 |
88 WorkerInfoMap workers_; | 88 WorkerInfoMap workers_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager); | 90 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); |
91 }; | 91 }; |
92 | 92 |
93 } // namespace content | 93 } // namespace content |
94 | 94 |
95 #endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ | 95 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |