Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: content/browser/devtools/shared_worker_devtools_manager.h

Issue 196503005: Make DevTools support for the embedded SharedWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix UAF bug Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/devtools/shared_worker_devtools_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_ 5 #ifndef CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
6 #define CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_ 6 #define CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
7 7
8 #include "base/basictypes.h" 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"
9 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
10 #include "base/observer_list.h" 13 #include "base/strings/string16.h"
11 #include "base/task_runner.h" 14 #include "content/browser/shared_worker/shared_worker_instance.h"
12 #include "base/timer/timer.h"
13 #include "content/browser/power_profiler/power_data_provider.h"
14 #include "content/browser/power_profiler/power_profiler_observer.h"
15 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 16
17 class GURL;
18
17 namespace content { 19 namespace content {
20 class DevToolsAgentHost;
18 21
19 // A class used to query power information and notify the observers. 22 // SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when
20 class CONTENT_EXPORT PowerProfilerService { 23 // "enable-embedded-shared-worker" flag is set.
24 // This class lives on UI thread.
25 class CONTENT_EXPORT SharedWorkerDevToolsManager {
21 public: 26 public:
22 static PowerProfilerService* GetInstance(); 27 typedef std::pair<int, int> WorkerId;
28 class SharedWorkerDevToolsAgentHost;
23 29
24 // Add and remove an observer. 30 // Returns the SharedWorkerDevToolsManager singleton.
25 void AddObserver(PowerProfilerObserver* observer); 31 static SharedWorkerDevToolsManager* GetInstance();
26 void RemoveObserver(PowerProfilerObserver* observer);
27 32
28 bool IsAvailable(); 33 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id,
34 int worker_route_id);
29 35
30 virtual ~PowerProfilerService(); 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);
31 42
32 private: 43 private:
33 enum Status { 44 friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>;
34 UNINITIALIZED, 45 friend class SharedWorkerDevToolsManagerTest;
35 INITIALIZED, // Initialized, profiling has not started. 46 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, BasicTest);
36 PROFILING 47 FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, AttachTest);
48
49 enum WorkerState {
50 WORKER_UNINSPECTED,
51 WORKER_INSPECTED,
52 WORKER_TERMINATED,
53 WORKER_PAUSED,
37 }; 54 };
38 55
39 friend struct DefaultSingletonTraits<PowerProfilerService>; 56 class WorkerInfo {
40 friend class PowerProfilerServiceTest; 57 public:
58 explicit WorkerInfo(const SharedWorkerInstance& instance)
59 : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {}
41 60
42 PowerProfilerService(); 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 }
43 68
44 PowerProfilerService(scoped_ptr<PowerDataProvider> provider, 69 private:
45 scoped_refptr<base::TaskRunner> task_runner, 70 const SharedWorkerInstance instance_;
46 const base::TimeDelta& sample_period); 71 WorkerState state_;
72 SharedWorkerDevToolsAgentHost* agent_host_;
73 };
47 74
48 void Start(); 75 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap;
49 void Stop();
50 76
51 // Query power data from PowerDataProvider, executes on the WorkerPool thread. 77 SharedWorkerDevToolsManager();
52 void QueryDataOnTaskRunner(); 78 virtual ~SharedWorkerDevToolsManager();
53 79
54 // Initiate the query on the UI thread, the task is delegated to 80 void RemoveInspectedWorkerData(SharedWorkerDevToolsAgentHost* agent_host);
55 // QueryDataOnTaskRunner.
56 void QueryData();
57 81
58 // Executes on the UI thread. 82 WorkerInfoMap::iterator FindExistingWorkerInfo(
59 void Notify(const PowerEventVector&); 83 const SharedWorkerInstance& instance);
60 84
61 base::RepeatingTimer<PowerProfilerService> query_power_timer_; 85 // Resets to its initial state as if newly created.
62 scoped_refptr<base::TaskRunner> task_runner_; 86 void ResetForTesting();
63 87
64 Status status_; 88 WorkerInfoMap workers_;
65 89
66 // Sampling period of power data measurement. 90 DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager);
67 const base::TimeDelta sample_period_;
68 ObserverList<PowerProfilerObserver> observers_;
69
70 scoped_ptr<PowerDataProvider> data_provider_;
71
72 DISALLOW_COPY_AND_ASSIGN(PowerProfilerService);
73 }; 91 };
74 92
75 } // namespace content 93 } // namespace content
76 94
77 #endif // CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_ 95 #endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/devtools/shared_worker_devtools_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698