| Index: chrome/browser/devtools/devtools_power_profiler_host.cc
|
| diff --git a/chrome/browser/devtools/devtools_power_profiler_host.cc b/chrome/browser/devtools/devtools_power_profiler_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7eb20aa4887da1193612a23ec7df80b61750fa58
|
| --- /dev/null
|
| +++ b/chrome/browser/devtools/devtools_power_profiler_host.cc
|
| @@ -0,0 +1,63 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/devtools/devtools_power_profiler_host.h"
|
| +
|
| +#include "base/json/json_writer.h"
|
| +#include "base/logging.h"
|
| +#include "base/time/time.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +using namespace content;
|
| +
|
| +DevToolsPowerProfilerHost::DevToolsPowerProfilerHost(
|
| + const base::WeakPtr<DevToolsWindow>& host) : frontend_host_(host) {
|
| + SetResolution(HIGH);
|
| +}
|
| +
|
| +void DevToolsPowerProfilerHost::convertPowerValueToJSONObject(
|
| + base::DictionaryValue* object, PowerEvent* event) {
|
| + const base::TimeTicks kNullTicks;
|
| + object->SetDouble("timestamp",
|
| + convertMonotonicTimeToWallTime(event->time).ToDoubleT() * 1000.0);
|
| + object->SetDouble("value", event->value);
|
| + switch (event->type) {
|
| + case PowerEvent::SOC_PACKAGE:
|
| + object->SetString("type", "SoC_Package");
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + break;
|
| + }
|
| +}
|
| +
|
| +void DevToolsPowerProfilerHost::Send(PowerEvent* event) {
|
| + std::string json_string;
|
| + base::DictionaryValue message_object;
|
| + base::DictionaryValue* params = new base::DictionaryValue();
|
| + base::ListValue* event_list = new base::ListValue();
|
| +
|
| + base::DictionaryValue* value = new base::DictionaryValue();
|
| + convertPowerValueToJSONObject(value, event);
|
| + event_list->Append(value);
|
| +
|
| + params->Set("powerEvents", event_list);
|
| + message_object.Set("params", params);
|
| + message_object.SetString("method", "Power.PowerEventsReceived");
|
| +
|
| + base::JSONWriter::Write(&message_object, &json_string);
|
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&DevToolsPowerProfilerHost::SendWrapper, this, json_string));
|
| +}
|
| +
|
| +void DevToolsPowerProfilerHost::SendWrapper(const std::string& message) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (frontend_host_)
|
| + frontend_host_->SendPowerEvent(message);
|
| +}
|
| +
|
| +base::Time DevToolsPowerProfilerHost::convertMonotonicTimeToWallTime(
|
| + base::TimeTicks& tick) {
|
| + return base::Time::UnixEpoch() + (tick - base::TimeTicks::UnixEpoch());
|
| +}
|
|
|