summaryrefslogtreecommitdiffstats
path: root/components/ownership
diff options
context:
space:
mode:
authorygorshenin <ygorshenin@chromium.org>2014-10-27 02:10:56 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-27 09:11:24 +0000
commit0e5fbf43b4ea78a8f2848b0b7bb1fe69b0c2892e (patch)
tree17b9261a6a51bdd76576dae10203be876e427dea /components/ownership
parentd6c36e32a81f912a3722238444c27fc6dd5d7bb8 (diff)
downloadchromium_src-0e5fbf43b4ea78a8f2848b0b7bb1fe69b0c2892e.zip
chromium_src-0e5fbf43b4ea78a8f2848b0b7bb1fe69b0c2892e.tar.gz
chromium_src-0e5fbf43b4ea78a8f2848b0b7bb1fe69b0c2892e.tar.bz2
Implemented OwnerSettingsService::Set() method.
BUG=230018 TEST=unit_tests:OwnerSettingsServiceChromeOSTest.* Committed: https://crrev.com/5fa0ee22683b92d67e07c060e8c7a3c4cced51ee Cr-Commit-Position: refs/heads/master@{#301132} Review URL: https://codereview.chromium.org/654263003 Cr-Commit-Position: refs/heads/master@{#301328}
Diffstat (limited to 'components/ownership')
-rw-r--r--components/ownership/owner_settings_service.cc57
-rw-r--r--components/ownership/owner_settings_service.h55
2 files changed, 94 insertions, 18 deletions
diff --git a/components/ownership/owner_settings_service.cc b/components/ownership/owner_settings_service.cc
index 56bcbe0..204cdd1 100644
--- a/components/ownership/owner_settings_service.cc
+++ b/components/ownership/owner_settings_service.cc
@@ -12,6 +12,7 @@
#include "base/message_loop/message_loop.h"
#include "base/task_runner.h"
#include "base/task_runner_util.h"
+#include "base/values.h"
#include "components/ownership/owner_key_util.h"
#include "crypto/signature_creator.h"
@@ -21,13 +22,15 @@ namespace ownership {
namespace {
-std::string AssembleAndSignPolicy(scoped_ptr<em::PolicyData> policy,
- crypto::RSAPrivateKey* private_key) {
+scoped_ptr<em::PolicyFetchResponse> AssembleAndSignPolicy(
+ scoped_ptr<em::PolicyData> policy,
+ crypto::RSAPrivateKey* private_key) {
// Assemble the policy.
- em::PolicyFetchResponse policy_response;
- if (!policy->SerializeToString(policy_response.mutable_policy_data())) {
+ scoped_ptr<em::PolicyFetchResponse> policy_response(
+ new em::PolicyFetchResponse());
+ if (!policy->SerializeToString(policy_response->mutable_policy_data())) {
LOG(ERROR) << "Failed to encode policy payload.";
- return std::string();
+ return scoped_ptr<em::PolicyFetchResponse>(nullptr).Pass();
}
// Generate the signature.
@@ -35,19 +38,19 @@ std::string AssembleAndSignPolicy(scoped_ptr<em::PolicyData> policy,
crypto::SignatureCreator::Create(private_key,
crypto::SignatureCreator::SHA1));
signature_creator->Update(
- reinterpret_cast<const uint8*>(policy_response.policy_data().c_str()),
- policy_response.policy_data().size());
+ reinterpret_cast<const uint8*>(policy_response->policy_data().c_str()),
+ policy_response->policy_data().size());
std::vector<uint8> signature_bytes;
std::string policy_blob;
if (!signature_creator->Final(&signature_bytes)) {
LOG(ERROR) << "Failed to create policy signature.";
- return std::string();
+ return scoped_ptr<em::PolicyFetchResponse>(nullptr).Pass();
}
- policy_response.mutable_policy_data_signature()->assign(
+ policy_response->mutable_policy_data_signature()->assign(
reinterpret_cast<const char*>(vector_as_array(&signature_bytes)),
signature_bytes.size());
- return policy_response.SerializeAsString();
+ return policy_response.Pass();
}
} // namepace
@@ -61,6 +64,15 @@ OwnerSettingsService::~OwnerSettingsService() {
DCHECK(thread_checker_.CalledOnValidThread());
}
+void OwnerSettingsService::AddObserver(Observer* observer) {
+ if (observer && !observers_.HasObserver(observer))
+ observers_.AddObserver(observer);
+}
+
+void OwnerSettingsService::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
bool OwnerSettingsService::IsOwner() {
DCHECK(thread_checker_.CalledOnValidThread());
return private_key_.get() && private_key_->key();
@@ -91,6 +103,31 @@ bool OwnerSettingsService::AssembleAndSignPolicyAsync(
callback);
}
+bool OwnerSettingsService::SetBoolean(const std::string& setting, bool value) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::FundamentalValue in_value(value);
+ return Set(setting, in_value);
+}
+
+bool OwnerSettingsService::SetInteger(const std::string& setting, int value) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::FundamentalValue in_value(value);
+ return Set(setting, in_value);
+}
+
+bool OwnerSettingsService::SetDouble(const std::string& setting, double value) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::FundamentalValue in_value(value);
+ return Set(setting, in_value);
+}
+
+bool OwnerSettingsService::SetString(const std::string& setting,
+ const std::string& value) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::StringValue in_value(value);
+ return Set(setting, in_value);
+}
+
void OwnerSettingsService::ReloadKeypair() {
ReloadKeypairImpl(
base::Bind(&OwnerSettingsService::OnKeypairLoaded, as_weak_ptr()));
diff --git a/components/ownership/owner_settings_service.h b/components/ownership/owner_settings_service.h
index 1961975..db36595 100644
--- a/components/ownership/owner_settings_service.h
+++ b/components/ownership/owner_settings_service.h
@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/ownership/ownership_export.h"
@@ -20,6 +21,7 @@
namespace base {
class TaskRunner;
+class Value;
}
namespace ownership {
@@ -31,19 +33,42 @@ class PublicKey;
// which deal with ownership, keypairs and owner-related settings.
class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
public:
- typedef base::Callback<void(std::string policy_blob)>
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ // Called when signed policy was stored, or when an error happed during
+ // policy storage..
+ virtual void OnSignedPolicyStored(bool success) {}
+
+ // Called when tentative changes were made to policy, but the policy still
+ // not signed and stored.
+ //
+ // TODO (ygorshenin@, crbug.com/230018): get rid of the method
+ // since it creates DeviceSettingsService's dependency on
+ // OwnerSettingsService.
+ virtual void OnTentativeChangesInPolicy(
+ const enterprise_management::PolicyData& policy_data) {}
+ };
+
+ typedef base::Callback<void(
+ scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response)>
AssembleAndSignPolicyAsyncCallback;
typedef base::Callback<void(bool is_owner)> IsOwnerCallback;
explicit OwnerSettingsService(
const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
- ~OwnerSettingsService() override;
+ virtual ~OwnerSettingsService();
base::WeakPtr<OwnerSettingsService> as_weak_ptr() {
return weak_factory_.GetWeakPtr();
}
+ void AddObserver(Observer* observer);
+
+ void RemoveObserver(Observer* observer);
+
// Returns whether current user is owner or not. When this method
// is called too early, incorrect result can be returned because
// private key loading may be in progress.
@@ -60,12 +85,24 @@ class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
scoped_ptr<enterprise_management::PolicyData> policy,
const AssembleAndSignPolicyAsyncCallback& callback);
- // Signs |settings| with the private half of the owner key and sends
- // the resulting policy blob for storage. The
- // result of the operation is reported through |callback|.
- virtual void SignAndStorePolicyAsync(
- scoped_ptr<enterprise_management::PolicyData> policy,
- const base::Closure& callback) = 0;
+ // Checks whether |setting| is handled by OwnerSettingsService.
+ virtual bool HandlesSetting(const std::string& setting) = 0;
+
+ // Sets |setting| value to |value|.
+ virtual bool Set(const std::string& setting, const base::Value& value) = 0;
+
+ // Sets a bunch of device settings accumulated before ownership gets
+ // established.
+ //
+ // TODO (ygorshenin@, crbug.com/230018): that this is a temporary
+ // solution and should be removed.
+ virtual bool CommitTentativeDeviceSettings(
+ scoped_ptr<enterprise_management::PolicyData> policy) = 0;
+
+ bool SetBoolean(const std::string& setting, bool value);
+ bool SetInteger(const std::string& setting, int value);
+ bool SetDouble(const std::string& setting, double value);
+ bool SetString(const std::string& setting, const std::string& value);
protected:
void ReloadKeypair();
@@ -89,6 +126,8 @@ class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService {
std::vector<IsOwnerCallback> pending_is_owner_callbacks_;
+ ObserverList<Observer> observers_;
+
base::ThreadChecker thread_checker_;
private: