OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/download/download_dir_policy_handler.h" | 5 #include "chrome/browser/download/download_dir_policy_handler.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_value_map.h" | 9 #include "base/prefs/pref_value_map.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/download/download_prefs.h" | 11 #include "chrome/browser/download/download_prefs.h" |
12 #include "chrome/browser/policy/policy_path_parser.h" | 12 #include "chrome/browser/policy/policy_path_parser.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "components/policy/core/browser/configuration_policy_handler_parameters .h" | |
15 #include "components/policy/core/browser/policy_error_map.h" | |
14 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
17 #include "components/policy/core/common/policy_types.h" | |
18 #include "grit/component_strings.h" | |
15 #include "policy/policy_constants.h" | 19 #include "policy/policy_constants.h" |
16 | 20 |
21 #if defined(OS_CHROMEOS) | |
22 #include "chrome/browser/chromeos/drive/file_system_util.h" | |
23 #endif | |
24 | |
25 namespace { | |
26 #if defined(OS_CHROMEOS) | |
27 const char* kDriveNamePolicyVariableName = "${google_drive}"; | |
28 | |
29 // Drive root folder relative to its mount point. | |
30 const base::FilePath::CharType* kRootRelativeToDriveMount = | |
31 FILE_PATH_LITERAL("root"); | |
32 #endif | |
33 } // namespace | |
34 | |
17 DownloadDirPolicyHandler::DownloadDirPolicyHandler() | 35 DownloadDirPolicyHandler::DownloadDirPolicyHandler() |
18 : TypeCheckingPolicyHandler(policy::key::kDownloadDirectory, | 36 : TypeCheckingPolicyHandler(policy::key::kDownloadDirectory, |
19 base::Value::TYPE_STRING) {} | 37 base::Value::TYPE_STRING) {} |
20 | 38 |
21 DownloadDirPolicyHandler::~DownloadDirPolicyHandler() {} | 39 DownloadDirPolicyHandler::~DownloadDirPolicyHandler() {} |
22 | 40 |
23 void DownloadDirPolicyHandler::ApplyPolicySettings( | 41 bool DownloadDirPolicyHandler::CheckPolicySettings( |
24 const policy::PolicyMap& policies, | 42 const policy::PolicyMap& policies, |
43 policy::PolicyErrorMap* errors) { | |
44 const base::Value* value = NULL; | |
45 if (!CheckAndGetValue(policies, errors, &value)) | |
46 return false; | |
47 | |
48 #if defined(OS_CHROMEOS) | |
49 // Download directory can only be set as a user policy. If it is set through | |
50 // platform policy for a chromeos=1 build, ignore it. | |
51 if (value && | |
52 policies.Get(policy_name())->scope != policy::POLICY_SCOPE_USER) { | |
53 errors->AddError(policy_name(), IDS_POLICY_SCOPE_ERROR); | |
54 return false; | |
55 } | |
56 #endif | |
57 | |
58 return true; | |
59 } | |
60 | |
61 void DownloadDirPolicyHandler::ApplyPolicySettingsWithParameters( | |
62 const policy::PolicyMap& policies, | |
63 const policy::PolicyHandlerParameters& parameters, | |
25 PrefValueMap* prefs) { | 64 PrefValueMap* prefs) { |
26 const base::Value* value = policies.GetValue(policy_name()); | 65 const base::Value* value = policies.GetValue(policy_name()); |
27 base::FilePath::StringType string_value; | 66 base::FilePath::StringType string_value; |
28 if (!value || !value->GetAsString(&string_value)) | 67 if (!value || !value->GetAsString(&string_value)) |
29 return; | 68 return; |
30 | 69 |
31 base::FilePath::StringType expanded_value = | 70 base::FilePath::StringType expanded_value; |
32 policy::path_parser::ExpandPathVariables(string_value); | 71 #if defined(OS_CHROMEOS) |
72 // TODO(kaliamoorthi): Clean up policy::path_parser and fold this code | |
73 // into it. http://crbug.com/352627 | |
74 size_t position = string_value.find(kDriveNamePolicyVariableName); | |
75 if (position != base::FilePath::StringType::npos) { | |
76 base::FilePath::StringType google_drive_root; | |
77 if (!parameters.user_id_hash.empty()) { | |
78 google_drive_root = drive::util::GetDriveMountPointPathForUserIdHash( | |
79 parameters.user_id_hash) | |
80 .Append(kRootRelativeToDriveMount) | |
81 .value(); | |
82 } | |
83 expanded_value = string_value.replace( | |
84 position, | |
85 base::FilePath::StringType(kDriveNamePolicyVariableName).length(), | |
86 google_drive_root); | |
87 } | |
88 #else | |
89 expanded_value = policy::path_parser::ExpandPathVariables(string_value); | |
90 #endif | |
33 // Make sure the path isn't empty, since that will point to an undefined | 91 // Make sure the path isn't empty, since that will point to an undefined |
34 // location; the default location is used instead in that case. | 92 // location; the default location is used instead in that case. |
35 // This is checked after path expansion because a non-empty policy value can | 93 // This is checked after path expansion because a non-empty policy value can |
36 // lead to an empty path value after expansion (e.g. "\"\""). | 94 // lead to an empty path value after expansion (e.g. "\"\""). |
37 if (expanded_value.empty()) | 95 if (expanded_value.empty()) |
38 expanded_value = DownloadPrefs::GetDefaultDownloadDirectory().value(); | 96 expanded_value = DownloadPrefs::GetDefaultDownloadDirectory().value(); |
39 prefs->SetValue(prefs::kDownloadDefaultDirectory, | 97 prefs->SetValue(prefs::kDownloadDefaultDirectory, |
40 base::Value::CreateStringValue(expanded_value)); | 98 base::Value::CreateStringValue(expanded_value)); |
41 prefs->SetValue(prefs::kPromptForDownload, | 99 |
42 base::Value::CreateBooleanValue(false)); | 100 // 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/
| |
101 // it would enable a user to bypass the mandatory policy. | |
102 if (policies.Get(policy_name())->level == policy::POLICY_LEVEL_MANDATORY) { | |
103 prefs->SetValue(prefs::kPromptForDownload, | |
104 base::Value::CreateBooleanValue(false)); | |
105 } | |
43 } | 106 } |
OLD | NEW |