| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 enum PlatformDownloadPathType { | 94 enum PlatformDownloadPathType { |
| 95 // Return the platform specific target path. | 95 // Return the platform specific target path. |
| 96 PLATFORM_TARGET_PATH, | 96 PLATFORM_TARGET_PATH, |
| 97 | 97 |
| 98 // Return the platform specific current path. If the download is in-progress | 98 // Return the platform specific current path. If the download is in-progress |
| 99 // and the download location is a local filesystem path, then | 99 // and the download location is a local filesystem path, then |
| 100 // GetPlatformDownloadPath will return the path to the intermediate file. | 100 // GetPlatformDownloadPath will return the path to the intermediate file. |
| 101 PLATFORM_CURRENT_PATH | 101 PLATFORM_CURRENT_PATH |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // Returns a path in the form that that is expected by platform_util::OpenItem / | 104 // Returns a path in the form that that is expected by platform_util::OpenFile / |
| 105 // platform_util::ShowItemInFolder / DownloadTargetDeterminer. | 105 // platform_util::OpenFolder / platform_util::ShowItemInFolder / |
| 106 // DownloadTargetDeterminer. |
| 106 // | 107 // |
| 107 // DownloadItems corresponding to Drive downloads use a temporary file as the | 108 // DownloadItems corresponding to Drive downloads use a temporary file as the |
| 108 // target path. The paths returned by DownloadItem::GetFullPath() / | 109 // target path. The paths returned by DownloadItem::GetFullPath() / |
| 109 // GetTargetFilePath() refer to this temporary file. This function looks up the | 110 // GetTargetFilePath() refer to this temporary file. This function looks up the |
| 110 // corresponding path in Drive for these downloads. | 111 // corresponding path in Drive for these downloads. |
| 111 // | 112 // |
| 112 // How the platform path is determined is based on PlatformDownloadPathType. | 113 // How the platform path is determined is based on PlatformDownloadPathType. |
| 113 base::FilePath GetPlatformDownloadPath(Profile* profile, | 114 base::FilePath GetPlatformDownloadPath(Profile* profile, |
| 114 const DownloadItem* download, | 115 const DownloadItem* download, |
| 115 PlatformDownloadPathType path_type) { | 116 PlatformDownloadPathType path_type) { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 can_save_as_complete, | 422 can_save_as_complete, |
| 422 download_prefs_.get(), | 423 download_prefs_.get(), |
| 423 callback); | 424 callback); |
| 424 } | 425 } |
| 425 | 426 |
| 426 void ChromeDownloadManagerDelegate::OpenDownloadUsingPlatformHandler( | 427 void ChromeDownloadManagerDelegate::OpenDownloadUsingPlatformHandler( |
| 427 DownloadItem* download) { | 428 DownloadItem* download) { |
| 428 base::FilePath platform_path( | 429 base::FilePath platform_path( |
| 429 GetPlatformDownloadPath(profile_, download, PLATFORM_TARGET_PATH)); | 430 GetPlatformDownloadPath(profile_, download, PLATFORM_TARGET_PATH)); |
| 430 DCHECK(!platform_path.empty()); | 431 DCHECK(!platform_path.empty()); |
| 431 platform_util::OpenItem(profile_, platform_path); | 432 platform_util::OpenFile(profile_, platform_path, |
| 433 platform_util::OpenOperationCallback()); |
| 432 } | 434 } |
| 433 | 435 |
| 434 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { | 436 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { |
| 435 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); | 437 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 436 DCHECK(!download->GetTargetFilePath().empty()); | 438 DCHECK(!download->GetTargetFilePath().empty()); |
| 437 if (!download->CanOpenDownload()) | 439 if (!download->CanOpenDownload()) |
| 438 return; | 440 return; |
| 439 | 441 |
| 440 if (!DownloadItemModel(download).ShouldPreferOpeningInBrowser()) { | 442 if (!DownloadItemModel(download).ShouldPreferOpeningInBrowser()) { |
| 441 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_PLATFORM); | 443 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_PLATFORM); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 742 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 741 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 743 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 742 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 744 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 743 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 745 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 744 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 746 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 745 return true; | 747 return true; |
| 746 } | 748 } |
| 747 #endif | 749 #endif |
| 748 return false; | 750 return false; |
| 749 } | 751 } |
| OLD | NEW |