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 "base/basictypes.h"
9 #include "base/containers/scoped_ptr_hash_map.h"
10 #include "base/files/file_path.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"
21 class DevToolsAgentHost
;
23 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when
24 // "enable-embedded-shared-worker" flag is set.
25 // This class lives on UI thread.
26 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager
{
28 typedef std::pair
<int, int> WorkerId
;
29 class EmbeddedWorkerDevToolsAgentHost
;
31 // Returns the EmbeddedWorkerDevToolsManager singleton.
32 static EmbeddedWorkerDevToolsManager
* GetInstance();
34 DevToolsAgentHost
* GetDevToolsAgentHostForWorker(int worker_process_id
,
37 // Returns true when the worker must be paused on start.
38 bool SharedWorkerCreated(int worker_process_id
,
40 const SharedWorkerInstance
& instance
);
41 // Returns true when the worker must be paused on start.
42 // TODO(horo): Currently we identify ServiceWorkers with the path of storage
43 // partition and the scope of ServiceWorker. Consider having a class like
44 // SharedWorkerInstance instead of the pair.
45 bool ServiceWorkerCreated(int worker_process_id
,
47 const base::FilePath
& storage_partition_path
,
48 const GURL
& service_worker_scope
);
49 void WorkerContextStarted(int worker_process_id
, int worker_route_id
);
50 void WorkerDestroyed(int worker_process_id
, int worker_route_id
);
53 friend struct DefaultSingletonTraits
<EmbeddedWorkerDevToolsManager
>;
54 friend class EmbeddedWorkerDevToolsManagerTest
;
55 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest
, BasicTest
);
56 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest
, AttachTest
);
67 // Creates WorkerInfo for SharedWorker.
68 explicit WorkerInfo(const SharedWorkerInstance
& instance
);
69 // Creates WorkerInfo for ServiceWorker.
70 WorkerInfo(const base::FilePath
& storage_partition_path
,
71 const GURL
& service_worker_scope
);
74 WorkerState
state() { return state_
; }
75 void set_state(WorkerState new_state
) { state_
= new_state
; }
76 EmbeddedWorkerDevToolsAgentHost
* agent_host() { return agent_host_
; }
77 void set_agent_host(EmbeddedWorkerDevToolsAgentHost
* agent_host
) {
78 agent_host_
= agent_host
;
80 bool Matches(const SharedWorkerInstance
& other
);
81 bool Matches(const base::FilePath
& other_storage_partition_path
,
82 const GURL
& other_service_worker_scope
);
85 scoped_ptr
<SharedWorkerInstance
> shared_worker_instance_
;
86 scoped_ptr
<base::FilePath
> storage_partition_path_
;
87 scoped_ptr
<GURL
> service_worker_scope_
;
89 EmbeddedWorkerDevToolsAgentHost
* agent_host_
;
92 typedef base::ScopedPtrHashMap
<WorkerId
, WorkerInfo
> WorkerInfoMap
;
94 EmbeddedWorkerDevToolsManager();
95 virtual ~EmbeddedWorkerDevToolsManager();
97 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost
* agent_host
);
99 WorkerInfoMap::iterator
FindExistingSharedWorkerInfo(
100 const SharedWorkerInstance
& instance
);
101 WorkerInfoMap::iterator
FindExistingServiceWorkerInfo(
102 const base::FilePath
& storage_partition_path
,
103 const GURL
& service_worker_scope
);
105 void MoveToPausedState(const WorkerId
& id
, const WorkerInfoMap::iterator
& it
);
107 // Resets to its initial state as if newly created.
108 void ResetForTesting();
110 WorkerInfoMap workers_
;
112 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager
);
115 } // namespace content
117 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_