| OLD | NEW |
| 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 #include "content/browser/devtools/protocol/power_handler.h" | 5 #include "content/browser/devtools/protocol/power_handler.h" |
| 6 | 6 |
| 7 #include "content/browser/power_profiler/power_profiler_service.h" | 7 #include "content/browser/power_profiler/power_profiler_service.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 namespace devtools { | 10 namespace devtools { |
| 11 namespace power { | 11 namespace power { |
| 12 | 12 |
| 13 typedef DevToolsProtocolClient::Response Response; | 13 typedef DevToolsProtocolClient::Response Response; |
| 14 | 14 |
| 15 PowerHandler::PowerHandler() : enabled_(false) { | 15 PowerHandler::PowerHandler() : enabled_(false) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 PowerHandler::~PowerHandler() { | 18 PowerHandler::~PowerHandler() { |
| 19 if (enabled_) | 19 if (enabled_) |
| 20 PowerProfilerService::GetInstance()->RemoveObserver(this); | 20 PowerProfilerService::GetInstance()->RemoveObserver(this); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void PowerHandler::SetClient(scoped_ptr<Client> client) { | 23 void PowerHandler::SetClient(scoped_ptr<Client> client) { |
| 24 client_.swap(client); | 24 client_.swap(client); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void PowerHandler::OnPowerEvent(const PowerEventVector& events) { | 27 void PowerHandler::OnPowerEvent(const PowerEventVector& events) { |
| 28 std::vector<PowerEvent> event_list; | 28 ListBuilder<PowerEvent> event_list; |
| 29 for (const auto& event : events) { | 29 for (const auto& event : events) { |
| 30 PowerEvent event_body; | |
| 31 DCHECK(event.type < content::PowerEvent::ID_COUNT); | 30 DCHECK(event.type < content::PowerEvent::ID_COUNT); |
| 32 event_body.set_type(kPowerTypeNames[event.type]); | |
| 33 // Use internal value to be consistent with Blink's | 31 // Use internal value to be consistent with Blink's |
| 34 // monotonicallyIncreasingTime. | 32 // monotonicallyIncreasingTime. |
| 35 event_body.set_timestamp(event.time.ToInternalValue() / | 33 double timestamp = event.time.ToInternalValue() / |
| 36 static_cast<double>(base::Time::kMicrosecondsPerMillisecond)); | 34 static_cast<double>(base::Time::kMicrosecondsPerMillisecond); |
| 37 event_body.set_value(event.value); | 35 event_list.push_back(PowerEvent::Create() |
| 38 event_list.push_back(event_body); | 36 .set_type(kPowerTypeNames[event.type]) |
| 37 .set_timestamp(timestamp) |
| 38 .set_value(event.value) |
| 39 .Pass()); |
| 39 } | 40 } |
| 40 DataAvailableParams params; | 41 client_->DataAvailable( |
| 41 params.set_value(event_list); | 42 DataAvailableParams::Create().set_value(event_list.Pass()).Pass()); |
| 42 client_->DataAvailable(params); | |
| 43 } | 43 } |
| 44 | 44 |
| 45 void PowerHandler::Detached() { | 45 void PowerHandler::Detached() { |
| 46 if (enabled_) { | 46 if (enabled_) { |
| 47 PowerProfilerService::GetInstance()->RemoveObserver(this); | 47 PowerProfilerService::GetInstance()->RemoveObserver(this); |
| 48 enabled_ = false; | 48 enabled_ = false; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 Response PowerHandler::Start() { | 52 Response PowerHandler::Start() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 Response PowerHandler::GetAccuracyLevel(std::string* result) { | 77 Response PowerHandler::GetAccuracyLevel(std::string* result) { |
| 78 if (!PowerProfilerService::GetInstance()->IsAvailable()) | 78 if (!PowerProfilerService::GetInstance()->IsAvailable()) |
| 79 return Response::InternalError("Power profiler service unavailable"); | 79 return Response::InternalError("Power profiler service unavailable"); |
| 80 *result = PowerProfilerService::GetInstance()->GetAccuracyLevel(); | 80 *result = PowerProfilerService::GetInstance()->GetAccuracyLevel(); |
| 81 return Response::OK(); | 81 return Response::OK(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace power | 84 } // namespace power |
| 85 } // namespace devtools | 85 } // namespace devtools |
| 86 } // namespace content | 86 } // namespace content |
| OLD | NEW |