| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 element->SetDouble("batteryDischargeRate", sample.battery_discharge_rate); | 90 element->SetDouble("batteryDischargeRate", sample.battery_discharge_rate); |
| 91 element->SetBoolean("externalPower", sample.external_power); | 91 element->SetBoolean("externalPower", sample.external_power); |
| 92 element->SetDouble("time", sample.time.ToJsTime()); | 92 element->SetDouble("time", sample.time.ToJsTime()); |
| 93 | 93 |
| 94 js_power_supply_data.Append(element.release()); | 94 js_power_supply_data.Append(element.release()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 base::ListValue js_system_resumed_data; | 97 base::ListValue js_system_resumed_data; |
| 98 GetJsSystemResumedData(&js_system_resumed_data); | 98 GetJsSystemResumedData(&js_system_resumed_data); |
| 99 | 99 |
| 100 web_ui()->CallJavascriptFunction(kOnRequestBatteryChargeDataFunction, | 100 web_ui()->CallJavascriptFunctionUnsafe(kOnRequestBatteryChargeDataFunction, |
| 101 js_power_supply_data, | 101 js_power_supply_data, |
| 102 js_system_resumed_data); | 102 js_system_resumed_data); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void PowerMessageHandler::OnGetCpuIdleData(const base::ListValue* value) { | 105 void PowerMessageHandler::OnGetCpuIdleData(const base::ListValue* value) { |
| 106 const CpuDataCollector& cpu_data_collector = | 106 const CpuDataCollector& cpu_data_collector = |
| 107 PowerDataCollector::Get()->cpu_data_collector(); | 107 PowerDataCollector::Get()->cpu_data_collector(); |
| 108 | 108 |
| 109 const std::vector<CpuDataCollector::StateOccupancySampleDeque>& idle_data = | 109 const std::vector<CpuDataCollector::StateOccupancySampleDeque>& idle_data = |
| 110 cpu_data_collector.cpu_idle_state_data(); | 110 cpu_data_collector.cpu_idle_state_data(); |
| 111 const std::vector<std::string>& idle_state_names = | 111 const std::vector<std::string>& idle_state_names = |
| 112 cpu_data_collector.cpu_idle_state_names(); | 112 cpu_data_collector.cpu_idle_state_names(); |
| 113 base::ListValue js_idle_data; | 113 base::ListValue js_idle_data; |
| 114 GetJsStateOccupancyData(idle_data, idle_state_names, &js_idle_data); | 114 GetJsStateOccupancyData(idle_data, idle_state_names, &js_idle_data); |
| 115 | 115 |
| 116 base::ListValue js_system_resumed_data; | 116 base::ListValue js_system_resumed_data; |
| 117 GetJsSystemResumedData(&js_system_resumed_data); | 117 GetJsSystemResumedData(&js_system_resumed_data); |
| 118 | 118 |
| 119 web_ui()->CallJavascriptFunction(kOnRequestCpuIdleDataFunction, | 119 web_ui()->CallJavascriptFunctionUnsafe(kOnRequestCpuIdleDataFunction, |
| 120 js_idle_data, | 120 js_idle_data, js_system_resumed_data); |
| 121 js_system_resumed_data); | |
| 122 } | 121 } |
| 123 | 122 |
| 124 void PowerMessageHandler::OnGetCpuFreqData(const base::ListValue* value) { | 123 void PowerMessageHandler::OnGetCpuFreqData(const base::ListValue* value) { |
| 125 const CpuDataCollector& cpu_data_collector = | 124 const CpuDataCollector& cpu_data_collector = |
| 126 PowerDataCollector::Get()->cpu_data_collector(); | 125 PowerDataCollector::Get()->cpu_data_collector(); |
| 127 | 126 |
| 128 const std::vector<CpuDataCollector::StateOccupancySampleDeque>& freq_data = | 127 const std::vector<CpuDataCollector::StateOccupancySampleDeque>& freq_data = |
| 129 cpu_data_collector.cpu_freq_state_data(); | 128 cpu_data_collector.cpu_freq_state_data(); |
| 130 const std::vector<std::string>& freq_state_names = | 129 const std::vector<std::string>& freq_state_names = |
| 131 cpu_data_collector.cpu_freq_state_names(); | 130 cpu_data_collector.cpu_freq_state_names(); |
| 132 base::ListValue js_freq_data; | 131 base::ListValue js_freq_data; |
| 133 GetJsStateOccupancyData(freq_data, freq_state_names, &js_freq_data); | 132 GetJsStateOccupancyData(freq_data, freq_state_names, &js_freq_data); |
| 134 | 133 |
| 135 base::ListValue js_system_resumed_data; | 134 base::ListValue js_system_resumed_data; |
| 136 GetJsSystemResumedData(&js_system_resumed_data); | 135 GetJsSystemResumedData(&js_system_resumed_data); |
| 137 | 136 |
| 138 web_ui()->CallJavascriptFunction(kOnRequestCpuFreqDataFunction, | 137 web_ui()->CallJavascriptFunctionUnsafe(kOnRequestCpuFreqDataFunction, |
| 139 js_freq_data, | 138 js_freq_data, js_system_resumed_data); |
| 140 js_system_resumed_data); | |
| 141 } | 139 } |
| 142 | 140 |
| 143 void PowerMessageHandler::GetJsSystemResumedData(base::ListValue *data) { | 141 void PowerMessageHandler::GetJsSystemResumedData(base::ListValue *data) { |
| 144 DCHECK(data); | 142 DCHECK(data); |
| 145 | 143 |
| 146 const std::deque<PowerDataCollector::SystemResumedSample>& system_resumed = | 144 const std::deque<PowerDataCollector::SystemResumedSample>& system_resumed = |
| 147 PowerDataCollector::Get()->system_resumed_data(); | 145 PowerDataCollector::Get()->system_resumed_data(); |
| 148 for (size_t i = 0; i < system_resumed.size(); ++i) { | 146 for (size_t i = 0; i < system_resumed.size(); ++i) { |
| 149 const PowerDataCollector::SystemResumedSample& sample = system_resumed[i]; | 147 const PowerDataCollector::SystemResumedSample& sample = system_resumed[i]; |
| 150 std::unique_ptr<base::DictionaryValue> element(new base::DictionaryValue); | 148 std::unique_ptr<base::DictionaryValue> element(new base::DictionaryValue); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 html->SetDefaultResource(IDR_ABOUT_POWER_HTML); | 235 html->SetDefaultResource(IDR_ABOUT_POWER_HTML); |
| 238 | 236 |
| 239 Profile* profile = Profile::FromWebUI(web_ui); | 237 Profile* profile = Profile::FromWebUI(web_ui); |
| 240 content::WebUIDataSource::Add(profile, html); | 238 content::WebUIDataSource::Add(profile, html); |
| 241 } | 239 } |
| 242 | 240 |
| 243 PowerUI::~PowerUI() { | 241 PowerUI::~PowerUI() { |
| 244 } | 242 } |
| 245 | 243 |
| 246 } // namespace chromeos | 244 } // namespace chromeos |
| OLD | NEW |