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

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

Issue 58313002: Removed the PolicyDefinitionList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-10-use-registry
Patch Set: rebase Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/policy_loader_mac.h" 5 #include "chrome/browser/policy/policy_loader_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 PolicyLoaderMac::CreateValueFromProperty( 54 PolicyLoaderMac::CreateValueFromProperty(
55 static_cast<CFPropertyListRef>(value)); 55 static_cast<CFPropertyListRef>(value));
56 if (converted) 56 if (converted)
57 static_cast<base::ListValue *>(context)->Append(converted); 57 static_cast<base::ListValue *>(context)->Append(converted);
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 PolicyLoaderMac::PolicyLoaderMac( 62 PolicyLoaderMac::PolicyLoaderMac(
63 scoped_refptr<base::SequencedTaskRunner> task_runner, 63 scoped_refptr<base::SequencedTaskRunner> task_runner,
64 const PolicyDefinitionList* policy_list,
65 const base::FilePath& managed_policy_path, 64 const base::FilePath& managed_policy_path,
66 MacPreferences* preferences) 65 MacPreferences* preferences)
67 : AsyncPolicyLoader(task_runner), 66 : AsyncPolicyLoader(task_runner),
68 policy_list_(policy_list),
69 preferences_(preferences), 67 preferences_(preferences),
70 managed_policy_path_(managed_policy_path) {} 68 managed_policy_path_(managed_policy_path) {}
71 69
72 PolicyLoaderMac::~PolicyLoaderMac() {} 70 PolicyLoaderMac::~PolicyLoaderMac() {}
73 71
74 void PolicyLoaderMac::InitOnBackgroundThread() { 72 void PolicyLoaderMac::InitOnBackgroundThread() {
75 if (!managed_policy_path_.empty()) { 73 if (!managed_policy_path_.empty()) {
76 watcher_.Watch( 74 watcher_.Watch(
77 managed_policy_path_, false, 75 managed_policy_path_, false,
78 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this))); 76 base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this)));
79 } 77 }
80 } 78 }
81 79
82 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { 80 scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
83 preferences_->AppSynchronize(kCFPreferencesCurrentApplication); 81 preferences_->AppSynchronize(kCFPreferencesCurrentApplication);
84 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 82 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
85 83
86 // Load Chrome's policy. 84 // Load Chrome's policy.
87 // TODO(joaodasilva): Use the Chrome schema instead of the
88 // PolicyDefinitionList.
89 PolicyMap& chrome_policy = 85 PolicyMap& chrome_policy =
90 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 86 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
91 87
92 PolicyLoadStatusSample status; 88 PolicyLoadStatusSample status;
93 bool policy_present = false; 89 bool policy_present = false;
94 const PolicyDefinitionList::Entry* current; 90 const Schema* schema =
95 for (current = policy_list_->begin; current != policy_list_->end; ++current) { 91 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, ""));
92 for (Schema::Iterator it = schema->GetPropertiesIterator();
93 !it.IsAtEnd(); it.Advance()) {
96 base::ScopedCFTypeRef<CFStringRef> name( 94 base::ScopedCFTypeRef<CFStringRef> name(
97 base::SysUTF8ToCFStringRef(current->name)); 95 base::SysUTF8ToCFStringRef(it.key()));
98 base::ScopedCFTypeRef<CFPropertyListRef> value( 96 base::ScopedCFTypeRef<CFPropertyListRef> value(
99 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); 97 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication));
100 if (!value.get()) 98 if (!value.get())
101 continue; 99 continue;
102 policy_present = true; 100 policy_present = true;
103 bool forced = 101 bool forced =
104 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); 102 preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication);
105 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : 103 PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY :
106 POLICY_LEVEL_RECOMMENDED; 104 POLICY_LEVEL_RECOMMENDED;
107 // TODO(joaodasilva): figure the policy scope. 105 // TODO(joaodasilva): figure the policy scope.
108 base::Value* policy = CreateValueFromProperty(value); 106 base::Value* policy = CreateValueFromProperty(value);
109 if (policy) 107 if (policy)
110 chrome_policy.Set(current->name, level, POLICY_SCOPE_USER, policy, NULL); 108 chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, policy, NULL);
111 else 109 else
112 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); 110 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR);
113 } 111 }
114 112
115 if (!policy_present) 113 if (!policy_present)
116 status.Add(POLICY_LOAD_STATUS_NO_POLICY); 114 status.Add(POLICY_LOAD_STATUS_NO_POLICY);
117 115
118 // Load policy for the registered components. 116 // Load policy for the registered components.
119 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get()); 117 LoadPolicyForDomain(POLICY_DOMAIN_EXTENSIONS, "extensions", bundle.get());
120 118
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 226 }
229 } 227 }
230 } 228 }
231 229
232 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { 230 void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) {
233 if (!error) 231 if (!error)
234 Reload(false); 232 Reload(false);
235 } 233 }
236 234
237 } // namespace policy 235 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_loader_mac.h ('k') | chrome/browser/policy/policy_loader_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698