Chromium Code Reviews| Index: components/policy/core/common/policy_loader_mac.mm |
| diff --git a/components/policy/core/common/policy_loader_mac.cc b/components/policy/core/common/policy_loader_mac.mm |
| similarity index 76% |
| rename from components/policy/core/common/policy_loader_mac.cc |
| rename to components/policy/core/common/policy_loader_mac.mm |
| index 04e6314887de0c770a925f585ae71b6f8a9a14b2..923777d7e2aea2783dd0cff2aea5c687b567aa07 100644 |
| --- a/components/policy/core/common/policy_loader_mac.cc |
| +++ b/components/policy/core/common/policy_loader_mac.mm |
| @@ -7,6 +7,7 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/callback.h" |
| +#include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| #include "base/mac/foundation_util.h" |
| #include "base/mac/scoped_cftyperef.h" |
| @@ -32,7 +33,20 @@ PolicyLoaderMac::PolicyLoaderMac( |
| MacPreferences* preferences) |
| : AsyncPolicyLoader(task_runner), |
| preferences_(preferences), |
| - managed_policy_path_(managed_policy_path) {} |
| + managed_policy_path_(managed_policy_path), |
| + application_id_(kCFPreferencesCurrentApplication) { |
| +} |
| + |
| +PolicyLoaderMac::PolicyLoaderMac( |
| + scoped_refptr<base::SequencedTaskRunner> task_runner, |
| + const base::FilePath& managed_policy_path, |
| + MacPreferences* preferences, |
| + CFStringRef application_id) |
| + : AsyncPolicyLoader(task_runner), |
| + preferences_(preferences), |
| + managed_policy_path_(managed_policy_path), |
| + application_id_(application_id) { |
| +} |
| PolicyLoaderMac::~PolicyLoaderMac() {} |
| @@ -45,7 +59,7 @@ void PolicyLoaderMac::InitOnBackgroundThread() { |
| } |
| scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
| - preferences_->AppSynchronize(kCFPreferencesCurrentApplication); |
| + preferences_->AppSynchronize(application_id_); |
| scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| // Load Chrome's policy. |
| @@ -61,12 +75,11 @@ scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
| base::ScopedCFTypeRef<CFStringRef> name( |
| base::SysUTF8ToCFStringRef(it.key())); |
| base::ScopedCFTypeRef<CFPropertyListRef> value( |
| - preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); |
| + preferences_->CopyAppValue(name, application_id_)); |
| if (!value.get()) |
| continue; |
| policy_present = true; |
| - bool forced = |
| - preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication); |
| + bool forced = preferences_->AppValueIsForced(name, application_id_); |
| PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY : |
| POLICY_LEVEL_RECOMMENDED; |
| // TODO(joaodasilva): figure the policy scope. |
| @@ -157,4 +170,32 @@ void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
| Reload(false); |
| } |
| +#if defined(OS_MACOSX) && !defined(OS_IOS) |
| + |
| +base::FilePath PolicyLoaderMac::GetManagedPolicyPath(CFStringRef bundle_id) { |
|
Mattias Nissler (ping if slow)
2015/01/08 09:58:37
nit: Please move this up to make the ordering of f
Łukasz Anforowicz
2015/01/08 23:09:27
Done.
|
| + // This constructs the path to the plist file in which Mac OS X stores the |
| + // managed preference for the application. This is undocumented and therefore |
| + // fragile, but if it doesn't work out, AsyncPolicyLoader has a task that |
| + // polls periodically in order to reload managed preferences later even if we |
| + // missed the change. |
| + |
| + base::FilePath path; |
| + if (!base::mac::GetLocalDirectory(NSLibraryDirectory, &path)) { |
|
Mattias Nissler (ping if slow)
2015/01/08 09:58:36
nit: no curly braces
Łukasz Anforowicz
2015/01/08 23:09:27
Ok. I'll make this consistent with the rest of co
|
| + return base::FilePath(); |
| + } |
| + path = path.Append(FILE_PATH_LITERAL("Managed Preferences")); |
| + char* login = getlogin(); |
| + if (!login) { |
|
Mattias Nissler (ping if slow)
2015/01/08 09:58:36
ditto
Łukasz Anforowicz
2015/01/08 23:09:27
Done.
|
| + return base::FilePath(); |
| + } |
| + path = path.AppendASCII(login); |
| + if (!base::PathExists(path)) { // We don't want to create this. |
|
Mattias Nissler (ping if slow)
2015/01/08 09:58:36
As explained in my other reply, I think we should
Łukasz Anforowicz
2015/01/08 23:09:27
Done.
|
| + return base::FilePath(); |
| + } |
| + |
| + return path.Append(base::SysCFStringRefToUTF8(bundle_id) + ".plist"); |
| +} |
| + |
| +#endif |
| + |
| } // namespace policy |