Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / download / download_dir_policy_handler.cc
blob3f79ff513a4022250245425044f9ed9a89c45faa
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
3 // found in the LICENSE file.
5 #include "chrome/browser/download/download_dir_policy_handler.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_value_map.h"
10 #include "base/values.h"
11 #include "chrome/browser/download/download_prefs.h"
12 #include "chrome/browser/policy/policy_path_parser.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/policy/core/common/policy_map.h"
15 #include "policy/policy_constants.h"
17 DownloadDirPolicyHandler::DownloadDirPolicyHandler()
18 : TypeCheckingPolicyHandler(policy::key::kDownloadDirectory,
19 base::Value::TYPE_STRING) {}
21 DownloadDirPolicyHandler::~DownloadDirPolicyHandler() {}
23 void DownloadDirPolicyHandler::ApplyPolicySettings(
24 const policy::PolicyMap& policies,
25 PrefValueMap* prefs) {
26 const base::Value* value = policies.GetValue(policy_name());
27 base::FilePath::StringType string_value;
28 if (!value || !value->GetAsString(&string_value))
29 return;
31 base::FilePath::StringType expanded_value =
32 policy::path_parser::ExpandPathVariables(string_value);
33 // 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.
35 // This is checked after path expansion because a non-empty policy value can
36 // lead to an empty path value after expansion (e.g. "\"\"").
37 if (expanded_value.empty())
38 expanded_value = DownloadPrefs::GetDefaultDownloadDirectory().value();
39 prefs->SetValue(prefs::kDownloadDefaultDirectory,
40 base::Value::CreateStringValue(expanded_value));
41 prefs->SetValue(prefs::kPromptForDownload,
42 base::Value::CreateBooleanValue(false));