| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ | |
| 6 #define CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/memory/scoped_vector.h" | |
| 12 #include "base/memory/singleton.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 #include "content/browser/shared_worker/shared_worker_instance.h" | |
| 15 #include "content/common/content_export.h" | |
| 16 | |
| 17 class GURL; | |
| 18 | |
| 19 namespace content { | |
| 20 class DevToolsAgentHost; | |
| 21 | |
| 22 // SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when | |
| 23 // "enable-embedded-shared-worker" flag is set. | |
| 24 // This class lives on UI thread. | |
| 25 class CONTENT_EXPORT SharedWorkerDevToolsManager { | |
| 26 public: | |
| 27 typedef std::pair<int, int> WorkerId; | |
| 28 class SharedWorkerDevToolsAgentHost; | |
| 29 | |
| 30 // Returns the SharedWorkerDevToolsManager singleton. | |
| 31 static SharedWorkerDevToolsManager* GetInstance(); | |
| 32 | |
| 33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | |
| 34 int worker_route_id); | |
| 35 | |
| 36 // Returns true when the worker must be paused on start. | |
| 37 bool WorkerCreated(int worker_process_id, | |
| 38 int worker_route_id, | |
| 39 const SharedWorkerInstance& instance); | |
| 40 void WorkerDestroyed(int worker_process_id, int worker_route_id); | |
| 41 void WorkerContextStarted(int worker_process_id, int worker_route_id); | |
| 42 | |
| 43 private: | |
| 44 friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>; | |
| 45 friend class SharedWorkerDevToolsManagerTest; | |
| 46 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, BasicTest); | |
| 47 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, AttachTest); | |
| 48 | |
| 49 enum WorkerState { | |
| 50 WORKER_UNINSPECTED, | |
| 51 WORKER_INSPECTED, | |
| 52 WORKER_TERMINATED, | |
| 53 WORKER_PAUSED, | |
| 54 }; | |
| 55 | |
| 56 class WorkerInfo { | |
| 57 public: | |
| 58 explicit WorkerInfo(const SharedWorkerInstance& instance) | |
| 59 : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {} | |
| 60 | |
| 61 const SharedWorkerInstance& instance() const { return instance_; } | |
| 62 WorkerState state() { return state_; } | |
| 63 void set_state(WorkerState new_state) { state_ = new_state; } | |
| 64 SharedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | |
| 65 void set_agent_host(SharedWorkerDevToolsAgentHost* agent_host) { | |
| 66 agent_host_ = agent_host; | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 const SharedWorkerInstance instance_; | |
| 71 WorkerState state_; | |
| 72 SharedWorkerDevToolsAgentHost* agent_host_; | |
| 73 }; | |
| 74 | |
| 75 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | |
| 76 | |
| 77 SharedWorkerDevToolsManager(); | |
| 78 virtual ~SharedWorkerDevToolsManager(); | |
| 79 | |
| 80 void RemoveInspectedWorkerData(SharedWorkerDevToolsAgentHost* agent_host); | |
| 81 | |
| 82 WorkerInfoMap::iterator FindExistingWorkerInfo( | |
| 83 const SharedWorkerInstance& instance); | |
| 84 | |
| 85 // Resets to its initial state as if newly created. | |
| 86 void ResetForTesting(); | |
| 87 | |
| 88 WorkerInfoMap workers_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager); | |
| 91 }; | |
| 92 | |
| 93 } // namespace content | |
| 94 | |
| 95 #endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ | |
| OLD | NEW |