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" | |
14 #include "components/policy/core/common/policy_map.h" | 15 #include "components/policy/core/common/policy_map.h" |
16 #include "components/policy/core/common/policy_types.h" | |
15 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
16 | 18 |
19 #if defined(OS_CHROMEOS) | |
20 #include "chrome/browser/chromeos/drive/file_system_util.h" | |
21 #endif | |
22 | |
23 #if defined(OS_CHROMEOS) | |
24 const char* kDriveNamePolicyVarName = "${drive_name}"; | |
bartfab (slow)
2014/03/13 13:20:00
1: Why the "name" in "drive_name"? How about somet
| |
25 const char* kPathRelativeToDriveRoot = "/root/"; | |
kinaba
2014/03/13 03:56:50
nit: char => base::FilePath::CharType (and FILE_PA
bartfab (slow)
2014/03/13 13:20:00
Document what this is.
| |
26 #endif | |
27 | |
17 DownloadDirPolicyHandler::DownloadDirPolicyHandler() | 28 DownloadDirPolicyHandler::DownloadDirPolicyHandler() |
18 : TypeCheckingPolicyHandler(policy::key::kDownloadDirectory, | 29 : TypeCheckingPolicyHandler(policy::key::kDownloadDirectory, |
19 base::Value::TYPE_STRING) {} | 30 base::Value::TYPE_STRING) {} |
20 | 31 |
21 DownloadDirPolicyHandler::~DownloadDirPolicyHandler() {} | 32 DownloadDirPolicyHandler::~DownloadDirPolicyHandler() {} |
22 | 33 |
34 bool DownloadDirPolicyHandler::CheckPolicySettings( | |
35 const policy::PolicyMap& policies, | |
36 policy::PolicyErrorMap* errors) { | |
37 const base::Value* value = NULL; | |
38 bool check_status = CheckAndGetValue(policies, errors, &value); | |
bartfab (slow)
2014/03/13 13:20:00
Nit: Instead of introducing a boolean, do an early
| |
39 | |
40 #if defined(OS_CHROMEOS) | |
41 if (check_status && value != NULL && | |
bartfab (slow)
2014/03/13 13:20:00
1: When the check result is |false|, you should ad
| |
42 policies.Get(policy_name())->scope != policy::POLICY_SCOPE_USER) | |
43 check_status = false; | |
44 #endif | |
45 | |
46 return check_status; | |
47 } | |
48 | |
23 void DownloadDirPolicyHandler::ApplyPolicySettings( | 49 void DownloadDirPolicyHandler::ApplyPolicySettings( |
24 const policy::PolicyMap& policies, | 50 const policy::PolicyMap& policies, |
25 PrefValueMap* prefs) { | 51 PrefValueMap* prefs) { |
52 NOTREACHED() << "This policy handler should not be called"; | |
bartfab (slow)
2014/03/13 13:20:00
Nit 1: #include "base/logging.h"
Nit 2: No need to
| |
53 } | |
54 | |
55 void DownloadDirPolicyHandler::ApplyPolicySettingsWithPars( | |
56 const policy::PolicyMap& policies, | |
57 const policy::PolicyHandlerParameters& pars, | |
58 PrefValueMap* prefs) { | |
26 const base::Value* value = policies.GetValue(policy_name()); | 59 const base::Value* value = policies.GetValue(policy_name()); |
27 base::FilePath::StringType string_value; | 60 base::FilePath::StringType string_value; |
28 if (!value || !value->GetAsString(&string_value)) | 61 if (!value || !value->GetAsString(&string_value)) |
29 return; | 62 return; |
30 | 63 |
31 base::FilePath::StringType expanded_value = | 64 base::FilePath::StringType expanded_value = |
32 policy::path_parser::ExpandPathVariables(string_value); | 65 policy::path_parser::ExpandPathVariables(string_value); |
bartfab (slow)
2014/03/13 13:20:00
There is a policy_path_parser_linux.cc. Why not ad
| |
66 #if defined(OS_CHROMEOS) | |
67 if (!string_value.compare(kDriveNamePolicyVarName)) | |
bartfab (slow)
2014/03/13 13:20:00
You should do a substring match and substitution i
| |
68 expanded_value = pars.active_username_hash.empty() | |
69 ? "" | |
70 : drive::util::GetDriveMountPointPathUsingUserHash( | |
71 pars.active_username_hash).value() + | |
72 kPathRelativeToDriveRoot; | |
73 #endif | |
33 // Make sure the path isn't empty, since that will point to an undefined | 74 // 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. | 75 // location; the default location is used instead in that case. |
35 // This is checked after path expansion because a non-empty policy value can | 76 // This is checked after path expansion because a non-empty policy value can |
36 // lead to an empty path value after expansion (e.g. "\"\""). | 77 // lead to an empty path value after expansion (e.g. "\"\""). |
37 if (expanded_value.empty()) | 78 if (expanded_value.empty()) |
38 expanded_value = DownloadPrefs::GetDefaultDownloadDirectory().value(); | 79 expanded_value = DownloadPrefs::GetDefaultDownloadDirectory().value(); |
39 prefs->SetValue(prefs::kDownloadDefaultDirectory, | 80 prefs->SetValue(prefs::kDownloadDefaultDirectory, |
40 base::Value::CreateStringValue(expanded_value)); | 81 base::Value::CreateStringValue(expanded_value)); |
41 prefs->SetValue(prefs::kPromptForDownload, | 82 if (policies.Get(policy_name())->level == policy::POLICY_LEVEL_MANDATORY) |
bartfab (slow)
2014/03/13 13:20:00
Nit: Multi-line conditionals require curly braces.
| |
42 base::Value::CreateBooleanValue(false)); | 83 prefs->SetValue(prefs::kPromptForDownload, |
84 base::Value::CreateBooleanValue(false)); | |
43 } | 85 } |
OLD | NEW |