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

Unified Diff: components/policy/core/common/policy_loader_ios.mm

Issue 213483004: Extended the iOS platform policy loader to load an additional key. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added tests Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/policy_loader_ios.mm
diff --git a/components/policy/core/common/policy_loader_ios.mm b/components/policy/core/common/policy_loader_ios.mm
index 19718eae21201a4db5ae4e63670985779846b00f..71891bc18e7ca633e97a0e88d3bdb860dffeda1c 100644
--- a/components/policy/core/common/policy_loader_ios.mm
+++ b/components/policy/core/common/policy_loader_ios.mm
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/mac/scoped_nsobject.h"
#include "base/sequenced_task_runner.h"
#include "components/policy/core/common/mac_util.h"
#include "components/policy/core/common/policy_bundle.h"
@@ -32,6 +33,10 @@ NSString* const kConfigurationKey = @"com.apple.configuration.managed";
// Key in the managed app configuration that contains the Chrome policy.
NSString* const kChromePolicyKey = @"ChromePolicy";
+// Key in the managed app configuration that contains the encoded Chrome policy.
+// This is a serialized Property List, encoded in base 64.
+NSString* const kEncodedChromePolicyKey = @"EncodedChromePolicy";
+
} // namespace
// Helper that observes notifications for NSUserDefaults and triggers an update
@@ -107,15 +112,32 @@ scoped_ptr<PolicyBundle> PolicyLoaderIOS::Load() {
NSDictionary* configuration = [[NSUserDefaults standardUserDefaults]
dictionaryForKey:kConfigurationKey];
id chromePolicy = configuration[kChromePolicyKey];
+ id encodedChromePolicy = configuration[kEncodedChromePolicyKey];
dconnelly 2014/03/27 13:14:19 I think a warning on !(chromePolicy ^ encodedChrom
Joao da Silva 2014/03/27 14:05:08 Added a warning on chromePolicy && encodedChromePo
+
if (chromePolicy && [chromePolicy isKindOfClass:[NSDictionary class]]) {
- // NSDictionary is toll-free bridged to CFDictionaryRef, which is a
- // CFPropertyListRef.
- scoped_ptr<base::Value> value =
- PropertyToValue(static_cast<CFPropertyListRef>(chromePolicy));
- base::DictionaryValue* dict = NULL;
- if (value && value->GetAsDictionary(&dict)) {
- PolicyMap& map = bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, ""));
- map.LoadFrom(dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
+ LoadNSDictionaryToPolicyBundle(chromePolicy, bundle.get());
+ } else if (encodedChromePolicy &&
+ [encodedChromePolicy isKindOfClass:[NSString class]]) {
+ base::scoped_nsobject<NSData> data(
+ [[NSData alloc] initWithBase64EncodedString:encodedChromePolicy
+ options:0]);
+ if (!data) {
+ NSLog(@"Invalid Base64 encoding of EncodedChromePolicy");
+ } else {
+ NSError* error = nil;
+ NSDictionary* properties = [NSPropertyListSerialization
+ propertyListWithData:data.get()
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error];
+ if (!properties || error) {
+ NSLog(@"Invalid property list in EncodedChromePolicy: %@", error);
dconnelly 2014/03/27 13:14:19 Does !properties imply !!error? If not, maybe a di
Joao da Silva 2014/03/27 14:05:08 Done.
+ } else if (![properties isKindOfClass:[NSDictionary class]]) {
+ NSLog(@"Invalid property list in EncodedChromePolicy: expected an "
+ "NSDictionary but found %@", [properties class]);
+ } else {
+ LoadNSDictionaryToPolicyBundle(properties, bundle.get());
+ }
}
}
@@ -135,4 +157,18 @@ void PolicyLoaderIOS::UserDefaultsChanged() {
Reload(false);
}
+// static
+void PolicyLoaderIOS::LoadNSDictionaryToPolicyBundle(NSDictionary* dictionary,
+ PolicyBundle* bundle) {
+ // NSDictionary is toll-free bridged to CFDictionaryRef, which is a
+ // CFPropertyListRef.
+ scoped_ptr<base::Value> value =
+ PropertyToValue(static_cast<CFPropertyListRef>(dictionary));
+ base::DictionaryValue* dict = NULL;
+ if (value && value->GetAsDictionary(&dict)) {
+ PolicyMap& map = bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, ""));
+ map.LoadFrom(dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
+ }
+}
+
} // namespace policy
« no previous file with comments | « components/policy/core/common/policy_loader_ios.h ('k') | components/policy/core/common/policy_loader_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698