OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_prefs.h" | 5 #include "chrome/browser/download/download_prefs.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 18 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
19 #include "chrome/browser/download/download_extensions.h" | 19 #include "chrome/browser/download/download_extensions.h" |
20 #include "chrome/browser/download/download_service.h" | 20 #include "chrome/browser/download/download_service.h" |
21 #include "chrome/browser/download/download_service_factory.h" | 21 #include "chrome/browser/download/download_service_factory.h" |
22 #include "chrome/browser/download/download_util.h" | 22 #include "chrome/browser/download/download_util.h" |
| 23 #include "chrome/browser/prefs/pref_registry_syncable.h" |
23 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/download_manager.h" | 29 #include "content/public/browser/download_manager.h" |
29 #include "content/public/browser/save_page_type.h" | 30 #include "content/public/browser/save_page_type.h" |
30 | 31 |
31 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
32 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 33 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
(...skipping 27 matching lines...) Expand all Loading... |
60 download_util::GetFileDangerLevel(path) == download_util::NotDangerous) | 61 download_util::GetFileDangerLevel(path) == download_util::NotDangerous) |
61 auto_open_.insert(path.value()); | 62 auto_open_.insert(path.value()); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 DownloadPrefs::~DownloadPrefs() { | 66 DownloadPrefs::~DownloadPrefs() { |
66 SaveAutoOpenState(); | 67 SaveAutoOpenState(); |
67 } | 68 } |
68 | 69 |
69 // static | 70 // static |
70 void DownloadPrefs::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 71 void DownloadPrefs::RegisterUserPrefs(PrefService* prefs, |
71 prefs->RegisterBooleanPref(prefs::kPromptForDownload, | 72 PrefRegistrySyncable* registry) { |
72 false, | 73 registry->RegisterBooleanPref(prefs::kPromptForDownload, |
73 PrefServiceSyncable::SYNCABLE_PREF); | 74 false, |
74 prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, | 75 PrefRegistrySyncable::SYNCABLE_PREF); |
75 "", | 76 registry->RegisterStringPref(prefs::kDownloadExtensionsToOpen, |
76 PrefServiceSyncable::UNSYNCABLE_PREF); | 77 "", |
77 prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, | 78 PrefRegistrySyncable::UNSYNCABLE_PREF); |
78 false, | 79 registry->RegisterBooleanPref(prefs::kDownloadDirUpgraded, |
79 PrefServiceSyncable::UNSYNCABLE_PREF); | 80 false, |
80 prefs->RegisterIntegerPref(prefs::kSaveFileType, | 81 PrefRegistrySyncable::UNSYNCABLE_PREF); |
81 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 82 registry->RegisterIntegerPref(prefs::kSaveFileType, |
82 PrefServiceSyncable::UNSYNCABLE_PREF); | 83 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
| 84 PrefRegistrySyncable::UNSYNCABLE_PREF); |
83 | 85 |
84 // The default download path is userprofile\download. | 86 // The default download path is userprofile\download. |
85 const base::FilePath& default_download_path = | 87 const base::FilePath& default_download_path = |
86 download_util::GetDefaultDownloadDirectory(); | 88 download_util::GetDefaultDownloadDirectory(); |
87 prefs->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, | 89 registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, |
88 default_download_path, | 90 default_download_path, |
89 PrefServiceSyncable::UNSYNCABLE_PREF); | 91 PrefRegistrySyncable::UNSYNCABLE_PREF); |
90 | 92 |
91 #if defined(OS_CHROMEOS) | 93 #if defined(OS_CHROMEOS) |
92 // Ensure that the download directory specified in the preferences exists. | 94 // Ensure that the download directory specified in the preferences exists. |
93 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
94 BrowserThread::FILE, FROM_HERE, | 96 BrowserThread::FILE, FROM_HERE, |
95 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), | 97 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), |
96 default_download_path)); | 98 default_download_path)); |
97 #endif // defined(OS_CHROMEOS) | 99 #endif // defined(OS_CHROMEOS) |
98 | 100 |
| 101 // TODO(joi): Move this out, and get rid of PrefService param above. |
| 102 |
99 // If the download path is dangerous we forcefully reset it. But if we do | 103 // If the download path is dangerous we forcefully reset it. But if we do |
100 // so we set a flag to make sure we only do it once, to avoid fighting | 104 // so we set a flag to make sure we only do it once, to avoid fighting |
101 // the user if he really wants it on an unsafe place such as the desktop. | 105 // the user if he really wants it on an unsafe place such as the desktop. |
102 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { | 106 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { |
103 base::FilePath current_download_dir = prefs->GetFilePath( | 107 base::FilePath current_download_dir = prefs->GetFilePath( |
104 prefs::kDownloadDefaultDirectory); | 108 prefs::kDownloadDefaultDirectory); |
105 if (download_util::DownloadPathIsDangerous(current_download_dir)) { | 109 if (download_util::DownloadPathIsDangerous(current_download_dir)) { |
106 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, | 110 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, |
107 default_download_path); | 111 default_download_path); |
108 } | 112 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 extensions.erase(extensions.size() - 1); | 206 extensions.erase(extensions.size() - 1); |
203 | 207 |
204 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); | 208 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); |
205 } | 209 } |
206 | 210 |
207 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( | 211 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( |
208 const base::FilePath::StringType& a, | 212 const base::FilePath::StringType& a, |
209 const base::FilePath::StringType& b) const { | 213 const base::FilePath::StringType& b) const { |
210 return base::FilePath::CompareLessIgnoreCase(a, b); | 214 return base::FilePath::CompareLessIgnoreCase(a, b); |
211 } | 215 } |
OLD | NEW |