summaryrefslogtreecommitdiffstats
path: root/chromeos
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
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')
-rw-r--r--chromeos/dbus/cryptohome_client.cc26
-rw-r--r--chromeos/dbus/cryptohome_client.h9
-rw-r--r--chromeos/dbus/fake_cryptohome_client.cc5
-rw-r--r--chromeos/dbus/fake_cryptohome_client.h2
-rw-r--r--chromeos/dbus/fake_session_manager_client.cc5
-rw-r--r--chromeos/dbus/fake_session_manager_client.h2
-rw-r--r--chromeos/dbus/mock_cryptohome_client.h2
-rw-r--r--chromeos/dbus/mock_session_manager_client.h1
-rw-r--r--chromeos/dbus/session_manager_client.cc52
-rw-r--r--chromeos/dbus/session_manager_client.h9
10 files changed, 100 insertions, 13 deletions
diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc
index 5cf72f8..0a5a7fb 100644
--- a/chromeos/dbus/cryptohome_client.cc
+++ b/chromeos/dbus/cryptohome_client.cc
@@ -152,6 +152,26 @@ class CryptohomeClientImpl : public CryptohomeClient {
}
// CryptohomeClient override.
+ virtual std::string BlockingGetSanitizedUsername(
+ const std::string& username) OVERRIDE {
+ dbus::MethodCall method_call(cryptohome::kCryptohomeInterface,
+ cryptohome::kCryptohomeGetSanitizedUsername);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(username);
+
+ scoped_ptr<dbus::Response> response =
+ blocking_method_caller_.CallMethodAndBlock(&method_call);
+
+ std::string sanitized_username;
+ if (response) {
+ dbus::MessageReader reader(response.get());
+ reader.PopString(&sanitized_username);
+ }
+
+ return sanitized_username;
+ }
+
+ // CryptohomeClient override.
virtual void AsyncMount(const std::string& username,
const std::string& key,
int flags,
@@ -882,6 +902,12 @@ class CryptohomeClientStubImpl : public CryptohomeClient {
}
// CryptohomeClient override.
+ virtual std::string BlockingGetSanitizedUsername(
+ const std::string& username) OVERRIDE {
+ return GetStubSanitizedUsername(username);
+ }
+
+ // CryptohomeClient override.
virtual void AsyncMount(const std::string& username,
const std::string& key,
int flags,
diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h
index 3d34ea4..d17c0d7 100644
--- a/chromeos/dbus/cryptohome_client.h
+++ b/chromeos/dbus/cryptohome_client.h
@@ -104,6 +104,15 @@ class CHROMEOS_EXPORT CryptohomeClient {
const std::string& username,
const StringDBusMethodCallback& callback) = 0;
+ // Same as GetSanitizedUsername() but blocks until a reply is received, and
+ // returns the sanitized username synchronously. Returns an empty string if
+ // the method call fails.
+ // This may only be called in situations where blocking the UI thread is
+ // considered acceptable (e.g. restarting the browser after a crash or after
+ // a flag change).
+ virtual std::string BlockingGetSanitizedUsername(
+ const std::string& username) = 0;
+
// Calls the AsyncMount method to asynchronously mount the cryptohome for
// |username|, using |key| to unlock it. For supported |flags|, see the
// documentation of AsyncMethodCaller::AsyncMount().
diff --git a/chromeos/dbus/fake_cryptohome_client.cc b/chromeos/dbus/fake_cryptohome_client.cc
index 39f0a6f..19bdf36 100644
--- a/chromeos/dbus/fake_cryptohome_client.cc
+++ b/chromeos/dbus/fake_cryptohome_client.cc
@@ -259,6 +259,11 @@ void FakeCryptohomeClient::GetSanitizedUsername(
username));
}
+std::string FakeCryptohomeClient::BlockingGetSanitizedUsername(
+ const std::string& username) {
+ return username;
+}
+
void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge(
attestation::AttestationKeyType key_type,
const std::string& key_name,
diff --git a/chromeos/dbus/fake_cryptohome_client.h b/chromeos/dbus/fake_cryptohome_client.h
index e8ff10c..e840697 100644
--- a/chromeos/dbus/fake_cryptohome_client.h
+++ b/chromeos/dbus/fake_cryptohome_client.h
@@ -38,6 +38,8 @@ class FakeCryptohomeClient : public CryptohomeClient {
virtual void GetSanitizedUsername(
const std::string& username,
const StringDBusMethodCallback& callback) OVERRIDE;
+ virtual std::string BlockingGetSanitizedUsername(
+ const std::string& username) OVERRIDE;
virtual void AsyncMount(const std::string& username,
const std::string& key,
int flags,
diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc
index ea3d870..37d90da 100644
--- a/chromeos/dbus/fake_session_manager_client.cc
+++ b/chromeos/dbus/fake_session_manager_client.cc
@@ -93,6 +93,11 @@ void FakeSessionManagerClient::RetrievePolicyForUser(
FROM_HERE, base::Bind(callback, user_policies_[username]));
}
+std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
+ const std::string& username) {
+ return user_policies_[username];
+}
+
void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
const std::string& account_id,
const RetrievePolicyCallback& callback) {
diff --git a/chromeos/dbus/fake_session_manager_client.h b/chromeos/dbus/fake_session_manager_client.h
index 1acd082..5c8941b3 100644
--- a/chromeos/dbus/fake_session_manager_client.h
+++ b/chromeos/dbus/fake_session_manager_client.h
@@ -44,6 +44,8 @@ class FakeSessionManagerClient : public chromeos::SessionManagerClient {
virtual void RetrievePolicyForUser(
const std::string& username,
const RetrievePolicyCallback& callback) OVERRIDE;
+ virtual std::string BlockingRetrievePolicyForUser(
+ const std::string& username) OVERRIDE;
virtual void RetrieveDeviceLocalAccountPolicy(
const std::string& account_id,
const RetrievePolicyCallback& callback) OVERRIDE;
diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h
index d72d3f4..0ba51c2 100644
--- a/chromeos/dbus/mock_cryptohome_client.h
+++ b/chromeos/dbus/mock_cryptohome_client.h
@@ -38,6 +38,8 @@ class MockCryptohomeClient : public CryptohomeClient {
MOCK_METHOD2(GetSanitizedUsername,
void(const std::string& username,
const StringDBusMethodCallback& callback));
+ MOCK_METHOD1(BlockingGetSanitizedUsername,
+ std::string(const std::string& username));
MOCK_METHOD4(AsyncMount, void(const std::string& username,
const std::string& key,
int flags,
diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h
index 1596951..afe8e37 100644
--- a/chromeos/dbus/mock_session_manager_client.h
+++ b/chromeos/dbus/mock_session_manager_client.h
@@ -36,6 +36,7 @@ class MockSessionManagerClient : public SessionManagerClient {
MOCK_METHOD2(RetrievePolicyForUser,
void(const std::string&,
const RetrievePolicyCallback&));
+ MOCK_METHOD1(BlockingRetrievePolicyForUser, std::string(const std::string&));
MOCK_METHOD2(RetrieveDeviceLocalAccountPolicy,
void(const std::string&,
const RetrievePolicyCallback&));
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 {
diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h
index ca10707..45b9b14 100644
--- a/chromeos/dbus/session_manager_client.h
+++ b/chromeos/dbus/session_manager_client.h
@@ -126,6 +126,15 @@ class CHROMEOS_EXPORT SessionManagerClient {
const std::string& username,
const RetrievePolicyCallback& callback) = 0;
+ // Same as RetrievePolicyForUser() but blocks until a reply is received, and
+ // returns the policy synchronously. Returns an empty string if the method
+ // call fails.
+ // This may only be called in situations where blocking the UI thread is
+ // considered acceptable (e.g. restarting the browser after a crash or after
+ // a flag change).
+ virtual std::string BlockingRetrievePolicyForUser(
+ const std::string& username) = 0;
+
// Fetches the policy blob associated with the specified device-local account
// from session manager. |callback| is invoked up on completion.
virtual void RetrieveDeviceLocalAccountPolicy(