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 "chrome/browser/ui/webui/chromeos/power_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/power_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 void PowerMessageHandler::RegisterMessages() { | 49 void PowerMessageHandler::RegisterMessages() { |
50 web_ui()->RegisterMessageCallback( | 50 web_ui()->RegisterMessageCallback( |
51 kRequestBatteryChargeDataCallback, | 51 kRequestBatteryChargeDataCallback, |
52 base::Bind(&PowerMessageHandler::OnGetBatteryChargeData, | 52 base::Bind(&PowerMessageHandler::OnGetBatteryChargeData, |
53 base::Unretained(this))); | 53 base::Unretained(this))); |
54 } | 54 } |
55 | 55 |
56 void PowerMessageHandler::OnGetBatteryChargeData(const base::ListValue* value) { | 56 void PowerMessageHandler::OnGetBatteryChargeData(const base::ListValue* value) { |
57 const std::vector<PowerDataCollector::PowerSupplySnapshot>& power_supply = | 57 const std::deque<PowerDataCollector::PowerSupplySnapshot>& power_supply = |
58 PowerDataCollector::Get()->power_supply_data(); | 58 PowerDataCollector::Get()->power_supply_data(); |
59 base::ListValue data; | 59 base::ListValue data; |
60 | 60 |
61 for (unsigned int i = 0; i < power_supply.size(); ++i) { | 61 for (unsigned int i = 0; i < power_supply.size(); ++i) { |
62 const PowerDataCollector::PowerSupplySnapshot& snapshot = power_supply[i]; | 62 const PowerDataCollector::PowerSupplySnapshot& snapshot = power_supply[i]; |
63 base::Time time = base::Time::Now() - | 63 base::Time time = base::Time::Now() - |
64 (base::TimeTicks::Now() - power_supply[i].time); | 64 (base::TimeTicks::Now() - snapshot.time); |
65 scoped_ptr<base::DictionaryValue> element(new base::DictionaryValue); | 65 scoped_ptr<base::DictionaryValue> element(new base::DictionaryValue); |
66 element->SetDouble("battery_percent", snapshot.battery_percent); | 66 element->SetDouble("battery_percent", snapshot.battery_percent); |
67 element->SetBoolean("external_power", snapshot.external_power); | 67 element->SetBoolean("external_power", snapshot.external_power); |
68 element->SetDouble("time", time.ToJsTime()); | 68 element->SetDouble("time", time.ToJsTime()); |
69 | 69 |
70 data.Append(element.release()); | 70 data.Append(element.release()); |
71 } | 71 } |
72 | 72 |
73 web_ui()->CallJavascriptFunction(kOnRequestBatteryChargeDataFunction, data); | 73 web_ui()->CallJavascriptFunction(kOnRequestBatteryChargeDataFunction, data); |
74 } | 74 } |
(...skipping 22 matching lines...) Expand all Loading... |
97 html->SetDefaultResource(IDR_ABOUT_POWER_HTML); | 97 html->SetDefaultResource(IDR_ABOUT_POWER_HTML); |
98 | 98 |
99 Profile* profile = Profile::FromWebUI(web_ui); | 99 Profile* profile = Profile::FromWebUI(web_ui); |
100 content::WebUIDataSource::Add(profile, html); | 100 content::WebUIDataSource::Add(profile, html); |
101 } | 101 } |
102 | 102 |
103 PowerUI::~PowerUI() { | 103 PowerUI::~PowerUI() { |
104 } | 104 } |
105 | 105 |
106 } // namespace chromeos | 106 } // namespace chromeos |
OLD | NEW |