Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / devtools / service_worker_devtools_manager.h
blob3e55b8b1b027e967e997053aa5fbde54393b8a0d
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/singleton.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "content/public/browser/devtools_agent_host.h"
16 namespace content {
18 class DevToolsAgentHostImpl;
19 class ServiceWorkerDevToolsAgentHost;
20 class ServiceWorkerContextCore;
22 // Manages WorkerDevToolsAgentHost's for Service Workers.
23 // This class lives on UI thread.
24 class CONTENT_EXPORT ServiceWorkerDevToolsManager {
25 public:
26 using WorkerId = std::pair<int, int>;
27 using AgentList = std::vector<scoped_refptr<ServiceWorkerDevToolsAgentHost>>;
29 class Observer {
30 public:
31 virtual void WorkerCreated(ServiceWorkerDevToolsAgentHost* host) {}
32 virtual void WorkerReadyForInspection(
33 ServiceWorkerDevToolsAgentHost* host) {}
34 virtual void WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) {}
35 virtual void DebugOnStartUpdated(bool debug_on_start) {}
37 protected:
38 virtual ~Observer() {}
41 class ServiceWorkerIdentifier {
42 public:
43 ServiceWorkerIdentifier(
44 const ServiceWorkerContextCore* context,
45 base::WeakPtr<ServiceWorkerContextCore> context_weak,
46 int64 version_id,
47 const GURL& url);
48 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other);
49 ~ServiceWorkerIdentifier();
51 bool Matches(const ServiceWorkerIdentifier& other) const;
53 const ServiceWorkerContextCore* context() const { return context_; }
54 base::WeakPtr<ServiceWorkerContextCore> context_weak() const {
55 return context_weak_;
57 int64 version_id() const { return version_id_; }
58 GURL url() const { return url_; }
60 private:
61 const ServiceWorkerContextCore* const context_;
62 const base::WeakPtr<ServiceWorkerContextCore> context_weak_;
63 const int64 version_id_;
64 const GURL url_;
67 // Returns the ServiceWorkerDevToolsManager singleton.
68 static ServiceWorkerDevToolsManager* GetInstance();
70 DevToolsAgentHostImpl* GetDevToolsAgentHostForWorker(int worker_process_id,
71 int worker_route_id);
72 void AddAllAgentHosts(
73 std::vector<scoped_refptr<ServiceWorkerDevToolsAgentHost>>* result);
75 // Returns true when the worker must be paused on start because a DevTool
76 // window for the same former ServiceWorkerIdentifier is still opened or
77 // debug-on-start is enabled in chrome://serviceworker-internals.
78 bool WorkerCreated(int worker_process_id,
79 int worker_route_id,
80 const ServiceWorkerIdentifier& service_worker_id);
81 void WorkerReadyForInspection(int worker_process_id, int worker_route_id);
82 void WorkerStopIgnored(int worker_process_id, int worker_route_id);
83 void WorkerDestroyed(int worker_process_id, int worker_route_id);
84 void RemoveInspectedWorkerData(WorkerId id);
86 void AddObserver(Observer* observer);
87 void RemoveObserver(Observer* observer);
89 void set_debug_service_worker_on_start(bool debug_on_start);
90 bool debug_service_worker_on_start() const {
91 return debug_service_worker_on_start_;
94 private:
95 friend struct DefaultSingletonTraits<ServiceWorkerDevToolsManager>;
96 friend class ServiceWorkerDevToolsAgentHost;
98 using AgentHostMap = std::map<WorkerId, ServiceWorkerDevToolsAgentHost*>;
100 ServiceWorkerDevToolsManager();
101 ~ServiceWorkerDevToolsManager();
103 AgentHostMap::iterator FindExistingWorkerAgentHost(
104 const ServiceWorkerIdentifier& service_worker_id);
106 // Resets to its initial state as if newly created.
107 void ResetForTesting();
109 ObserverList<Observer> observer_list_;
110 AgentHostMap workers_;
111 bool debug_service_worker_on_start_;
113 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDevToolsManager);
116 } // namespace content
118 #endif // CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_