| Index: content/browser/devtools/shared_worker_devtools_manager.h
|
| diff --git a/content/browser/power_profiler/power_profiler_service.h b/content/browser/devtools/shared_worker_devtools_manager.h
|
| similarity index 11%
|
| copy from content/browser/power_profiler/power_profiler_service.h
|
| copy to content/browser/devtools/shared_worker_devtools_manager.h
|
| index c21811a6ddc469df3d2d1c3851b3993644d24932..4b238211d1df3f9fd3815a8451ce5601f15f14ee 100644
|
| --- a/content/browser/power_profiler/power_profiler_service.h
|
| +++ b/content/browser/devtools/shared_worker_devtools_manager.h
|
| @@ -2,76 +2,94 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_
|
| -#define CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_
|
| +#ifndef CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
|
| +#define CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
|
|
|
| #include "base/basictypes.h"
|
| +#include "base/containers/scoped_ptr_hash_map.h"
|
| +#include "base/gtest_prod_util.h"
|
| +#include "base/memory/scoped_vector.h"
|
| #include "base/memory/singleton.h"
|
| -#include "base/observer_list.h"
|
| -#include "base/task_runner.h"
|
| -#include "base/timer/timer.h"
|
| -#include "content/browser/power_profiler/power_data_provider.h"
|
| -#include "content/browser/power_profiler/power_profiler_observer.h"
|
| +#include "base/strings/string16.h"
|
| +#include "content/browser/shared_worker/shared_worker_instance.h"
|
| #include "content/common/content_export.h"
|
|
|
| +class GURL;
|
| +
|
| namespace content {
|
| +class DevToolsAgentHost;
|
|
|
| -// A class used to query power information and notify the observers.
|
| -class CONTENT_EXPORT PowerProfilerService {
|
| +// SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when
|
| +// "enable-embedded-shared-worker" flag is set.
|
| +// This class lives on UI thread.
|
| +class CONTENT_EXPORT SharedWorkerDevToolsManager {
|
| public:
|
| - static PowerProfilerService* GetInstance();
|
| + typedef std::pair<int, int> WorkerId;
|
| + class SharedWorkerDevToolsAgentHost;
|
|
|
| - // Add and remove an observer.
|
| - void AddObserver(PowerProfilerObserver* observer);
|
| - void RemoveObserver(PowerProfilerObserver* observer);
|
| + // Returns the SharedWorkerDevToolsManager singleton.
|
| + static SharedWorkerDevToolsManager* GetInstance();
|
|
|
| - bool IsAvailable();
|
| + DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id,
|
| + int worker_route_id);
|
|
|
| - virtual ~PowerProfilerService();
|
| + // Returns true when the worker must be paused on start.
|
| + bool WorkerCreated(int worker_process_id,
|
| + int worker_route_id,
|
| + const SharedWorkerInstance& instance);
|
| + void WorkerDestroyed(int worker_process_id, int worker_route_id);
|
| + void WorkerContextStarted(int worker_process_id, int worker_route_id);
|
|
|
| private:
|
| - enum Status {
|
| - UNINITIALIZED,
|
| - INITIALIZED, // Initialized, profiling has not started.
|
| - PROFILING
|
| + friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>;
|
| + friend class SharedWorkerDevToolsManagerTest;
|
| + FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, BasicTest);
|
| + FRIEND_TEST_ALL_PREFIXES(SharedWorkerDevToolsManagerTest, AttachTest);
|
| +
|
| + enum WorkerState {
|
| + WORKER_UNINSPECTED,
|
| + WORKER_INSPECTED,
|
| + WORKER_TERMINATED,
|
| + WORKER_PAUSED,
|
| };
|
|
|
| - friend struct DefaultSingletonTraits<PowerProfilerService>;
|
| - friend class PowerProfilerServiceTest;
|
| -
|
| - PowerProfilerService();
|
| -
|
| - PowerProfilerService(scoped_ptr<PowerDataProvider> provider,
|
| - scoped_refptr<base::TaskRunner> task_runner,
|
| - const base::TimeDelta& sample_period);
|
| -
|
| - void Start();
|
| - void Stop();
|
| -
|
| - // Query power data from PowerDataProvider, executes on the WorkerPool thread.
|
| - void QueryDataOnTaskRunner();
|
| + class WorkerInfo {
|
| + public:
|
| + explicit WorkerInfo(const SharedWorkerInstance& instance)
|
| + : instance_(instance), state_(WORKER_UNINSPECTED), agent_host_(NULL) {}
|
| +
|
| + const SharedWorkerInstance& instance() const { return instance_; }
|
| + WorkerState state() { return state_; }
|
| + void set_state(WorkerState new_state) { state_ = new_state; }
|
| + SharedWorkerDevToolsAgentHost* agent_host() { return agent_host_; }
|
| + void set_agent_host(SharedWorkerDevToolsAgentHost* agent_host) {
|
| + agent_host_ = agent_host;
|
| + }
|
| +
|
| + private:
|
| + const SharedWorkerInstance instance_;
|
| + WorkerState state_;
|
| + SharedWorkerDevToolsAgentHost* agent_host_;
|
| + };
|
|
|
| - // Initiate the query on the UI thread, the task is delegated to
|
| - // QueryDataOnTaskRunner.
|
| - void QueryData();
|
| + typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap;
|
|
|
| - // Executes on the UI thread.
|
| - void Notify(const PowerEventVector&);
|
| + SharedWorkerDevToolsManager();
|
| + virtual ~SharedWorkerDevToolsManager();
|
|
|
| - base::RepeatingTimer<PowerProfilerService> query_power_timer_;
|
| - scoped_refptr<base::TaskRunner> task_runner_;
|
| + void RemoveInspectedWorkerData(SharedWorkerDevToolsAgentHost* agent_host);
|
|
|
| - Status status_;
|
| + WorkerInfoMap::iterator FindExistingWorkerInfo(
|
| + const SharedWorkerInstance& instance);
|
|
|
| - // Sampling period of power data measurement.
|
| - const base::TimeDelta sample_period_;
|
| - ObserverList<PowerProfilerObserver> observers_;
|
| + // Resets to its initial state as if newly created.
|
| + void ResetForTesting();
|
|
|
| - scoped_ptr<PowerDataProvider> data_provider_;
|
| + WorkerInfoMap workers_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(PowerProfilerService);
|
| + DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager);
|
| };
|
|
|
| } // namespace content
|
|
|
| -#endif // CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_
|
| +#endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_
|
|
|