summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/session_manager_client.cc
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-24 12:33:44 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-24 12:33:44 +0000
commitc8252d4a18cf50c07ce68fb737b73e103dc1ef52 (patch)
tree50757b7d1fbd37a30fd41a85a09ba5d657d5406d /chromeos/dbus/session_manager_client.cc
parent75608c0c08a36d6c6804760a32139f1ad6e72555 (diff)
downloadchromium_src-c8252d4a18cf50c07ce68fb737b73e103dc1ef52.zip
chromium_src-c8252d4a18cf50c07ce68fb737b73e103dc1ef52.tar.gz
chromium_src-c8252d4a18cf50c07ce68fb737b73e103dc1ef52.tar.bz2
Load the policy store synchronously on ChromeOS, when appropriate.
The Profile can be created both in a synchronous and asynchronous mode. When asynchronous then the policy subsystems can load policy asynchronously, and the Profile resumes initialization once the policies are ready; this is the default on ChromeOS. But the synchronous path must load all the preferences (and thus, all the policies) during construction of the Profile, and this is used on ChromeOS when restarting the browser after a crash or after changing the flags. This CL makes that path load policy synchronously, so that the Profile starts with the correct managed settings immediately. Additionally, since the PolicyServiceImpl sends out its initialization and policy-changed signals in different tasks, this CL makes the PolicyPrefStore recompute the managed preferences on the initialization signal as well. BUG=263061 Review URL: https://chromiumcodereview.appspot.com/20053003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus/session_manager_client.cc')
-rw-r--r--chromeos/dbus/session_manager_client.cc52
1 files changed, 39 insertions, 13 deletions
diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc
index 39d3773..e842f88 100644
--- a/chromeos/dbus/session_manager_client.cc
+++ b/chromeos/dbus/session_manager_client.cc
@@ -15,6 +15,7 @@
#include "base/strings/string_util.h"
#include "base/threading/worker_pool.h"
#include "chromeos/chromeos_paths.h"
+#include "chromeos/dbus/blocking_method_caller.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
@@ -28,12 +29,11 @@ namespace chromeos {
class SessionManagerClientImpl : public SessionManagerClient {
public:
explicit SessionManagerClientImpl(dbus::Bus* bus)
- : session_manager_proxy_(NULL),
+ : session_manager_proxy_(bus->GetObjectProxy(
+ login_manager::kSessionManagerServiceName,
+ dbus::ObjectPath(login_manager::kSessionManagerServicePath))),
+ blocking_method_caller_(bus, session_manager_proxy_),
weak_ptr_factory_(this) {
- session_manager_proxy_ = bus->GetObjectProxy(
- login_manager::kSessionManagerServiceName,
- dbus::ObjectPath(login_manager::kSessionManagerServicePath));
-
// Signals emitted on Chromium's interface. Many of these ought to be
// method calls instead.
session_manager_proxy_->ConnectToSignal(
@@ -223,6 +223,22 @@ class SessionManagerClientImpl : public SessionManagerClient {
callback);
}
+ virtual std::string BlockingRetrievePolicyForUser(
+ const std::string& username) OVERRIDE {
+ dbus::MethodCall method_call(
+ login_manager::kSessionManagerInterface,
+ login_manager::kSessionManagerRetrievePolicyForUser);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(username);
+ scoped_ptr<dbus::Response> response =
+ blocking_method_caller_.CallMethodAndBlock(&method_call);
+ std::string policy;
+ ExtractString(login_manager::kSessionManagerRetrievePolicyForUser,
+ response.get(),
+ &policy);
+ return policy;
+ }
+
virtual void RetrieveDeviceLocalAccountPolicy(
const std::string& account_name,
const RetrievePolicyCallback& callback) OVERRIDE {
@@ -400,14 +416,11 @@ class SessionManagerClientImpl : public SessionManagerClient {
callback.Run(sessions, success);
}
- // Called when kSessionManagerRetrievePolicy or
- // kSessionManagerRetrievePolicyForUser method is complete.
- void OnRetrievePolicy(const std::string& method_name,
- const RetrievePolicyCallback& callback,
- dbus::Response* response) {
+ void ExtractString(const std::string& method_name,
+ dbus::Response* response,
+ std::string* extracted) {
if (!response) {
LOG(ERROR) << "Failed to call " << method_name;
- callback.Run("");
return;
}
dbus::MessageReader reader(response);
@@ -415,11 +428,19 @@ class SessionManagerClientImpl : public SessionManagerClient {
size_t length = 0;
if (!reader.PopArrayOfBytes(&values, &length)) {
LOG(ERROR) << "Invalid response: " << response->ToString();
- callback.Run("");
return;
}
// static_cast does not work due to signedness.
- std::string serialized_proto(reinterpret_cast<char*>(values), length);
+ extracted->assign(reinterpret_cast<char*>(values), length);
+ }
+
+ // Called when kSessionManagerRetrievePolicy or
+ // kSessionManagerRetrievePolicyForUser method is complete.
+ void OnRetrievePolicy(const std::string& method_name,
+ const RetrievePolicyCallback& callback,
+ dbus::Response* response) {
+ std::string serialized_proto;
+ ExtractString(method_name, response, &serialized_proto);
callback.Run(serialized_proto);
}
@@ -492,6 +513,7 @@ class SessionManagerClientImpl : public SessionManagerClient {
}
dbus::ObjectProxy* session_manager_proxy_;
+ BlockingMethodCaller blocking_method_caller_;
ObserverList<Observer> observers_;
// Note: This should remain the last member so it'll be destroyed and
@@ -559,6 +581,10 @@ class SessionManagerClientStubImpl : public SessionManagerClient {
const RetrievePolicyCallback& callback) OVERRIDE {
callback.Run(user_policies_[username]);
}
+ virtual std::string BlockingRetrievePolicyForUser(
+ const std::string& username) OVERRIDE {
+ return user_policies_[username];
+ }
virtual void RetrieveDeviceLocalAccountPolicy(
const std::string& account_name,
const RetrievePolicyCallback& callback) OVERRIDE {