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_
10 #include "base/basictypes.h"
11 #include "base/memory/singleton.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/devtools/worker_devtools_manager.h"
14 #include "content/browser/shared_worker/shared_worker_instance.h"
18 class ServiceWorkerDevToolsAgentHost
;
19 class ServiceWorkerContextCore
;
21 // Manages WorkerDevToolsAgentHost's for Service Workers.
22 // This class lives on UI thread.
23 class CONTENT_EXPORT ServiceWorkerDevToolsManager
24 : public WorkerDevToolsManager
{
26 class ServiceWorkerIdentifier
{
28 ServiceWorkerIdentifier(
29 const ServiceWorkerContextCore
* context
,
30 base::WeakPtr
<ServiceWorkerContextCore
> context_weak
,
33 ServiceWorkerIdentifier(const ServiceWorkerIdentifier
& other
);
34 ~ServiceWorkerIdentifier();
36 bool Matches(const ServiceWorkerIdentifier
& other
) const;
38 const ServiceWorkerContextCore
* context() const { return context_
; }
39 base::WeakPtr
<ServiceWorkerContextCore
> context_weak() const {
42 int64
version_id() const { return version_id_
; }
43 GURL
url() const { return url_
; }
46 const ServiceWorkerContextCore
* const context_
;
47 const base::WeakPtr
<ServiceWorkerContextCore
> context_weak_
;
48 const int64 version_id_
;
52 // Returns the ServiceWorkerDevToolsManager singleton.
53 static ServiceWorkerDevToolsManager
* GetInstance();
55 // Returns true when the worker must be paused on start because a DevTool
56 // window for the same former ServiceWorkerIdentifier is still opened or
57 // debug-on-start is enabled in chrome://serviceworker-internals.
58 bool WorkerCreated(int worker_process_id
,
60 const ServiceWorkerIdentifier
& service_worker_id
);
61 void WorkerStopIgnored(int worker_process_id
, int worker_route_id
);
63 void set_debug_service_worker_on_start(bool debug_on_start
) {
64 debug_service_worker_on_start_
= debug_on_start
;
66 bool debug_service_worker_on_start() const {
67 return debug_service_worker_on_start_
;
71 friend struct DefaultSingletonTraits
<ServiceWorkerDevToolsManager
>;
72 friend class ServiceWorkerDevToolsAgentHost
;
74 ServiceWorkerDevToolsManager();
75 ~ServiceWorkerDevToolsManager() override
;
77 AgentHostMap::iterator
FindExistingWorkerAgentHost(
78 const ServiceWorkerIdentifier
& service_worker_id
);
80 bool debug_service_worker_on_start_
;
82 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDevToolsManager
);
85 } // namespace content
87 #endif // CONTENT_BROWSER_DEVTOOLS_SERVICE_WORKER_DEVTOOLS_MANAGER_H_