OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/browser_policy_context.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/policy/cloud_policy_context.h" |
| 11 #include "chrome/browser/policy/cloud_policy_controller.h" |
| 12 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 13 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 14 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" |
| 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/chrome_switches.h" |
| 17 |
| 18 #if defined(OS_WIN) |
| 19 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
| 20 #elif defined(OS_MACOSX) |
| 21 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
| 22 #elif defined(OS_POSIX) |
| 23 #include "chrome/browser/policy/config_dir_policy_provider.h" |
| 24 #endif |
| 25 |
| 26 #if defined(OS_CHROMEOS) |
| 27 #include "chrome/browser/policy/device_policy_controller.h" |
| 28 #endif |
| 29 |
| 30 namespace { |
| 31 |
| 32 const FilePath::CharType kDevicePolicyCacheFile[] = |
| 33 FILE_PATH_LITERAL("policy"); |
| 34 |
| 35 } |
| 36 |
| 37 namespace policy { |
| 38 |
| 39 BrowserPolicyContext::BrowserPolicyContext() { |
| 40 managed_platform_provider_.reset(CreateManagedPlatformProvider()); |
| 41 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); |
| 42 |
| 43 #if defined(OS_CHROMEOS) |
| 44 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 45 if (command_line->HasSwitch(switches::kDevicePolicyCacheDir)) { |
| 46 FilePath cache_dir(command_line->GetSwitchValuePath( |
| 47 switches::kDevicePolicyCacheDir)); |
| 48 |
| 49 if (!file_util::CreateDirectory(cache_dir)) { |
| 50 LOG(WARNING) << "Device policy cache directory " |
| 51 << cache_dir.value() |
| 52 << " is not accessible, skipping initialization."; |
| 53 } else { |
| 54 controller_.reset(new DevicePolicyController()); |
| 55 cloud_context_.reset( |
| 56 new CloudPolicyContext(cache_dir.Append(kDevicePolicyCacheFile), |
| 57 controller_.get())); |
| 58 } |
| 59 } |
| 60 #endif |
| 61 } |
| 62 |
| 63 BrowserPolicyContext::BrowserPolicyContext( |
| 64 ConfigurationPolicyProvider* managed_platform_provider, |
| 65 ConfigurationPolicyProvider* recommended_platform_provider) |
| 66 : managed_platform_provider_(managed_platform_provider), |
| 67 recommended_platform_provider_(recommended_platform_provider) {} |
| 68 |
| 69 void BrowserPolicyContext::Initialize( |
| 70 PrefService* local_state, |
| 71 URLRequestContextGetter* request_context) { |
| 72 DCHECK(local_state); |
| 73 DCHECK(request_context); |
| 74 if (cloud_context_.get()) |
| 75 cloud_context_->Initialize(local_state, request_context); |
| 76 } |
| 77 |
| 78 BrowserPolicyContext::~BrowserPolicyContext() { |
| 79 if (cloud_context_.get()) |
| 80 cloud_context_->Shutdown(); |
| 81 cloud_context_.reset(); |
| 82 controller_.reset(); |
| 83 } |
| 84 |
| 85 ConfigurationPolicyProvider* |
| 86 BrowserPolicyContext::GetManagedPlatformProvider() const { |
| 87 return managed_platform_provider_.get(); |
| 88 } |
| 89 |
| 90 ConfigurationPolicyProvider* |
| 91 BrowserPolicyContext::GetManagedCloudProvider() const { |
| 92 if (cloud_context_.get()) |
| 93 return cloud_context_->GetManagedPolicyProvider(); |
| 94 |
| 95 return NULL; |
| 96 } |
| 97 |
| 98 ConfigurationPolicyProvider* |
| 99 BrowserPolicyContext::GetRecommendedPlatformProvider() const { |
| 100 return recommended_platform_provider_.get(); |
| 101 } |
| 102 |
| 103 ConfigurationPolicyProvider* |
| 104 BrowserPolicyContext::GetRecommendedCloudProvider() const { |
| 105 if (cloud_context_.get()) |
| 106 return cloud_context_->GetRecommendedPolicyProvider(); |
| 107 |
| 108 return NULL; |
| 109 } |
| 110 |
| 111 ConfigurationPolicyProvider* |
| 112 BrowserPolicyContext::CreateManagedPlatformProvider() { |
| 113 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
| 114 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
| 115 #if defined(OS_WIN) |
| 116 return new ConfigurationPolicyProviderWin(policy_list); |
| 117 #elif defined(OS_MACOSX) |
| 118 return new ConfigurationPolicyProviderMac(policy_list); |
| 119 #elif defined(OS_POSIX) |
| 120 FilePath config_dir_path; |
| 121 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
| 122 return new ConfigDirPolicyProvider( |
| 123 policy_list, |
| 124 config_dir_path.Append(FILE_PATH_LITERAL("managed"))); |
| 125 } else { |
| 126 return new DummyConfigurationPolicyProvider(policy_list); |
| 127 } |
| 128 #else |
| 129 return new DummyConfigurationPolicyProvider(policy_list); |
| 130 #endif |
| 131 } |
| 132 |
| 133 ConfigurationPolicyProvider* |
| 134 BrowserPolicyContext::CreateRecommendedPlatformProvider() { |
| 135 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
| 136 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
| 137 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 138 FilePath config_dir_path; |
| 139 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
| 140 return new ConfigDirPolicyProvider( |
| 141 policy_list, |
| 142 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
| 143 } else { |
| 144 return new DummyConfigurationPolicyProvider(policy_list); |
| 145 } |
| 146 #else |
| 147 return new DummyConfigurationPolicyProvider(policy_list); |
| 148 #endif |
| 149 } |
| 150 |
| 151 } // namespace |
OLD | NEW |