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

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

Issue 985343002: DevTools: remove the WorkerDevToolsManager base - implementations are diverging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed. Created 5 years, 9 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_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/public/browser/devtools_agent_host.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 class DevToolsAgentHostImpl;
18 class ServiceWorkerDevToolsAgentHost; 19 class ServiceWorkerDevToolsAgentHost;
19 class ServiceWorkerContextCore; 20 class ServiceWorkerContextCore;
20 21
21 // Manages WorkerDevToolsAgentHost's for Service Workers. 22 // Manages WorkerDevToolsAgentHost's for Service Workers.
22 // This class lives on UI thread. 23 // This class lives on UI thread.
23 class CONTENT_EXPORT ServiceWorkerDevToolsManager 24 class CONTENT_EXPORT ServiceWorkerDevToolsManager {
24 : public WorkerDevToolsManager {
25 public: 25 public:
26 typedef std::pair<int, int> WorkerId;
27
28 class Observer {
29 public:
30 virtual void WorkerCreated(DevToolsAgentHost* host) {}
31 virtual void WorkerDestroyed(DevToolsAgentHost* host) {}
32
33 protected:
34 virtual ~Observer() {}
35 };
36
26 class ServiceWorkerIdentifier { 37 class ServiceWorkerIdentifier {
27 public: 38 public:
28 ServiceWorkerIdentifier( 39 ServiceWorkerIdentifier(
29 const ServiceWorkerContextCore* context, 40 const ServiceWorkerContextCore* context,
30 base::WeakPtr<ServiceWorkerContextCore> context_weak, 41 base::WeakPtr<ServiceWorkerContextCore> context_weak,
31 int64 version_id, 42 int64 version_id,
32 const GURL& url); 43 const GURL& url);
33 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); 44 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other);
34 ~ServiceWorkerIdentifier(); 45 ~ServiceWorkerIdentifier();
35 46
36 bool Matches(const ServiceWorkerIdentifier& other) const; 47 bool Matches(const ServiceWorkerIdentifier& other) const;
37 48
38 const ServiceWorkerContextCore* context() const { return context_; } 49 const ServiceWorkerContextCore* context() const { return context_; }
39 base::WeakPtr<ServiceWorkerContextCore> context_weak() const { 50 base::WeakPtr<ServiceWorkerContextCore> context_weak() const {
40 return context_weak_; 51 return context_weak_;
41 } 52 }
42 int64 version_id() const { return version_id_; } 53 int64 version_id() const { return version_id_; }
43 GURL url() const { return url_; } 54 GURL url() const { return url_; }
44 55
45 private: 56 private:
46 const ServiceWorkerContextCore* const context_; 57 const ServiceWorkerContextCore* const context_;
47 const base::WeakPtr<ServiceWorkerContextCore> context_weak_; 58 const base::WeakPtr<ServiceWorkerContextCore> context_weak_;
48 const int64 version_id_; 59 const int64 version_id_;
49 const GURL url_; 60 const GURL url_;
50 }; 61 };
51 62
52 // Returns the ServiceWorkerDevToolsManager singleton. 63 // Returns the ServiceWorkerDevToolsManager singleton.
53 static ServiceWorkerDevToolsManager* GetInstance(); 64 static ServiceWorkerDevToolsManager* GetInstance();
54 65
66 DevToolsAgentHostImpl* GetDevToolsAgentHostForWorker(int worker_process_id,
67 int worker_route_id);
68 void AddAllAgentHosts(DevToolsAgentHost::List* result);
69
55 // Returns true when the worker must be paused on start because a DevTool 70 // Returns true when the worker must be paused on start because a DevTool
56 // window for the same former ServiceWorkerIdentifier is still opened or 71 // window for the same former ServiceWorkerIdentifier is still opened or
57 // debug-on-start is enabled in chrome://serviceworker-internals. 72 // debug-on-start is enabled in chrome://serviceworker-internals.
58 bool WorkerCreated(int worker_process_id, 73 bool WorkerCreated(int worker_process_id,
59 int worker_route_id, 74 int worker_route_id,
60 const ServiceWorkerIdentifier& service_worker_id); 75 const ServiceWorkerIdentifier& service_worker_id);
76 void WorkerReadyForInspection(int worker_process_id, int worker_route_id);
61 void WorkerStopIgnored(int worker_process_id, int worker_route_id); 77 void WorkerStopIgnored(int worker_process_id, int worker_route_id);
78 void WorkerDestroyed(int worker_process_id, int worker_route_id);
79 void RemoveInspectedWorkerData(WorkerId id);
80
81 void AddObserver(Observer* observer);
82 void RemoveObserver(Observer* observer);
62 83
63 void set_debug_service_worker_on_start(bool debug_on_start) { 84 void set_debug_service_worker_on_start(bool debug_on_start) {
64 debug_service_worker_on_start_ = debug_on_start; 85 debug_service_worker_on_start_ = debug_on_start;
65 } 86 }
66 bool debug_service_worker_on_start() const { 87 bool debug_service_worker_on_start() const {
67 return debug_service_worker_on_start_; 88 return debug_service_worker_on_start_;
68 } 89 }
69 90
70 private: 91 private:
71 friend struct DefaultSingletonTraits<ServiceWorkerDevToolsManager>; 92 friend struct DefaultSingletonTraits<ServiceWorkerDevToolsManager>;
72 friend class ServiceWorkerDevToolsAgentHost; 93 friend class ServiceWorkerDevToolsAgentHost;
73 94
95 using AgentHostMap = std::map<WorkerId, ServiceWorkerDevToolsAgentHost*>;
96
74 ServiceWorkerDevToolsManager(); 97 ServiceWorkerDevToolsManager();
75 ~ServiceWorkerDevToolsManager() override; 98 ~ServiceWorkerDevToolsManager();
76 99
77 AgentHostMap::iterator FindExistingWorkerAgentHost( 100 AgentHostMap::iterator FindExistingWorkerAgentHost(
78 const ServiceWorkerIdentifier& service_worker_id); 101 const ServiceWorkerIdentifier& service_worker_id);
79 102
103 // Resets to its initial state as if newly created.
104 void ResetForTesting();
105
106 ObserverList<Observer> observer_list_;
107 AgentHostMap workers_;
80 bool debug_service_worker_on_start_; 108 bool debug_service_worker_on_start_;
81 109
82 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDevToolsManager); 110 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDevToolsManager);
83 }; 111 };
84 112
85 } // namespace content 113 } // namespace content
86 114
87 #endif // CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_ 115 #endif // CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698