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" | |
10 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "content/browser/shared_worker/shared_worker_instance.h" | 15 #include "content/browser/shared_worker/shared_worker_instance.h" |
15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
16 | 17 |
17 class GURL; | 18 class GURL; |
18 | 19 |
19 namespace content { | 20 namespace content { |
(...skipping 10 matching lines...) Expand all Loading... | |
30 // Returns the EmbeddedWorkerDevToolsManager singleton. | 31 // Returns the EmbeddedWorkerDevToolsManager singleton. |
31 static EmbeddedWorkerDevToolsManager* GetInstance(); | 32 static EmbeddedWorkerDevToolsManager* GetInstance(); |
32 | 33 |
33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | 34 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
34 int worker_route_id); | 35 int worker_route_id); |
35 | 36 |
36 // Returns true when the worker must be paused on start. | 37 // Returns true when the worker must be paused on start. |
37 bool SharedWorkerCreated(int worker_process_id, | 38 bool SharedWorkerCreated(int worker_process_id, |
38 int worker_route_id, | 39 int worker_route_id, |
39 const SharedWorkerInstance& instance); | 40 const SharedWorkerInstance& instance); |
41 bool ServiceWorkerCreated(int worker_process_id, | |
42 int worker_route_id, | |
43 const base::FilePath& path, | |
44 const GURL& scope); | |
45 void WorkerContextStarted(int worker_process_id, int worker_route_id); | |
40 void WorkerDestroyed(int worker_process_id, int worker_route_id); | 46 void WorkerDestroyed(int worker_process_id, int worker_route_id); |
41 void WorkerContextStarted(int worker_process_id, int worker_route_id); | |
42 | 47 |
43 private: | 48 private: |
44 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; | 49 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; |
45 friend class EmbeddedWorkerDevToolsManagerTest; | 50 friend class EmbeddedWorkerDevToolsManagerTest; |
46 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); | 51 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); |
47 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); | 52 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); |
48 | 53 |
49 enum WorkerState { | 54 enum WorkerState { |
50 WORKER_UNINSPECTED, | 55 WORKER_UNINSPECTED, |
51 WORKER_INSPECTED, | 56 WORKER_INSPECTED, |
52 WORKER_TERMINATED, | 57 WORKER_TERMINATED, |
53 WORKER_PAUSED, | 58 WORKER_PAUSED, |
54 }; | 59 }; |
55 | 60 |
56 class WorkerInfo { | 61 class WorkerInfo { |
57 public: | 62 public: |
58 explicit WorkerInfo(const SharedWorkerInstance& instance) | 63 explicit WorkerInfo(const SharedWorkerInstance& instance); |
59 : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {} | 64 WorkerInfo(const base::FilePath& service_worker_path, |
65 const GURL& service_worker_scope); | |
66 ~WorkerInfo(); | |
60 | 67 |
61 const SharedWorkerInstance& instance() const { return instance_; } | |
62 WorkerState state() { return state_; } | 68 WorkerState state() { return state_; } |
63 void set_state(WorkerState new_state) { state_ = new_state; } | 69 void set_state(WorkerState new_state) { state_ = new_state; } |
64 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | 70 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } |
65 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { | 71 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { |
66 agent_host_ = agent_host; | 72 agent_host_ = agent_host; |
67 } | 73 } |
74 bool Matches(const SharedWorkerInstance& other) { | |
75 if (!shared_worker_instance_) | |
76 return false; | |
77 return shared_worker_instance_->Matches(other); | |
78 } | |
79 bool Matches(const base::FilePath& other_service_worker_path, | |
yurys
2014/05/02 04:35:35
nit: move implementation of Matches methods to the
horo
2014/05/02 06:31:55
Done.
| |
80 const GURL& other_service_worker_scope) { | |
81 if (!service_worker_path_ || !service_worker_scope_) | |
82 return false; | |
83 return *service_worker_path_ == other_service_worker_path && | |
84 *service_worker_scope_ == other_service_worker_scope; | |
85 } | |
68 | 86 |
69 private: | 87 private: |
70 const SharedWorkerInstance instance_; | 88 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; |
89 scoped_ptr<base::FilePath> service_worker_path_; | |
90 scoped_ptr<GURL> service_worker_scope_; | |
71 WorkerState state_; | 91 WorkerState state_; |
72 EmbeddedWorkerDevToolsAgentHost* agent_host_; | 92 EmbeddedWorkerDevToolsAgentHost* agent_host_; |
73 }; | 93 }; |
74 | 94 |
75 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | 95 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
76 | 96 |
77 EmbeddedWorkerDevToolsManager(); | 97 EmbeddedWorkerDevToolsManager(); |
78 virtual ~EmbeddedWorkerDevToolsManager(); | 98 virtual ~EmbeddedWorkerDevToolsManager(); |
79 | 99 |
80 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); | 100 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); |
81 | 101 |
82 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( | 102 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( |
83 const SharedWorkerInstance& instance); | 103 const SharedWorkerInstance& instance); |
104 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( | |
105 const base::FilePath& service_worker_path, | |
106 const GURL& service_worker_scope); | |
84 | 107 |
85 // Resets to its initial state as if newly created. | 108 // Resets to its initial state as if newly created. |
86 void ResetForTesting(); | 109 void ResetForTesting(); |
87 | 110 |
88 WorkerInfoMap workers_; | 111 WorkerInfoMap workers_; |
89 | 112 |
90 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); | 113 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); |
91 }; | 114 }; |
92 | 115 |
93 } // namespace content | 116 } // namespace content |
94 | 117 |
95 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 118 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |