Implement SSLKEYLOGFILE for OpenSSL.
[chromium-blink-merge.git] / content / browser / devtools / embedded_worker_devtools_manager.h
blob804ef4176ce840fe4771ed9793ecc875ea894ebc
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 WorkerContextStarted(int worker_process_id, int worker_route_id);
78 void WorkerDestroyed(int worker_process_id, int worker_route_id);
80 void set_debug_service_worker_on_start(bool debug_on_start) {
81 debug_service_worker_on_start_ = debug_on_start;
83 bool debug_service_worker_on_start() const {
84 return debug_service_worker_on_start_;
87 private:
88 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>;
89 friend class EmbeddedWorkerDevToolsAgentHost;
90 friend class EmbeddedWorkerDevToolsManagerTest;
91 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest);
92 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest);
94 typedef std::map<WorkerId, EmbeddedWorkerDevToolsAgentHost*> AgentHostMap;
96 EmbeddedWorkerDevToolsManager();
97 virtual ~EmbeddedWorkerDevToolsManager();
99 void RemoveInspectedWorkerData(WorkerId id);
101 AgentHostMap::iterator FindExistingSharedWorkerAgentHost(
102 const SharedWorkerInstance& instance);
103 AgentHostMap::iterator FindExistingServiceWorkerAgentHost(
104 const ServiceWorkerIdentifier& service_worker_id);
106 void WorkerRestarted(const WorkerId& id, const AgentHostMap::iterator& it);
108 // Resets to its initial state as if newly created.
109 void ResetForTesting();
111 AgentHostMap workers_;
113 bool debug_service_worker_on_start_;
115 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager);
118 } // namespace content
120 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_