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_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/singleton.h"
14 #include "base/strings/string16.h"
15 #include "content/browser/shared_worker/shared_worker_instance.h"
16 #include "content/common/content_export.h"
20 class DevToolsAgentHost;
21 class EmbeddedWorkerDevToolsAgentHost;
22 class ServiceWorkerContextCore;
24 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when
25 // "enable-embedded-shared-worker" flag is set.
26 // This class lives on UI thread.
27 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager {
29 typedef std::pair<int, int> WorkerId;
31 class ServiceWorkerIdentifier {
33 ServiceWorkerIdentifier(
34 const ServiceWorkerContextCore* const service_worker_context,
35 int64 service_worker_version_id);
36 explicit ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other);
37 ~ServiceWorkerIdentifier() {}
39 bool Matches(const ServiceWorkerIdentifier& other) const;
42 const ServiceWorkerContextCore* const service_worker_context_;
43 const int64 service_worker_version_id_;
46 // Returns the EmbeddedWorkerDevToolsManager singleton.
47 static EmbeddedWorkerDevToolsManager* GetInstance();
49 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id,
52 // Returns true when the worker must be paused on start because a DevTool
53 // window for the same former SharedWorkerInstance is still opened.
54 bool SharedWorkerCreated(int worker_process_id,
56 const SharedWorkerInstance& instance);
57 // Returns true when the worker must be paused on start because a DevTool
58 // window for the same former ServiceWorkerIdentifier is still opened or
59 // debug-on-start is enabled in chrome://serviceworker-internals.
60 bool ServiceWorkerCreated(int worker_process_id,
62 const ServiceWorkerIdentifier& service_worker_id);
63 void WorkerContextStarted(int worker_process_id, int worker_route_id);
64 void WorkerDestroyed(int worker_process_id, int worker_route_id);
66 void set_debug_service_worker_on_start(bool debug_on_start) {
67 debug_service_worker_on_start_ = debug_on_start;
69 bool debug_service_worker_on_start() const {
70 return debug_service_worker_on_start_;
74 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>;
75 friend class EmbeddedWorkerDevToolsAgentHost;
76 friend class EmbeddedWorkerDevToolsManagerTest;
77 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest);
78 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest);
80 typedef std::map<WorkerId, EmbeddedWorkerDevToolsAgentHost*> AgentHostMap;
82 EmbeddedWorkerDevToolsManager();
83 virtual ~EmbeddedWorkerDevToolsManager();
85 void RemoveInspectedWorkerData(WorkerId id);
87 AgentHostMap::iterator FindExistingSharedWorkerAgentHost(
88 const SharedWorkerInstance& instance);
89 AgentHostMap::iterator FindExistingServiceWorkerAgentHost(
90 const ServiceWorkerIdentifier& service_worker_id);
92 void WorkerRestarted(const WorkerId& id, const AgentHostMap::iterator& it);
94 // Resets to its initial state as if newly created.
95 void ResetForTesting();
97 AgentHostMap workers_;
99 bool debug_service_worker_on_start_;
101 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager);
104 } // namespace content
106 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_