Change next_proto member type.
[chromium-blink-merge.git] / content / browser / devtools / embedded_worker_devtools_manager.h
blob7103877be11864b242b144ff3bf5485db9b27dba
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_
8 #include <map>
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/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "content/browser/shared_worker/shared_worker_instance.h"
17 #include "content/common/content_export.h"
19 namespace content {
21 class DevToolsAgentHost;
22 class DevToolsAgentHostImpl;
23 class EmbeddedWorkerDevToolsAgentHost;
24 class ServiceWorkerContextCore;
26 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when
27 // "enable-embedded-shared-worker" flag is set.
28 // This class lives on UI thread.
29 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager {
30 public:
31 typedef std::pair<int, int> WorkerId;
33 class ServiceWorkerIdentifier {
34 public:
35 ServiceWorkerIdentifier(
36 const ServiceWorkerContextCore* context,
37 base::WeakPtr<ServiceWorkerContextCore> context_weak,
38 int64 version_id,
39 const GURL& url);
40 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other);
41 ~ServiceWorkerIdentifier();
43 bool Matches(const ServiceWorkerIdentifier& other) const;
45 const ServiceWorkerContextCore* context() const;
46 base::WeakPtr<ServiceWorkerContextCore> context_weak() const;
47 int64 version_id() const;
48 GURL url() const;
50 private:
51 const ServiceWorkerContextCore* const context_;
52 const base::WeakPtr<ServiceWorkerContextCore> context_weak_;
53 const int64 version_id_;
54 const GURL url_;
57 // Returns the EmbeddedWorkerDevToolsManager singleton.
58 static EmbeddedWorkerDevToolsManager* GetInstance();
60 DevToolsAgentHostImpl* GetDevToolsAgentHostForWorker(int worker_process_id,
61 int worker_route_id);
63 std::vector<scoped_refptr<DevToolsAgentHost> > GetOrCreateAllAgentHosts();
65 // Returns true when the worker must be paused on start because a DevTool
66 // window for the same former SharedWorkerInstance is still opened.
67 bool SharedWorkerCreated(int worker_process_id,
68 int worker_route_id,
69 const SharedWorkerInstance& instance);
70 // Returns true when the worker must be paused on start because a DevTool
71 // window for the same former ServiceWorkerIdentifier is still opened or
72 // debug-on-start is enabled in chrome://serviceworker-internals.
73 bool ServiceWorkerCreated(int worker_process_id,
74 int worker_route_id,
75 const ServiceWorkerIdentifier& service_worker_id);
76 void WorkerReadyForInspection(int worker_process_id, int worker_route_id);
77 void WorkerDestroyed(int worker_process_id, int worker_route_id);
79 void set_debug_service_worker_on_start(bool debug_on_start) {
80 debug_service_worker_on_start_ = debug_on_start;
82 bool debug_service_worker_on_start() const {
83 return debug_service_worker_on_start_;
86 private:
87 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>;
88 friend class EmbeddedWorkerDevToolsAgentHost;
89 friend class EmbeddedWorkerDevToolsManagerTest;
90 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest);
91 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest);
93 typedef std::map<WorkerId, EmbeddedWorkerDevToolsAgentHost*> AgentHostMap;
95 EmbeddedWorkerDevToolsManager();
96 virtual ~EmbeddedWorkerDevToolsManager();
98 void RemoveInspectedWorkerData(WorkerId id);
100 AgentHostMap::iterator FindExistingSharedWorkerAgentHost(
101 const SharedWorkerInstance& instance);
102 AgentHostMap::iterator FindExistingServiceWorkerAgentHost(
103 const ServiceWorkerIdentifier& service_worker_id);
105 void WorkerRestarted(const WorkerId& id, const AgentHostMap::iterator& it);
107 // Resets to its initial state as if newly created.
108 void ResetForTesting();
110 AgentHostMap workers_;
112 bool debug_service_worker_on_start_;
114 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager);
117 } // namespace content
119 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_