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

Side by Side Diff: chrome/browser/resources/settings/device_page/power.js

Issue 2629573006: chromeos: Add Power device page to chrome://md-settings. (Closed)
Patch Set: update now that power source settings exist Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * 'settings-power' is the settings subpage for power settings.
8 */
9 Polymer({
10 is: 'settings-power',
11
12 behaviors: [
13 I18nBehavior,
14 WebUIListenerBehavior,
15 ],
16
17 properties: {
18 enablePowerSettings: Boolean,
michaelpg 2017/03/01 05:20:39 if this is false, we probably should bail out in r
Daniel Erat 2017/03/01 23:01:53 done (i think; let me know if i got it wrong)
19
20 /** @private {string} ID of the selected power source, or ''. */
21 selectedPowerSourceId_: String,
22
23 /** @private {!settings.BatteryStatus|undefined} */
24 batteryStatus_: Object,
25
26 /** @private {boolean} Whether a low-power (USB) charger is being used. */
27 lowPowerCharger_: Boolean,
28
29 /**
30 * List of available dual-role power sources, if enablePowerSettings_ is on.
michaelpg 2017/03/01 05:20:39 enablePowerSettings (no underscore)
Daniel Erat 2017/03/01 23:01:53 Done.
31 * @private {!Array<!settings.PowerSource>|undefined}
32 */
33 powerSources_: Array,
34
35 /** @private */
36 powerSourceLabel_: {
37 type: String,
38 computed:
39 'computePowerSourceLabel_(powerSources_, batteryStatus_.calculating)',
40 },
41
42 /** @private */
43 showPowerSourceDropdown_: {
44 type: Boolean,
45 computed: 'computeShowPowerSourceDropdown_(powerSources_)',
46 value: false,
47 },
48
49 /**
50 * The name of the dedicated charging device being used, if present.
51 * @private {string}
52 */
53 powerSourceName_: {
54 type: String,
55 computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)',
56 },
57 },
58
59 /** @override */
60 attached: function() {
61 if (this.enablePowerSettings) {
stevenjb 2017/03/01 17:19:43 In practice this is fine since enablePowerSettings
Daniel Erat 2017/03/01 23:01:53 Done.
62 this.addWebUIListener(
63 'battery-status-changed', this.set.bind(this, 'batteryStatus_'));
64 this.addWebUIListener(
65 'power-sources-changed', this.powerSourcesChanged_.bind(this));
66 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus();
67 }
68 },
69
70 /**
71 * @param {!Array<!settings.PowerSource>|undefined} powerSources
72 * @param {boolean} calculating
73 * @return {string} The primary label for the power source row.
74 * @private
75 */
76 computePowerSourceLabel_: function(powerSources, calculating) {
77 return this.i18n(
78 calculating ?
79 'calculatingPower' :
80 powerSources.length ? 'powerSourceLabel' : 'powerSourceBattery');
81 },
82
83 /**
84 * @param {!Array<!settings.PowerSource>} powerSources
85 * @return {boolean} True if at least one power source is attached and all of
86 * them are dual-role (no dedicated chargers).
87 * @private
88 */
89 computeShowPowerSourceDropdown_: function(powerSources) {
90 return powerSources.length > 0 && powerSources.every(function(source) {
91 return source.type == settings.PowerDeviceType.DUAL_ROLE_USB;
92 });
93 },
94
95 /**
96 * @param {!Array<!settings.PowerSource>} powerSources
97 * @param {boolean} lowPowerCharger
98 * @return {string} Description of the power source.
99 * @private
100 */
101 computePowerSourceName_: function(powerSources, lowPowerCharger) {
102 if (lowPowerCharger)
103 return this.i18n('powerSourceLowPowerCharger');
104 if (powerSources.length)
105 return this.i18n('powerSourceAcAdapter');
106 return '';
107 },
108
109 onPowerSourceChange_: function() {
110 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource(
111 this.$$('#powerSource').value);
112 },
113
114 /**
115 * @param {!Array<settings.PowerSource>} sources External power sources.
116 * @param {string} selectedId The ID of the currently used power source.
117 * @param {boolean} lowPowerCharger Whether the currently used power source
118 * is a low-powered USB charger.
119 * @private
120 */
121 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) {
122 this.powerSources_ = sources;
123 this.selectedPowerSourceId_ = selectedId;
124 this.lowPowerCharger_ = lowPowerCharger;
125 },
126
127 /**
128 * @param {*} lhs
129 * @param {*} rhs
130 * @return {boolean}
131 * @private
132 */
133 isEqual_: function(lhs, rhs) {
134 return lhs === rhs;
135 },
136 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698