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

Issue 436683002: Battery Status API: implementation for Linux. (Closed)

Created:
6 years, 4 months ago by timvolodine
Modified:
6 years, 4 months ago
CC:
chromium-reviews, darin-cc_chromium.org, jam, stevenjb
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Project:
chromium
Visibility:
Public.

Description

Battery Status API: implementation for Linux. Implementation of the Battery Status API for the Linux platform. Implementation uses DBus to talk to org.freedesktop.UPower service to obtain battery information. BUG=122593 TEST=http://jsbin.com/battery-status-test (manual) TBR=brettw@chromium.org NOTRY=true Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=289372 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=289431

Patch Set 1 #

Patch Set 2 : rebase #

Total comments: 23

Patch Set 3 : fixed comments #

Total comments: 28

Patch Set 4 : addressed many comments #

Patch Set 5 : fix BUILD.gn #

Total comments: 89

Patch Set 6 : hashimoto's comments #

Patch Set 7 : more comments #

Patch Set 8 : cleanup and comments in notification thread destructor #

Total comments: 19

Patch Set 9 : comments #

Patch Set 10 : fix chromeOS build #

Unified diffs Side-by-side diffs Delta from patch set Stats (+564 lines, -1 line) Patch
M content/browser/BUILD.gn View 1 2 3 4 5 6 7 8 9 1 chunk +5 lines, -1 line 0 comments Download
A content/browser/battery_status/battery_status_manager_linux.h View 1 2 3 4 5 6 1 chunk +34 lines, -0 lines 0 comments Download
A content/browser/battery_status/battery_status_manager_linux.cc View 1 2 3 4 5 6 7 8 1 chunk +374 lines, -0 lines 0 comments Download
A content/browser/battery_status/battery_status_manager_linux_unittest.cc View 1 2 3 4 5 6 7 8 1 chunk +143 lines, -0 lines 0 comments Download
M content/content_browser.gypi View 1 2 3 4 5 6 7 8 9 4 chunks +5 lines, -0 lines 0 comments Download
M content/content_tests.gypi View 1 2 3 4 5 6 7 8 9 3 chunks +3 lines, -0 lines 0 comments Download

Messages

Total messages: 35 (0 generated)
timvolodine
6 years, 4 months ago (2014-07-31 18:32:11 UTC) #1
Michael van Ouwerkerk
https://codereview.chromium.org/436683002/diff/20001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/20001/content/browser/battery_status/battery_status_manager_linux.cc#newcode125 content/browser/battery_status/battery_status_manager_linux.cc:125: // TODO(timvolodine): add support for multiple batteries. Currently we ...
6 years, 4 months ago (2014-08-01 15:24:39 UTC) #2
mlamouri (slow - plz ping)
https://codereview.chromium.org/436683002/diff/20001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/20001/content/browser/battery_status/battery_status_manager_linux.cc#newcode17 content/browser/battery_status/battery_status_manager_linux.cc:17: #include "third_party/cros_system_api/dbus/service_constants.h" I think you should remove that #include. ...
6 years, 4 months ago (2014-08-01 17:14:14 UTC) #3
timvolodine
thanks for the comments, replies below. https://codereview.chromium.org/436683002/diff/20001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/20001/content/browser/battery_status/battery_status_manager_linux.cc#newcode17 content/browser/battery_status/battery_status_manager_linux.cc:17: #include "third_party/cros_system_api/dbus/service_constants.h" On ...
6 years, 4 months ago (2014-08-06 16:37:43 UTC) #4
mlamouri (slow - plz ping)
lgtm with my comments applied. But please, get someone else to review this. Someone who ...
6 years, 4 months ago (2014-08-07 16:17:05 UTC) #5
timvolodine
+ adding Elliot as Linux expert to have a look at DBus and linux specifics.
6 years, 4 months ago (2014-08-07 17:53:14 UTC) #6
Elliot Glaysher
I don't believe I've ever used our dbus implementation; I don't think I have anything ...
6 years, 4 months ago (2014-08-07 18:08:28 UTC) #7
timvolodine
+ Scott as one of the dbus/ owners. Scott, this patch uses dbus could you ...
6 years, 4 months ago (2014-08-07 18:51:44 UTC) #8
timvolodine
+ cc: stevenjb@ as another owner of dbus.
6 years, 4 months ago (2014-08-08 12:52:33 UTC) #9
Michael van Ouwerkerk
https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.cc#newcode30 content/browser/battery_status/battery_status_manager_linux.cc:30: // intended for unit32, int64, uint64, double. s/unit32/uint32/ https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.h ...
6 years, 4 months ago (2014-08-08 14:54:59 UTC) #10
stevenjb
+satorux@, +hashimoto@ who are much more familiar with the low level DBus module than I ...
6 years, 4 months ago (2014-08-08 16:18:16 UTC) #11
mlamouri (slow - plz ping)
https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.h File content/browser/battery_status/battery_status_manager_linux.h (right): https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.h#newcode28 content/browser/battery_status/battery_status_manager_linux.h:28: CONTENT_EXPORT void ComputeWebBatteryStatus( On 2014/08/08 14:54:59, Michael van Ouwerkerk ...
6 years, 4 months ago (2014-08-08 17:31:00 UTC) #12
timvolodine
https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/40001/content/browser/battery_status/battery_status_manager_linux.cc#newcode30 content/browser/battery_status/battery_status_manager_linux.cc:30: // intended for unit32, int64, uint64, double. On 2014/08/08 ...
6 years, 4 months ago (2014-08-08 18:46:46 UTC) #13
Michael van Ouwerkerk
lgtm
6 years, 4 months ago (2014-08-08 18:54:51 UTC) #14
hashimoto
https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode44 content/browser/battery_status/battery_status_manager_linux.cc:44: // intended for uint32, int64, uint64, double. I see ...
6 years, 4 months ago (2014-08-11 08:19:16 UTC) #15
hashimoto
On 2014/08/08 16:18:16, stevenjb wrote: > +satorux@, +hashimoto@ who are much more familiar with the ...
6 years, 4 months ago (2014-08-11 08:47:38 UTC) #16
timvolodine
https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode44 content/browser/battery_status/battery_status_manager_linux.cc:44: // intended for uint32, int64, uint64, double. On 2014/08/11 ...
6 years, 4 months ago (2014-08-11 16:03:01 UTC) #17
timvolodine
+ brettw@ : for content/browser/BUILD.gn
6 years, 4 months ago (2014-08-11 17:13:00 UTC) #18
hashimoto
https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode66 content/browser/battery_status/battery_status_manager_linux.cc:66: kDBusPropertiesGetAll); On 2014/08/11 16:02:59, timvolodine wrote: > On 2014/08/11 ...
6 years, 4 months ago (2014-08-12 10:01:43 UTC) #19
timvolodine
https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode66 content/browser/battery_status/battery_status_manager_linux.cc:66: kDBusPropertiesGetAll); On 2014/08/12 10:01:42, hashimoto wrote: > On 2014/08/11 ...
6 years, 4 months ago (2014-08-12 19:27:53 UTC) #20
hashimoto
https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode82 content/browser/battery_status/battery_status_manager_linux.cc:82: return scoped_ptr<base::DictionaryValue>(new base::DictionaryValue()); On 2014/08/11 16:02:59, timvolodine wrote: > ...
6 years, 4 months ago (2014-08-13 11:02:21 UTC) #21
timvolodine
https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode82 content/browser/battery_status/battery_status_manager_linux.cc:82: return scoped_ptr<base::DictionaryValue>(new base::DictionaryValue()); On 2014/08/13 11:02:20, hashimoto wrote: > ...
6 years, 4 months ago (2014-08-13 16:58:09 UTC) #22
timvolodine
+ TBR=brettw@ : for content/browser/BUILD.gn
6 years, 4 months ago (2014-08-13 16:59:13 UTC) #23
timvolodine
The CQ bit was checked by timvolodine@chromium.org
6 years, 4 months ago (2014-08-13 16:59:22 UTC) #24
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/timvolodine@chromium.org/436683002/160001
6 years, 4 months ago (2014-08-13 17:00:28 UTC) #25
timvolodine
The CQ bit was unchecked by timvolodine@chromium.org
6 years, 4 months ago (2014-08-13 20:45:47 UTC) #26
timvolodine
The CQ bit was checked by timvolodine@chromium.org
6 years, 4 months ago (2014-08-13 20:46:41 UTC) #27
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/timvolodine@chromium.org/436683002/160001
6 years, 4 months ago (2014-08-13 20:49:24 UTC) #28
commit-bot: I haz the power
Committed patchset #9 (160001) as 289372
6 years, 4 months ago (2014-08-13 20:54:06 UTC) #29
timvolodine
The CQ bit was checked by timvolodine@chromium.org
6 years, 4 months ago (2014-08-14 00:45:43 UTC) #30
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/timvolodine@chromium.org/436683002/180001
6 years, 4 months ago (2014-08-14 00:49:25 UTC) #31
commit-bot: I haz the power
Committed patchset #10 (180001) as 289431
6 years, 4 months ago (2014-08-14 00:54:39 UTC) #32
hashimoto
Leaving my not lgtm for the record. https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc File content/browser/battery_status/battery_status_manager_linux.cc (right): https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_status/battery_status_manager_linux.cc#newcode66 content/browser/battery_status/battery_status_manager_linux.cc:66: kDBusPropertiesGetAll); On ...
6 years, 4 months ago (2014-08-14 04:17:05 UTC) #33
timvolodine
hashimoto@: Is there a specific reason for your !lgtm? If that's because of the PropertySet, ...
6 years, 4 months ago (2014-08-14 22:02:45 UTC) #34
hashimoto
6 years, 4 months ago (2014-08-15 02:07:00 UTC) #35
Message was sent while issue was closed.
PowerManagerClient was made to communicate with Chrome OS's PowerManager.
I don't think we can port it to Linux.

https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_...
File content/browser/battery_status/battery_status_manager_linux.cc (right):

https://codereview.chromium.org/436683002/diff/80001/content/browser/battery_...
content/browser/battery_status/battery_status_manager_linux.cc:221: // default
values.
On 2014/08/14 22:02:45, timvolodine wrote:
> On 2014/08/14 04:17:04, hashimoto wrote:
> > On 2014/08/13 16:58:08, timvolodine wrote:
> > > On 2014/08/13 11:02:20, hashimoto wrote:
> > > > On 2014/08/12 19:27:53, timvolodine wrote:
> > > > > On 2014/08/12 10:01:42, hashimoto wrote:
> > > > > > On 2014/08/11 16:03:00, timvolodine wrote:
> > > > > > > On 2014/08/11 08:19:15, hashimoto wrote:
> > > > > > > > Why do we need to do this?
> > > > > > > 
> > > > > > > this means we cannot get battery updates, so need to propagate
> default
> > > > > values
> > > > > > to
> > > > > > > blink (i.e. meaning we cannot provide battery information
according
> to
> > > > > > > specification)
> > > > > > 
> > > > > > It seems the Chrome OS implmentation is not doing the same thing
when
> > > > > > PowerManager fails to connect to the signal.
> > > > > > Is this really needed?
> > > > > 
> > > > > I believe this is needed to cover the following (unlikely) situation:
> > > imagine
> > > > we
> > > > > can get current battery status, but fail to connect to the signal. We
> have
> > > two
> > > > > options:
> > > > > 1. either execute callback with the current status and do nothing, or
> > > > > 2. execute the callback with default values (meaning cannot provide
data
> > > > > according to spec).
> > > > > 
> > > > > I think option 2 is better as option 1 would result in stale data
after
> > some
> > > > > time which would be misleading. ChromeOS probably follows option 1 and
> we
> > > > should
> > > > > see if this can be fixed.
> > > > 
> > > > When something goes wrong with D-Bus, it seems the current Chrome OS
> > > > implementation does nothing because PowerChanged() never gets called in
> > error
> > > > cases.
> > > > Also, it's more natural to do nothing than running the observer callback
> > with
> > > > the default value reserved to indicate an error.
> > > 
> > > I think ChromeOS actually forces one callback on start:
> > >
> >
>
https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/ba...
> > That RequestStatusUpdate() results in nothing if an error happens.
> 
> What I meant is that callback SignalConnected() is ignored in
> power_manager_client.cc (it simply logs a warning if it fails). So I was
> referring to the (hypothetical) case where the SignalConnected fails but the
> properties can be read from dbus in which case RequestStatusUpdate will
> propagate to observers.
>
https://code.google.com/p/chromium/codesearch#chromium/src/chromeos/dbus/powe...

You shouldn't expect the service to return responses for method calls when
SignalConnected() fails.

https://codereview.chromium.org/436683002/diff/140001/content/browser/battery...
File content/browser/battery_status/battery_status_manager_linux.cc (right):

https://codereview.chromium.org/436683002/diff/140001/content/browser/battery...
content/browser/battery_status/battery_status_manager_linux.cc:194:
options.connection_type = dbus::Bus::PRIVATE;
On 2014/08/14 22:02:45, timvolodine wrote:
> On 2014/08/14 04:17:05, hashimoto wrote:
> > On 2014/08/13 16:58:09, timvolodine wrote:
> > > On 2014/08/13 11:02:21, hashimoto wrote:
> > > > BTW, why don't you set options.dbus_task_runner?
> > > > This way you don't have to implement thread related logic after all.
> > > > 
> > > > Also, it makes it easy to introduce DBusThreadManager-ish object to
Linux
> > > > Chrome. (please refer to stevenjb@'s comment).
> > > 
> > > currently dbus runs on this thread anyway not sure what would I set the
> > > dbus_task_runner to.. Yes, ideally we would have DBusThreadManager for
> linux,
> > > like chromeOS does, I suppose that would make dbus implementations
simpler.
> > 
> > What I meant was owning the bus on the IO thread and let the bus handle all
> > D-Bus related business on another thread.
> > This way every code you write would be running on the IO thread.
> 
> yes that's another possibility, but since we don't have a dbus thread on linux
> we need to run a separate thread anyway. Furthermore if on IO thread we cannot
> do blocking calls, which would complicate the implementation because we would
> need to fetch the information asynchronously. Note that current Geolocation
> implementation for linux does a similar thing.
By using it you don't have to manually post tasks to the thread.
Adding a few callbacks to handle asynchronous steps isn't anything.

On Linux, developers tend to write their own code to setup dbus::Bus only
because there is no DBusThreadManager.
Having many classes which set up their own dbus::Bus is not desirable as Steven
said.
It's better to follow MediaTransferProtocolManager's example.

Powered by Google App Engine
This is Rietveld 408576698