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 std::vector<scoped_refptr<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 } | 39 } |
40 DataAvailableParams params; | 40 client_->DataAvailable(DataAvailableParams::Create()->set_value(event_list)); |
41 params.set_value(event_list); | |
42 client_->DataAvailable(params); | |
43 } | 41 } |
44 | 42 |
45 void PowerHandler::Detached() { | 43 void PowerHandler::Detached() { |
46 if (enabled_) { | 44 if (enabled_) { |
47 PowerProfilerService::GetInstance()->RemoveObserver(this); | 45 PowerProfilerService::GetInstance()->RemoveObserver(this); |
48 enabled_ = false; | 46 enabled_ = false; |
49 } | 47 } |
50 } | 48 } |
51 | 49 |
52 Response PowerHandler::Start() { | 50 Response PowerHandler::Start() { |
(...skipping 24 matching lines...) Expand all Loading... |
77 Response PowerHandler::GetAccuracyLevel(std::string* result) { | 75 Response PowerHandler::GetAccuracyLevel(std::string* result) { |
78 if (!PowerProfilerService::GetInstance()->IsAvailable()) | 76 if (!PowerProfilerService::GetInstance()->IsAvailable()) |
79 return Response::InternalError("Power profiler service unavailable"); | 77 return Response::InternalError("Power profiler service unavailable"); |
80 *result = PowerProfilerService::GetInstance()->GetAccuracyLevel(); | 78 *result = PowerProfilerService::GetInstance()->GetAccuracyLevel(); |
81 return Response::OK(); | 79 return Response::OK(); |
82 } | 80 } |
83 | 81 |
84 } // namespace power | 82 } // namespace power |
85 } // namespace devtools | 83 } // namespace devtools |
86 } // namespace content | 84 } // namespace content |
OLD | NEW |