Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/ui/webui/chromeos/power_ui.cc

Issue 140663004: [chromeos] Add a battery discharge rate plot to about:power page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/chromeos/power.js ('k') | chromeos/power/power_data_collector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const std::deque<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() - snapshot.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->SetDouble("battery_discharge_rate",
68 snapshot.battery_discharge_rate);
67 element->SetBoolean("external_power", snapshot.external_power); 69 element->SetBoolean("external_power", snapshot.external_power);
68 element->SetDouble("time", time.ToJsTime()); 70 element->SetDouble("time", time.ToJsTime());
69 71
70 data.Append(element.release()); 72 data.Append(element.release());
71 } 73 }
72 74
73 web_ui()->CallJavascriptFunction(kOnRequestBatteryChargeDataFunction, data); 75 web_ui()->CallJavascriptFunction(kOnRequestBatteryChargeDataFunction, data);
74 } 76 }
75 77
76 } // namespace 78 } // namespace
77 79
78 PowerUI::PowerUI(content::WebUI* web_ui) : content::WebUIController(web_ui) { 80 PowerUI::PowerUI(content::WebUI* web_ui) : content::WebUIController(web_ui) {
79 web_ui->AddMessageHandler(new PowerMessageHandler()); 81 web_ui->AddMessageHandler(new PowerMessageHandler());
80 82
81 content::WebUIDataSource* html = 83 content::WebUIDataSource* html =
82 content::WebUIDataSource::Create(chrome::kChromeUIPowerHost); 84 content::WebUIDataSource::Create(chrome::kChromeUIPowerHost);
83 html->SetUseJsonJSFormatV2(); 85 html->SetUseJsonJSFormatV2();
84 86
85 html->AddLocalizedString("titleText", IDS_ABOUT_POWER_TITLE); 87 html->AddLocalizedString("titleText", IDS_ABOUT_POWER_TITLE);
86 html->AddLocalizedString("reloadButton", IDS_ABOUT_POWER_RELOAD_BUTTON); 88 html->AddLocalizedString("reloadButton", IDS_ABOUT_POWER_RELOAD_BUTTON);
87 html->AddLocalizedString("batteryChargeHeader", 89 html->AddLocalizedString("batteryChargePercentageHeader",
88 IDS_ABOUT_POWER_BATTERY_CHARGE_HEADER); 90 IDS_ABOUT_POWER_BATTERY_CHARGE_PERCENTAGE_HEADER);
91 html->AddLocalizedString("batteryDischargeRateHeader",
92 IDS_ABOUT_POWER_BATTERY_DISCHARGE_RATE_HEADER);
93 html->AddLocalizedString("negativeDischargeRateInfo",
94 IDS_ABOUT_POWER_NEGATIVE_DISCHARGE_RATE_INFO);
89 html->AddLocalizedString("notEnoughDataAvailableYet", 95 html->AddLocalizedString("notEnoughDataAvailableYet",
90 IDS_ABOUT_POWER_NOT_ENOUGH_DATA); 96 IDS_ABOUT_POWER_NOT_ENOUGH_DATA);
91 html->AddLocalizedString("timeAndPlotDataMismatch", 97 html->AddLocalizedString("timeAndPlotDataMismatch",
92 IDS_ABOUT_POWER_TIME_AND_PLOT_DATA_MISMATCH); 98 IDS_ABOUT_POWER_TIME_AND_PLOT_DATA_MISMATCH);
93 html->SetJsonPath(kStringsJsFile); 99 html->SetJsonPath(kStringsJsFile);
94 100
95 html->AddResourcePath("power.css", IDR_ABOUT_POWER_CSS); 101 html->AddResourcePath("power.css", IDR_ABOUT_POWER_CSS);
96 html->AddResourcePath("power.js", IDR_ABOUT_POWER_JS); 102 html->AddResourcePath("power.js", IDR_ABOUT_POWER_JS);
97 html->SetDefaultResource(IDR_ABOUT_POWER_HTML); 103 html->SetDefaultResource(IDR_ABOUT_POWER_HTML);
98 104
99 Profile* profile = Profile::FromWebUI(web_ui); 105 Profile* profile = Profile::FromWebUI(web_ui);
100 content::WebUIDataSource::Add(profile, html); 106 content::WebUIDataSource::Add(profile, html);
101 } 107 }
102 108
103 PowerUI::~PowerUI() { 109 PowerUI::~PowerUI() {
104 } 110 }
105 111
106 } // namespace chromeos 112 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/power.js ('k') | chromeos/power/power_data_collector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698