Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/policy/managed_mode_policy_provider.cc

Issue 10510006: Add ManagedModePolicyProvider and extension API to get and set policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/managed_mode_policy_provider.h"
6
7 #include "chrome/browser/policy/policy_bundle.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/json_pref_store.h"
10 #include "chrome/common/chrome_constants.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "policy/policy_constants.h"
13
14 using content::BrowserThread;
15
16 namespace policy {
17
18 static const char kPolicies[] = "policies";
19
20 ManagedModePolicyProvider::ManagedModePolicyProvider(Profile* profile)
21 : ConfigurationPolicyProvider(GetChromePolicyDefinitionList()),
22 store_(new JsonPrefStore(profile->GetPath().Append(
23 chrome::kManagedModePolicyFilename),
24 BrowserThread::GetMessageLoopProxyForThread(
25 BrowserThread::FILE))) {
26 store_->AddObserver(this);
27 store_->ReadPrefsAsync(NULL);
28 }
29
30 ManagedModePolicyProvider::~ManagedModePolicyProvider() {
31 store_->RemoveObserver(this);
32 }
33
34 void ManagedModePolicyProvider::RefreshPolicies() {
35 }
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.
36
37 bool ManagedModePolicyProvider::IsInitializationComplete() const {
38 return store_->IsInitializationComplete();
39 }
40
41 base::DictionaryValue* ManagedModePolicyProvider::GetPolicyDictionary() const {
42 base::Value* value = NULL;
43 base::DictionaryValue* dict = NULL;
44 PrefStore::ReadResult result = store_->GetMutableValue(kPolicies, &value);
45 if (result == PrefStore::READ_NO_VALUE) {
46 dict = new DictionaryValue;
Joao da Silva 2012/06/06 16:36:38 base::DictionaryValue
Bernhard Bauer 2012/06/08 10:06:44 Done.
47 store_->SetValue(kPolicies, dict);
48 } else if (result == PrefStore::READ_OK) {
49 bool success = value->GetAsDictionary(&dict);
50 DCHECK(success);
51 } else {
52 NOTREACHED();
53 }
54
55 return dict;
56 }
57
58 const base::Value* ManagedModePolicyProvider::GetPolicy(
59 const std::string& key) const {
60 base::DictionaryValue* dict = GetPolicyDictionary();
61 base::Value* value = NULL;
62 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.
63 return value;
64 }
65
66 void ManagedModePolicyProvider::SetPolicy(const std::string& key,
67 const base::Value* value) {
68 base::DictionaryValue* dict = GetPolicyDictionary();
69 dict->SetWithoutPathExpansion(key, value->DeepCopy());
70 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
71 UpdatePolicies();
72 }
73
74 void ManagedModePolicyProvider::OnPrefValueChanged(const std::string& key) {}
75
76 void ManagedModePolicyProvider::OnInitializationCompleted(bool success) {
77 DCHECK(success);
78 UpdatePolicies();
79 }
80
81 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.
82 const base::DictionaryValue* dict = GetPolicyDictionary();
83 PolicyMap policy_map;
84 policy_map.LoadFrom(dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
85 scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle);
86 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.
87 UpdatePolicy(policy_bundle.Pass());
88 }
89
90 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698