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