Chromium Code Reviews| Index: chrome/browser/download/download_dir_policy_handler.cc |
| diff --git a/chrome/browser/download/download_dir_policy_handler.cc b/chrome/browser/download/download_dir_policy_handler.cc |
| index 3f79ff513a4022250245425044f9ed9a89c45faa..b15eaaf5887ea2d4f21a1b3a3d9489ac56bf51e0 100644 |
| --- a/chrome/browser/download/download_dir_policy_handler.cc |
| +++ b/chrome/browser/download/download_dir_policy_handler.cc |
| @@ -11,25 +11,83 @@ |
| #include "chrome/browser/download/download_prefs.h" |
| #include "chrome/browser/policy/policy_path_parser.h" |
| #include "chrome/common/pref_names.h" |
| +#include "components/policy/core/browser/configuration_policy_handler_parameters.h" |
| +#include "components/policy/core/browser/policy_error_map.h" |
| #include "components/policy/core/common/policy_map.h" |
| +#include "components/policy/core/common/policy_types.h" |
| +#include "grit/component_strings.h" |
| #include "policy/policy_constants.h" |
| +#if defined(OS_CHROMEOS) |
| +#include "chrome/browser/chromeos/drive/file_system_util.h" |
| +#endif |
| + |
| +namespace { |
| +#if defined(OS_CHROMEOS) |
| +const char* kDriveNamePolicyVariableName = "${google_drive}"; |
| + |
| +// Drive root folder relative to its mount point. |
| +const base::FilePath::CharType* kRootRelativeToDriveMount = |
| + FILE_PATH_LITERAL("root"); |
| +#endif |
| +} // namespace |
| + |
| DownloadDirPolicyHandler::DownloadDirPolicyHandler() |
| : TypeCheckingPolicyHandler(policy::key::kDownloadDirectory, |
| base::Value::TYPE_STRING) {} |
| DownloadDirPolicyHandler::~DownloadDirPolicyHandler() {} |
| -void DownloadDirPolicyHandler::ApplyPolicySettings( |
| +bool DownloadDirPolicyHandler::CheckPolicySettings( |
| const policy::PolicyMap& policies, |
| + policy::PolicyErrorMap* errors) { |
| + const base::Value* value = NULL; |
| + if (!CheckAndGetValue(policies, errors, &value)) |
| + return false; |
| + |
| +#if defined(OS_CHROMEOS) |
| + // Download directory can only be set as a user policy. If it is set through |
| + // platform policy for a chromeos=1 build, ignore it. |
| + if (value && |
| + policies.Get(policy_name())->scope != policy::POLICY_SCOPE_USER) { |
| + errors->AddError(policy_name(), IDS_POLICY_SCOPE_ERROR); |
| + return false; |
| + } |
| +#endif |
| + |
| + return true; |
| +} |
| + |
| +void DownloadDirPolicyHandler::ApplyPolicySettingsWithParameters( |
| + const policy::PolicyMap& policies, |
| + const policy::PolicyHandlerParameters& parameters, |
| PrefValueMap* prefs) { |
| const base::Value* value = policies.GetValue(policy_name()); |
| base::FilePath::StringType string_value; |
| if (!value || !value->GetAsString(&string_value)) |
| return; |
| - base::FilePath::StringType expanded_value = |
| - policy::path_parser::ExpandPathVariables(string_value); |
| + base::FilePath::StringType expanded_value; |
| +#if defined(OS_CHROMEOS) |
| + // TODO(kaliamoorthi): Clean up policy::path_parser and fold this code |
| + // into it. http://crbug.com/352627 |
| + size_t position = string_value.find(kDriveNamePolicyVariableName); |
| + if (position != base::FilePath::StringType::npos) { |
| + base::FilePath::StringType google_drive_root; |
| + if (!parameters.user_id_hash.empty()) { |
| + google_drive_root = drive::util::GetDriveMountPointPathForUserIdHash( |
| + parameters.user_id_hash) |
| + .Append(kRootRelativeToDriveMount) |
| + .value(); |
| + } |
| + expanded_value = string_value.replace( |
| + position, |
| + base::FilePath::StringType(kDriveNamePolicyVariableName).length(), |
| + google_drive_root); |
| + } |
| +#else |
| + expanded_value = policy::path_parser::ExpandPathVariables(string_value); |
| +#endif |
| // Make sure the path isn't empty, since that will point to an undefined |
| // location; the default location is used instead in that case. |
| // This is checked after path expansion because a non-empty policy value can |
| @@ -38,6 +96,11 @@ void DownloadDirPolicyHandler::ApplyPolicySettings( |
| expanded_value = DownloadPrefs::GetDefaultDownloadDirectory().value(); |
| prefs->SetValue(prefs::kDownloadDefaultDirectory, |
| base::Value::CreateStringValue(expanded_value)); |
| - prefs->SetValue(prefs::kPromptForDownload, |
| - base::Value::CreateBooleanValue(false)); |
| + |
| + // If the policy is mandatory prompt for download should be disabled, if not |
|
bartfab (slow)
2014/03/14 16:55:40
Nit 1: s/mandatory/mandatory, /
Nit 2: s/, if not/
|
| + // it would enable a user to bypass the mandatory policy. |
| + if (policies.Get(policy_name())->level == policy::POLICY_LEVEL_MANDATORY) { |
| + prefs->SetValue(prefs::kPromptForDownload, |
| + base::Value::CreateBooleanValue(false)); |
| + } |
| } |