Commit 6fa568a4 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Ensure all pref accesses are correct.

All channels of Chrome should use the same preferences. This
updates two preference accesses that were not updated in the
original change.

BUG=866750, 831577

Change-Id: Ibd0f8d2895027eb85772b3f5308ffebaef3aff32
Reviewed-on: https://chromium-review.googlesource.com/1148473Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577941}
parent f9da90b4
......@@ -16,7 +16,6 @@
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_ioobject.h"
#import "base/mac/scoped_nsautorelease_pool.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/sha1.h"
......@@ -37,8 +36,8 @@ namespace {
const char kDmTokenBaseDir[] =
FILE_PATH_LITERAL("Google/Chrome Cloud Enrollment/");
NSString* const kEnrollmentTokenPolicyName =
@"MachineLevelUserCloudPolicyEnrollmentToken";
const CFStringRef kEnrollmentTokenPolicyName =
CFSTR("MachineLevelUserCloudPolicyEnrollmentToken");
bool GetDmTokenFilePath(base::FilePath* token_file_path,
const std::string& client_id,
......@@ -111,16 +110,29 @@ std::string BrowserDMTokenStorageMac::InitClientId() {
}
std::string BrowserDMTokenStorageMac::InitEnrollmentToken() {
base::mac::ScopedNSAutoreleasePool pool;
// Since the configuration management infrastructure is not initialized when
// this code runs, read the policy preference directly.
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* value = [defaults stringForKey:kEnrollmentTokenPolicyName];
if (value && [defaults objectIsForcedForKey:kEnrollmentTokenPolicyName])
return base::SysNSStringToUTF8(value);
else
#if defined(GOOGLE_CHROME_BUILD)
// Explicitly access the "com.google.Chrome" bundle ID, no matter what this
// app's bundle ID actually is. All channels of Chrome should obey the same
// policies.
CFStringRef bundle_id = CFSTR("com.google.Chrome");
#else
base::ScopedCFTypeRef<CFStringRef> bundle_id(
base::SysUTF8ToCFStringRef(base::mac::BaseBundleID()));
#endif
base::ScopedCFTypeRef<CFPropertyListRef> value(
CFPreferencesCopyAppValue(kEnrollmentTokenPolicyName, bundle_id));
if (!value ||
!CFPreferencesAppValueIsForced(kEnrollmentTokenPolicyName, bundle_id))
return std::string();
CFStringRef value_string = base::mac::CFCast<CFStringRef>(value);
if (!value_string)
return std::string();
return base::SysCFStringRefToUTF8(value_string);
}
std::string BrowserDMTokenStorageMac::InitDMToken() {
......
......@@ -14,7 +14,8 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#import "base/mac/scoped_nsautorelease_pool.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/macros.h"
#include "base/strings/sys_string_conversions.h"
#include "components/policy/policy_constants.h"
......@@ -99,19 +100,33 @@ base::FilePath::StringType ExpandPathVariables(
}
void CheckUserDataDirPolicy(base::FilePath* user_data_dir) {
base::mac::ScopedNSAutoreleasePool pool;
// Since the configuration management infrastructure is not initialized when
// this code runs, read the policy preference directly.
NSString* key = base::SysUTF8ToNSString(policy::key::kUserDataDir);
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* value = [defaults stringForKey:key];
if (value && [defaults objectIsForcedForKey:key]) {
std::string string_value = base::SysNSStringToUTF8(value);
#if defined(GOOGLE_CHROME_BUILD)
// Explicitly access the "com.google.Chrome" bundle ID, no matter what this
// app's bundle ID actually is. All channels of Chrome should obey the same
// policies.
CFStringRef bundle_id = CFSTR("com.google.Chrome");
#else
base::ScopedCFTypeRef<CFStringRef> bundle_id(
base::SysUTF8ToCFStringRef(base::mac::BaseBundleID()));
#endif
base::ScopedCFTypeRef<CFStringRef> key(
base::SysUTF8ToCFStringRef(policy::key::kUserDataDir));
base::ScopedCFTypeRef<CFPropertyListRef> value(
CFPreferencesCopyAppValue(key, bundle_id));
if (!value || !CFPreferencesAppValueIsForced(key, bundle_id))
return;
CFStringRef value_string = base::mac::CFCast<CFStringRef>(value);
if (!value_string)
return;
// Now replace any vars the user might have used.
std::string string_value = base::SysCFStringRefToUTF8(value_string);
string_value = policy::path_parser::ExpandPathVariables(string_value);
*user_data_dir = base::FilePath(string_value);
}
}
void CheckDiskCacheDirPolicy(base::FilePath* user_data_dir) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment