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 #include "chrome/browser/devtools/devtools_power_profiler_host.h" |
| 6 |
| 7 #include "base/json/json_writer.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 |
| 12 using namespace content; |
| 13 |
| 14 DevToolsPowerProfilerHost::DevToolsPowerProfilerHost( |
| 15 const base::WeakPtr<DevToolsWindow>& host) : frontend_host_(host) { |
| 16 SetResolution(HIGH); |
| 17 } |
| 18 |
| 19 void DevToolsPowerProfilerHost::convertPowerValueToJSONObject( |
| 20 base::DictionaryValue* object, PowerEvent* event) { |
| 21 const base::TimeTicks kNullTicks; |
| 22 object->SetDouble("timestamp", |
| 23 convertMonotonicTimeToWallTime(event->time).ToDoubleT() * 1000.0); |
| 24 object->SetDouble("value", event->value); |
| 25 switch (event->type) { |
| 26 case PowerEvent::SOC_PACKAGE: |
| 27 object->SetString("type", "SoC_Package"); |
| 28 break; |
| 29 default: |
| 30 NOTREACHED(); |
| 31 break; |
| 32 } |
| 33 } |
| 34 |
| 35 void DevToolsPowerProfilerHost::Send(PowerEvent* event) { |
| 36 std::string json_string; |
| 37 base::DictionaryValue message_object; |
| 38 base::DictionaryValue* params = new base::DictionaryValue(); |
| 39 base::ListValue* event_list = new base::ListValue(); |
| 40 |
| 41 base::DictionaryValue* value = new base::DictionaryValue(); |
| 42 convertPowerValueToJSONObject(value, event); |
| 43 event_list->Append(value); |
| 44 |
| 45 params->Set("powerEvents", event_list); |
| 46 message_object.Set("params", params); |
| 47 message_object.SetString("method", "Power.PowerEventsReceived"); |
| 48 |
| 49 base::JSONWriter::Write(&message_object, &json_string); |
| 50 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 51 base::Bind(&DevToolsPowerProfilerHost::SendWrapper, this, json_string)); |
| 52 } |
| 53 |
| 54 void DevToolsPowerProfilerHost::SendWrapper(const std::string& message) { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 56 if (frontend_host_) |
| 57 frontend_host_->SendPowerEvent(message); |
| 58 } |
| 59 |
| 60 base::Time DevToolsPowerProfilerHost::convertMonotonicTimeToWallTime( |
| 61 base::TimeTicks& tick) { |
| 62 return base::Time::UnixEpoch() + (tick - base::TimeTicks::UnixEpoch()); |
| 63 } |
OLD | NEW |