Chromium Code Reviews| 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/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 #include "net/base/net_util.h" | 54 #include "net/base/net_util.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 56 | 56 |
| 57 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
| 58 #include "chrome/browser/chromeos/drive/download_handler.h" | 58 #include "chrome/browser/chromeos/drive/download_handler.h" |
| 59 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 59 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
| 60 #include "chrome/browser/download/download_file_picker_chromeos.h" | 60 #include "chrome/browser/download/download_file_picker_chromeos.h" |
| 61 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | 61 #include "chrome/browser/download/save_package_file_picker_chromeos.h" |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 using content::BrowserContext; | |
| 65 using content::BrowserThread; | 64 using content::BrowserThread; |
| 66 using content::DownloadId; | 65 using content::DownloadId; |
| 67 using content::DownloadItem; | 66 using content::DownloadItem; |
| 68 using content::DownloadManager; | 67 using content::DownloadManager; |
| 69 using content::WebContents; | 68 using content::WebContents; |
| 70 using safe_browsing::DownloadProtectionService; | 69 using safe_browsing::DownloadProtectionService; |
| 71 | 70 |
| 72 namespace { | 71 namespace { |
| 73 | 72 |
| 74 // String pointer used for identifying safebrowing data associated with | 73 // String pointer used for identifying safebrowing data associated with |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 #if defined(OS_CHROMEOS) | 173 #if defined(OS_CHROMEOS) |
| 175 drive::DownloadHandler* drive_download_handler = | 174 drive::DownloadHandler* drive_download_handler = |
| 176 drive::DownloadHandler::GetForProfile(profile); | 175 drive::DownloadHandler::GetForProfile(profile); |
| 177 if (drive_download_handler && | 176 if (drive_download_handler && |
| 178 drive_download_handler->IsDriveDownload(download)) | 177 drive_download_handler->IsDriveDownload(download)) |
| 179 return drive_download_handler->GetTargetPath(download); | 178 return drive_download_handler->GetTargetPath(download); |
| 180 #endif | 179 #endif |
| 181 return download->GetFullPath(); | 180 return download->GetFullPath(); |
| 182 } | 181 } |
| 183 | 182 |
| 183 void VirtualSavePathChosen(content::BrowserContext* context, | |
| 184 const base::FilePath& path) { | |
| 185 StringPrefMember save_file_path; | |
| 186 save_file_path.Init(prefs::kSaveFileDefaultDirectory, | |
| 187 Profile::FromBrowserContext(context)->GetPrefs()); | |
| 188 #if defined(OS_POSIX) | |
| 189 std::string path_string = path.DirName().value(); | |
| 190 #elif defined(OS_WIN) | |
| 191 std::string path_string = WideToUTF8(path.DirName().value()); | |
|
Randy Smith (Not in Mondays)
2013/04/25 17:58:55
Is this the usual method of persisting file paths
asanka
2013/04/25 19:01:39
kSaveFileDefaultDirectory is registered in CDMD as
benjhayden
2013/04/30 21:11:12
Done.
benjhayden
2013/04/30 21:11:12
Done.
| |
| 192 #endif | |
| 193 // If user change the default saving directory, we will remember it just | |
| 194 // like IE and FireFox. | |
| 195 if (!context->IsOffTheRecord() && | |
| 196 (save_file_path.GetValue() != path_string)) { | |
| 197 save_file_path.SetValue(path_string); | |
| 198 } | |
| 199 } | |
| 200 | |
| 184 } // namespace | 201 } // namespace |
| 185 | 202 |
| 186 // static | 203 // static |
| 187 void ChromeDownloadManagerDelegate::RegisterUserPrefs( | 204 void ChromeDownloadManagerDelegate::RegisterUserPrefs( |
| 188 PrefRegistrySyncable* registry) { | 205 PrefRegistrySyncable* registry) { |
| 189 const base::FilePath& default_download_path = | 206 const base::FilePath& default_download_path = |
| 190 download_util::GetDefaultDownloadDirectory(); | 207 download_util::GetDefaultDownloadDirectory(); |
| 191 registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, | 208 registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, |
| 192 default_download_path, | 209 default_download_path, |
| 193 PrefRegistrySyncable::UNSYNCABLE_PREF); | 210 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 207 } | 224 } |
| 208 | 225 |
| 209 void ChromeDownloadManagerDelegate::Shutdown() { | 226 void ChromeDownloadManagerDelegate::Shutdown() { |
| 210 download_prefs_.reset(); | 227 download_prefs_.reset(); |
| 211 } | 228 } |
| 212 | 229 |
| 213 DownloadId ChromeDownloadManagerDelegate::GetNextId() { | 230 DownloadId ChromeDownloadManagerDelegate::GetNextId() { |
| 214 if (!profile_->IsOffTheRecord()) | 231 if (!profile_->IsOffTheRecord()) |
| 215 return DownloadId(this, next_download_id_++); | 232 return DownloadId(this, next_download_id_++); |
| 216 | 233 |
| 217 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> | 234 return content::BrowserContext::GetDownloadManager( |
| 218 GetDelegate()->GetNextId(); | 235 profile_->GetOriginalProfile())->GetDelegate()->GetNextId(); |
| 219 } | 236 } |
| 220 | 237 |
| 221 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( | 238 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( |
| 222 DownloadItem* download, | 239 DownloadItem* download, |
| 223 const content::DownloadTargetCallback& callback) { | 240 const content::DownloadTargetCallback& callback) { |
| 224 #if defined(FULL_SAFE_BROWSING) | 241 #if defined(FULL_SAFE_BROWSING) |
| 225 DownloadProtectionService* service = GetDownloadProtectionService(); | 242 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 226 if (service) { | 243 if (service) { |
| 227 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " | 244 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " |
| 228 << download->DebugString(false); | 245 << download->DebugString(false); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 378 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
| 362 #if defined(FULL_SAFE_BROWSING) | 379 #if defined(FULL_SAFE_BROWSING) |
| 363 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 380 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 364 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 381 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
| 365 #else | 382 #else |
| 366 return false; | 383 return false; |
| 367 #endif | 384 #endif |
| 368 } | 385 } |
| 369 | 386 |
| 370 void ChromeDownloadManagerDelegate::GetSaveDir( | 387 void ChromeDownloadManagerDelegate::GetSaveDir( |
| 371 BrowserContext* browser_context, | 388 content::BrowserContext* browser_context, |
| 372 base::FilePath* website_save_dir, | 389 base::FilePath* website_save_dir, |
| 373 base::FilePath* download_save_dir, | 390 base::FilePath* download_save_dir, |
| 374 bool* skip_dir_check) { | 391 bool* skip_dir_check) { |
| 375 Profile* profile = Profile::FromBrowserContext(browser_context); | 392 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 376 PrefService* prefs = profile->GetPrefs(); | 393 PrefService* prefs = profile->GetPrefs(); |
| 377 | 394 |
| 378 // Check whether the preference for the preferred directory for | 395 // Check whether the preference for the preferred directory for |
| 379 // saving file has been explicitly set. If not, and the preference | 396 // saving file has been explicitly set. If not, and the preference |
| 380 // for the default download directory has been set, initialize it | 397 // for the default download directory has been set, initialize it |
| 381 // with the latter. Note that the defaults for both are the same. | 398 // with the latter. Note that the defaults for both are the same. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 405 const base::FilePath& suggested_path, | 422 const base::FilePath& suggested_path, |
| 406 const base::FilePath::StringType& default_extension, | 423 const base::FilePath::StringType& default_extension, |
| 407 bool can_save_as_complete, | 424 bool can_save_as_complete, |
| 408 const content::SavePackagePathPickedCallback& callback) { | 425 const content::SavePackagePathPickedCallback& callback) { |
| 409 // Deletes itself. | 426 // Deletes itself. |
| 410 #if defined(OS_CHROMEOS) | 427 #if defined(OS_CHROMEOS) |
| 411 new SavePackageFilePickerChromeOS( | 428 new SavePackageFilePickerChromeOS( |
| 412 web_contents, | 429 web_contents, |
| 413 suggested_path, | 430 suggested_path, |
| 414 can_save_as_complete, | 431 can_save_as_complete, |
| 432 base::Bind(&VirtualSavePathChosen, web_contents->GetBrowserContext()), | |
| 415 callback); | 433 callback); |
| 416 #else | 434 #else |
| 417 new SavePackageFilePicker( | 435 new SavePackageFilePicker( |
| 418 web_contents, | 436 web_contents, |
| 419 suggested_path, | 437 suggested_path, |
| 420 default_extension, | 438 default_extension, |
| 421 can_save_as_complete, | 439 can_save_as_complete, |
| 422 download_prefs_.get(), | 440 download_prefs_.get(), |
| 441 base::Bind(&VirtualSavePathChosen, web_contents->GetBrowserContext()), | |
| 423 callback); | 442 callback); |
| 424 #endif | 443 #endif |
| 425 } | 444 } |
| 426 | 445 |
| 427 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { | 446 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { |
| 428 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); | 447 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); |
| 429 } | 448 } |
| 430 | 449 |
| 431 void ChromeDownloadManagerDelegate::ShowDownloadInShell( | 450 void ChromeDownloadManagerDelegate::ShowDownloadInShell( |
| 432 DownloadItem* download) { | 451 DownloadItem* download) { |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a | 911 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a |
| 893 // directory to persist. Or perhaps, if the Drive path | 912 // directory to persist. Or perhaps, if the Drive path |
| 894 // substitution logic is moved here, then we would have a | 913 // substitution logic is moved here, then we would have a |
| 895 // persistable path after the DownloadFilePicker is done. | 914 // persistable path after the DownloadFilePicker is done. |
| 896 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && | 915 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && |
| 897 !download->IsTemporary()) | 916 !download->IsTemporary()) |
| 898 last_download_path_ = target_path.DirName(); | 917 last_download_path_ = target_path.DirName(); |
| 899 } | 918 } |
| 900 callback.Run(target_path, disposition, danger_type, intermediate_path); | 919 callback.Run(target_path, disposition, danger_type, intermediate_path); |
| 901 } | 920 } |
| OLD | NEW |