Chromium Code Reviews| Index: chrome/browser/policy/managed_mode_policy_provider.cc |
| diff --git a/chrome/browser/policy/managed_mode_policy_provider.cc b/chrome/browser/policy/managed_mode_policy_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dd93f5dde42209c808311cb33677c5b80e5679f1 |
| --- /dev/null |
| +++ b/chrome/browser/policy/managed_mode_policy_provider.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/policy/managed_mode_policy_provider.h" |
| + |
| +#include "chrome/browser/policy/policy_bundle.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/json_pref_store.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "policy/policy_constants.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace policy { |
| + |
| +static const char kPolicies[] = "policies"; |
| + |
| +ManagedModePolicyProvider::ManagedModePolicyProvider(Profile* profile) |
| + : ConfigurationPolicyProvider(GetChromePolicyDefinitionList()), |
| + store_(new JsonPrefStore(profile->GetPath().Append( |
| + chrome::kManagedModePolicyFilename), |
| + BrowserThread::GetMessageLoopProxyForThread( |
| + BrowserThread::FILE))) { |
| + store_->AddObserver(this); |
| + store_->ReadPrefsAsync(NULL); |
| +} |
| + |
| +ManagedModePolicyProvider::~ManagedModePolicyProvider() { |
| + store_->RemoveObserver(this); |
| +} |
| + |
| +void ManagedModePolicyProvider::RefreshPolicies() { |
| +} |
|
Joao da Silva
2012/06/06 16:36:38
This must call UpdatePolicies(), because callers o
Bernhard Bauer
2012/06/08 10:06:44
Done.
|
| + |
| +bool ManagedModePolicyProvider::IsInitializationComplete() const { |
| + return store_->IsInitializationComplete(); |
| +} |
| + |
| +base::DictionaryValue* ManagedModePolicyProvider::GetPolicyDictionary() const { |
| + base::Value* value = NULL; |
| + base::DictionaryValue* dict = NULL; |
| + PrefStore::ReadResult result = store_->GetMutableValue(kPolicies, &value); |
| + if (result == PrefStore::READ_NO_VALUE) { |
| + dict = new DictionaryValue; |
|
Joao da Silva
2012/06/06 16:36:38
base::DictionaryValue
Bernhard Bauer
2012/06/08 10:06:44
Done.
|
| + store_->SetValue(kPolicies, dict); |
| + } else if (result == PrefStore::READ_OK) { |
| + bool success = value->GetAsDictionary(&dict); |
| + DCHECK(success); |
| + } else { |
| + NOTREACHED(); |
| + } |
| + |
| + return dict; |
| +} |
| + |
| +const base::Value* ManagedModePolicyProvider::GetPolicy( |
| + const std::string& key) const { |
| + base::DictionaryValue* dict = GetPolicyDictionary(); |
| + base::Value* value = NULL; |
| + dict->Get(key, &value); |
|
Joao da Silva
2012/06/06 16:36:38
GetWithoutPathExpansion?
Bernhard Bauer
2012/06/08 10:06:44
Good catch! Done.
|
| + return value; |
| +} |
| + |
| +void ManagedModePolicyProvider::SetPolicy(const std::string& key, |
| + const base::Value* value) { |
| + base::DictionaryValue* dict = GetPolicyDictionary(); |
| + dict->SetWithoutPathExpansion(key, value->DeepCopy()); |
| + store_->ReportValueChanged(kPolicies); |
|
Mattias Nissler (ping if slow)
2012/06/06 17:22:09
necessary?
Bernhard Bauer
2012/06/08 10:06:44
I'm not using the SetValue method on the PrefStore
|
| + UpdatePolicies(); |
| +} |
| + |
| +void ManagedModePolicyProvider::OnPrefValueChanged(const std::string& key) {} |
| + |
| +void ManagedModePolicyProvider::OnInitializationCompleted(bool success) { |
| + DCHECK(success); |
| + UpdatePolicies(); |
| +} |
| + |
| +void ManagedModePolicyProvider::UpdatePolicies() { |
|
Mattias Nissler (ping if slow)
2012/06/06 17:22:09
Having two functions, one called UpdatePolicies an
Bernhard Bauer
2012/06/08 10:06:44
Done.
|
| + const base::DictionaryValue* dict = GetPolicyDictionary(); |
| + PolicyMap policy_map; |
| + policy_map.LoadFrom(dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
| + scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle); |
| + policy_bundle->Get(POLICY_DOMAIN_CHROME, std::string()).MergeFrom(policy_map); |
|
Joao da Silva
2012/06/06 16:36:38
.LoadFrom() can be directly invoked in the bundle,
Mattias Nissler (ping if slow)
2012/06/06 17:22:09
I think Joao means Swap().
Joao da Silva
2012/06/06 19:07:24
That also works. I meant
policy_bundle->Get(POLIC
Bernhard Bauer
2012/06/08 10:06:44
Done.
|
| + UpdatePolicy(policy_bundle.Pass()); |
| +} |
| + |
| +} // namespace policy |