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_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "content/browser/devtools/worker_devtools_manager.h" | 13 #include "base/observer_list.h" |
14 #include "content/browser/shared_worker/shared_worker_instance.h" | 14 #include "content/browser/shared_worker/shared_worker_instance.h" |
dgozman
2015/03/07 20:46:40
nit: unnecessary include
pfeldman
2015/03/08 12:17:27
Done.
pfeldman
2015/03/08 12:17:27
Done.
| |
15 #include "content/public/browser/devtools_agent_host.h" | |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
19 class DevToolsAgentHostImpl; | |
18 class ServiceWorkerDevToolsAgentHost; | 20 class ServiceWorkerDevToolsAgentHost; |
19 class ServiceWorkerContextCore; | 21 class ServiceWorkerContextCore; |
20 | 22 |
21 // Manages WorkerDevToolsAgentHost's for Service Workers. | 23 // Manages WorkerDevToolsAgentHost's for Service Workers. |
22 // This class lives on UI thread. | 24 // This class lives on UI thread. |
23 class CONTENT_EXPORT ServiceWorkerDevToolsManager | 25 class CONTENT_EXPORT ServiceWorkerDevToolsManager { |
24 : public WorkerDevToolsManager { | |
25 public: | 26 public: |
27 typedef std::pair<int, int> WorkerId; | |
28 | |
29 class Observer { | |
30 public: | |
31 virtual void WorkerCreated(DevToolsAgentHost* host) {} | |
32 virtual void WorkerDestroyed(DevToolsAgentHost* host) {} | |
33 | |
34 protected: | |
35 virtual ~Observer() {} | |
36 }; | |
37 | |
26 class ServiceWorkerIdentifier { | 38 class ServiceWorkerIdentifier { |
27 public: | 39 public: |
28 ServiceWorkerIdentifier( | 40 ServiceWorkerIdentifier( |
29 const ServiceWorkerContextCore* context, | 41 const ServiceWorkerContextCore* context, |
30 base::WeakPtr<ServiceWorkerContextCore> context_weak, | 42 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
31 int64 version_id, | 43 int64 version_id, |
32 const GURL& url); | 44 const GURL& url); |
33 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); | 45 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); |
34 ~ServiceWorkerIdentifier(); | 46 ~ServiceWorkerIdentifier(); |
35 | 47 |
36 bool Matches(const ServiceWorkerIdentifier& other) const; | 48 bool Matches(const ServiceWorkerIdentifier& other) const; |
37 | 49 |
38 const ServiceWorkerContextCore* context() const { return context_; } | 50 const ServiceWorkerContextCore* context() const { return context_; } |
39 base::WeakPtr<ServiceWorkerContextCore> context_weak() const { | 51 base::WeakPtr<ServiceWorkerContextCore> context_weak() const { |
40 return context_weak_; | 52 return context_weak_; |
41 } | 53 } |
42 int64 version_id() const { return version_id_; } | 54 int64 version_id() const { return version_id_; } |
43 GURL url() const { return url_; } | 55 GURL url() const { return url_; } |
44 | 56 |
45 private: | 57 private: |
46 const ServiceWorkerContextCore* const context_; | 58 const ServiceWorkerContextCore* const context_; |
47 const base::WeakPtr<ServiceWorkerContextCore> context_weak_; | 59 const base::WeakPtr<ServiceWorkerContextCore> context_weak_; |
48 const int64 version_id_; | 60 const int64 version_id_; |
49 const GURL url_; | 61 const GURL url_; |
50 }; | 62 }; |
51 | 63 |
52 // Returns the ServiceWorkerDevToolsManager singleton. | 64 // Returns the ServiceWorkerDevToolsManager singleton. |
53 static ServiceWorkerDevToolsManager* GetInstance(); | 65 static ServiceWorkerDevToolsManager* GetInstance(); |
54 | 66 |
67 DevToolsAgentHostImpl* GetDevToolsAgentHostForWorker(int worker_process_id, | |
dgozman
2015/03/07 20:46:40
return ServiceWorkerDevToolsAgentHost*?
pfeldman
2015/03/08 12:17:27
Clients don't need it to be that specific, you onl
| |
68 int worker_route_id); | |
69 void AddAllAgentHosts(DevToolsAgentHost::List* result); | |
70 | |
55 // Returns true when the worker must be paused on start because a DevTool | 71 // Returns true when the worker must be paused on start because a DevTool |
56 // window for the same former ServiceWorkerIdentifier is still opened or | 72 // window for the same former ServiceWorkerIdentifier is still opened or |
57 // debug-on-start is enabled in chrome://serviceworker-internals. | 73 // debug-on-start is enabled in chrome://serviceworker-internals. |
58 bool WorkerCreated(int worker_process_id, | 74 bool WorkerCreated(int worker_process_id, |
59 int worker_route_id, | 75 int worker_route_id, |
60 const ServiceWorkerIdentifier& service_worker_id); | 76 const ServiceWorkerIdentifier& service_worker_id); |
77 void WorkerReadyForInspection(int worker_process_id, int worker_route_id); | |
dgozman
2015/03/07 20:46:40
Should all this methods be public? Perhaps, "frien
pfeldman
2015/03/08 12:17:27
It is the other way around, these are the instrume
| |
61 void WorkerStopIgnored(int worker_process_id, int worker_route_id); | 78 void WorkerStopIgnored(int worker_process_id, int worker_route_id); |
79 void WorkerDestroyed(int worker_process_id, int worker_route_id); | |
80 void RemoveInspectedWorkerData(WorkerId id); | |
81 | |
82 void AddObserver(Observer* observer); | |
83 void RemoveObserver(Observer* observer); | |
62 | 84 |
63 void set_debug_service_worker_on_start(bool debug_on_start) { | 85 void set_debug_service_worker_on_start(bool debug_on_start) { |
64 debug_service_worker_on_start_ = debug_on_start; | 86 debug_service_worker_on_start_ = debug_on_start; |
65 } | 87 } |
66 bool debug_service_worker_on_start() const { | 88 bool debug_service_worker_on_start() const { |
67 return debug_service_worker_on_start_; | 89 return debug_service_worker_on_start_; |
68 } | 90 } |
69 | 91 |
70 private: | 92 private: |
71 friend struct DefaultSingletonTraits<ServiceWorkerDevToolsManager>; | 93 friend struct DefaultSingletonTraits<ServiceWorkerDevToolsManager>; |
72 friend class ServiceWorkerDevToolsAgentHost; | 94 friend class ServiceWorkerDevToolsAgentHost; |
73 | 95 |
96 using AgentHostMap = std::map<WorkerId, ServiceWorkerDevToolsAgentHost*>; | |
97 | |
74 ServiceWorkerDevToolsManager(); | 98 ServiceWorkerDevToolsManager(); |
75 ~ServiceWorkerDevToolsManager() override; | 99 ~ServiceWorkerDevToolsManager(); |
76 | 100 |
77 AgentHostMap::iterator FindExistingWorkerAgentHost( | 101 AgentHostMap::iterator FindExistingWorkerAgentHost( |
78 const ServiceWorkerIdentifier& service_worker_id); | 102 const ServiceWorkerIdentifier& service_worker_id); |
79 | 103 |
104 // Resets to its initial state as if newly created. | |
105 void ResetForTesting(); | |
106 | |
107 ObserverList<Observer> observer_list_; | |
108 AgentHostMap workers_; | |
80 bool debug_service_worker_on_start_; | 109 bool debug_service_worker_on_start_; |
81 | 110 |
82 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDevToolsManager); | 111 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDevToolsManager); |
83 }; | 112 }; |
84 | 113 |
85 } // namespace content | 114 } // namespace content |
86 | 115 |
87 #endif // CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ | 116 #endif // CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |