diff options
author | nywang <nywang@chromium.org> | 2015-09-28 15:46:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-28 22:48:10 +0000 |
commit | a5523d02410fc00401b569cfcac06f71b09b1c66 (patch) | |
tree | a1a0a4151ffbd7304449a23021536920079b7ad5 /dbus | |
parent | 45cbfc953362be66bb1813b38d3c0d76a68fe9a0 (diff) | |
download | chromium_src-a5523d02410fc00401b569cfcac06f71b09b1c66.zip chromium_src-a5523d02410fc00401b569cfcac06f71b09b1c66.tar.gz chromium_src-a5523d02410fc00401b569cfcac06f71b09b1c66.tar.bz2 |
dbus: add support for synchronous PropertySet::Get
The existing PropertySet::Get function is asynchronous.
This CL adds the synchronous version of PropertySet::Get.
It is defined as PropertySet::GetAndBlock.
Also fix some typos and indent problems in previous
introduced SetAndBlock().
BUG=https://b.corp.google.com/u/0/issues/24131409
TEST=manually tested
Review URL: https://codereview.chromium.org/1368713002
Cr-Commit-Position: refs/heads/master@{#351185}
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/property.cc | 31 | ||||
-rw-r--r-- | dbus/property.h | 19 |
2 files changed, 46 insertions, 4 deletions
diff --git a/dbus/property.cc b/dbus/property.cc index b7a0c8b..234036c 100644 --- a/dbus/property.cc +++ b/dbus/property.cc @@ -133,6 +133,35 @@ void PropertySet::OnGet(PropertyBase* property, GetCallback callback, callback.Run(response); } +bool PropertySet::GetAndBlock(PropertyBase* property) { + MethodCall method_call(kPropertiesInterface, kPropertiesGet); + MessageWriter writer(&method_call); + writer.AppendString(interface()); + writer.AppendString(property->name()); + + DCHECK(object_proxy_); + scoped_ptr<dbus::Response> response( + object_proxy_->CallMethodAndBlock(&method_call, + ObjectProxy::TIMEOUT_USE_DEFAULT)); + + if (!response.get()) { + LOG(WARNING) << property->name() << ": GetAndBlock: failed."; + return false; + } + + MessageReader reader(response.get()); + if (property->PopValueFromReader(&reader)) { + property->set_valid(true); + NotifyPropertyChanged(property->name()); + } else { + if (property->is_valid()) { + property->set_valid(false); + NotifyPropertyChanged(property->name()); + } + } + return true; +} + void PropertySet::GetAll() { MethodCall method_call(kPropertiesInterface, kPropertiesGetAll); MessageWriter writer(&method_call); @@ -184,7 +213,7 @@ bool PropertySet::SetAndBlock(PropertyBase* property) { DCHECK(object_proxy_); scoped_ptr<dbus::Response> response( object_proxy_->CallMethodAndBlock(&method_call, - ObjectProxy::TIMEOUT_USE_DEFAULT)); + ObjectProxy::TIMEOUT_USE_DEFAULT)); if (response.get()) return true; return false; diff --git a/dbus/property.h b/dbus/property.h index 940ef715d..e379f8a 100644 --- a/dbus/property.h +++ b/dbus/property.h @@ -259,6 +259,10 @@ class CHROME_DBUS_EXPORT PropertySet { virtual void OnGet(PropertyBase* property, GetCallback callback, Response* response); + // The synchronous version of Get(). + // This should never be used on an interactive thread. + virtual bool GetAndBlock(PropertyBase* property); + // Queries the remote object for values of all properties and updates // initial values. Sub-classes may override to use a different D-Bus // method, or if the remote object does not support retrieving all @@ -276,11 +280,13 @@ class CHROME_DBUS_EXPORT PropertySet { // depending on the remote object. This method may be overridden by // sub-classes if interfaces use different method calls. virtual void Set(PropertyBase* property, SetCallback callback); - // The sychronous version of Set(). - virtual bool SetAndBlock(PropertyBase* property); virtual void OnSet(PropertyBase* property, SetCallback callback, Response* response); + // The synchronous version of Set(). + // This should never be used on an interactive thread. + virtual bool SetAndBlock(PropertyBase* property); + // Update properties by reading an array of dictionary entries, each // containing a string with the name and a variant with the value, from // |message_reader|. Returns false if message is in incorrect format. @@ -382,6 +388,12 @@ class CHROME_DBUS_EXPORT Property : public PropertyBase { property_set()->Get(this, callback); } + // The synchronous version of Get(). + // This should never be used on an interactive thread. + virtual bool GetAndBlock() { + return property_set()->GetAndBlock(this); + } + // Requests that the remote object change the property value to |value|, // |callback| will be called to indicate the success or failure of the // request, however the new value may not be available depending on the @@ -391,7 +403,8 @@ class CHROME_DBUS_EXPORT Property : public PropertyBase { property_set()->Set(this, callback); } - // The sychronous version of Set(). + // The synchronous version of Set(). + // This should never be used on an interactive thread. virtual bool SetAndBlock(const T& value) { set_value_ = value; return property_set()->SetAndBlock(this); |