Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 14640020: [Resumption 9/11] Handle filename determination for resumed downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 private: 81 private:
82 DownloadProtectionService::DownloadCheckResult verdict_; 82 DownloadProtectionService::DownloadCheckResult verdict_;
83 83
84 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingState); 84 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingState);
85 }; 85 };
86 86
87 SafeBrowsingState::~SafeBrowsingState() {} 87 SafeBrowsingState::~SafeBrowsingState() {}
88 88
89 // Returns a file path in the form that is expected by 89 // Used with GetPlatformDownloadPath() to indicate which platform path to
90 // platform_util::OpenItem/ShowItemInFolder, including any transformation 90 // return.
91 // required for download abstractions layered on top of the core system, 91 enum PlatformDownloadPathType {
92 // e.g. download to Drive. 92 // Return the platform specific target path.
93 PLATFORM_TARGET_PATH,
94
95 // Return the platform specific current path. If the download is in-progress
96 // and the download location is a local filesystem path, then
97 // GetPlatformDownloadPath will return the path to the intermediate file.
98 PLATFORM_CURRENT_PATH
99 };
100
101 // Returns a path in the form that that is expected by platform_util::OpenItem /
102 // platform_util::ShowItemInFolder / DownloadTargetDeterminer.
103 //
104 // DownloadItems corresponding to Drive downloads use a temporary file as the
105 // target path. The paths returned by DownloadItem::GetFullPath() /
106 // GetTargetFilePath() refer to this temporary file. This function looks up the
107 // corresponding path in Drive for these downloads.
108 //
109 // How the platform path is determined is based on PlatformDownloadPathType.
93 base::FilePath GetPlatformDownloadPath(Profile* profile, 110 base::FilePath GetPlatformDownloadPath(Profile* profile,
94 const DownloadItem* download) { 111 const DownloadItem* download,
112 PlatformDownloadPathType path_type) {
95 #if defined(OS_CHROMEOS) 113 #if defined(OS_CHROMEOS)
114 // Drive downloads always return the target path for all types.
96 drive::DownloadHandler* drive_download_handler = 115 drive::DownloadHandler* drive_download_handler =
97 drive::DownloadHandler::GetForProfile(profile); 116 drive::DownloadHandler::GetForProfile(profile);
98 if (drive_download_handler && 117 if (drive_download_handler &&
99 drive_download_handler->IsDriveDownload(download)) 118 drive_download_handler->IsDriveDownload(download))
100 return drive_download_handler->GetTargetPath(download); 119 return drive_download_handler->GetTargetPath(download);
101 #endif 120 #endif
102 // The caller wants to open the download or show it in a file browser. The 121
103 // download could be in one of three states: 122 if (path_type == PLATFORM_TARGET_PATH)
104 // - Complete: The path we want is GetTargetFilePath().
105 // - Not complete, but there's an intermediate file: GetFullPath() will be
106 // non-empty and is the location of the intermediate file. Since no target
107 // file exits yet, use GetFullPath(). This should only happen during
108 // ShowDownloadInShell().
109 // - Not Complete, and there's no intermediate file: GetFullPath() will be
110 // empty. This shouldn't happen since CanShowInFolder() returns false and
111 // this function shouldn't have been called.
112 if (download->GetState() == DownloadItem::COMPLETE) {
113 DCHECK(!download->GetTargetFilePath().empty());
114 return download->GetTargetFilePath(); 123 return download->GetTargetFilePath();
115 }
116
117 DCHECK(!download->GetFullPath().empty());
118 return download->GetFullPath(); 124 return download->GetFullPath();
119 } 125 }
120 126
121 // Callback invoked by DownloadProtectionService::CheckClientDownload. 127 // Callback invoked by DownloadProtectionService::CheckClientDownload.
122 // |is_content_check_supported| is true if the SB service supports scanning the 128 // |is_content_check_supported| is true if the SB service supports scanning the
123 // download for malicious content. 129 // download for malicious content.
124 // |callback| is invoked with a danger type determined as follows: 130 // |callback| is invoked with a danger type determined as follows:
125 // 131 //
126 // Danger type is (in order of preference): 132 // Danger type is (in order of preference):
127 // * DANGEROUS_URL, if the URL is a known malware site. 133 // * DANGEROUS_URL, if the URL is a known malware site.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!profile_->IsOffTheRecord()) 178 if (!profile_->IsOffTheRecord())
173 return DownloadId(this, next_download_id_++); 179 return DownloadId(this, next_download_id_++);
174 180
175 return content::BrowserContext::GetDownloadManager( 181 return content::BrowserContext::GetDownloadManager(
176 profile_->GetOriginalProfile())->GetDelegate()->GetNextId(); 182 profile_->GetOriginalProfile())->GetDelegate()->GetNextId();
177 } 183 }
178 184
179 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( 185 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget(
180 DownloadItem* download, 186 DownloadItem* download,
181 const content::DownloadTargetCallback& callback) { 187 const content::DownloadTargetCallback& callback) {
182 DownloadTargetDeterminer::Start(download, 188 DownloadTargetDeterminer::Start(
183 download_prefs_.get(), 189 download,
184 this, 190 GetPlatformDownloadPath(
185 callback); 191 profile_, download, PLATFORM_TARGET_PATH),
192 download_prefs_.get(),
193 this,
194 callback);
186 return true; 195 return true;
187 } 196 }
188 197
189 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( 198 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
190 const base::FilePath& path) { 199 const base::FilePath& path) {
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
192 if (path.Extension().empty()) 201 if (path.Extension().empty())
193 return false; 202 return false;
194 // TODO(asanka): This determination is done based on |path|, while 203 // TODO(asanka): This determination is done based on |path|, while
195 // ShouldOpenDownload() detects extension downloads based on the 204 // ShouldOpenDownload() detects extension downloads based on the
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 default_extension, 333 default_extension,
325 can_save_as_complete, 334 can_save_as_complete,
326 download_prefs_.get(), 335 download_prefs_.get(),
327 callback); 336 callback);
328 } 337 }
329 338
330 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { 339 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) {
331 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); 340 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState());
332 if (!download->CanOpenDownload()) 341 if (!download->CanOpenDownload())
333 return; 342 return;
334 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); 343 base::FilePath platform_path(
344 GetPlatformDownloadPath(profile_, download, PLATFORM_TARGET_PATH));
345 DCHECK(!platform_path.empty());
346 platform_util::OpenItem(platform_path);
335 } 347 }
336 348
337 void ChromeDownloadManagerDelegate::ShowDownloadInShell( 349 void ChromeDownloadManagerDelegate::ShowDownloadInShell(
338 DownloadItem* download) { 350 DownloadItem* download) {
339 if (!download->CanShowInFolder()) 351 if (!download->CanShowInFolder())
340 return; 352 return;
341 platform_util::ShowItemInFolder(GetPlatformDownloadPath(profile_, download)); 353 base::FilePath platform_path(
354 GetPlatformDownloadPath(profile_, download, PLATFORM_CURRENT_PATH));
355 DCHECK(!platform_path.empty());
356 platform_util::ShowItemInFolder(platform_path);
342 } 357 }
343 358
344 void ChromeDownloadManagerDelegate::CheckForFileExistence( 359 void ChromeDownloadManagerDelegate::CheckForFileExistence(
345 DownloadItem* download, 360 DownloadItem* download,
346 const content::CheckForFileExistenceCallback& callback) { 361 const content::CheckForFileExistenceCallback& callback) {
347 #if defined(OS_CHROMEOS) 362 #if defined(OS_CHROMEOS)
348 drive::DownloadHandler* drive_download_handler = 363 drive::DownloadHandler* drive_download_handler =
349 drive::DownloadHandler::GetForProfile(profile_); 364 drive::DownloadHandler::GetForProfile(profile_);
350 if (drive_download_handler && 365 if (drive_download_handler &&
351 drive_download_handler->IsDriveDownload(download)) { 366 drive_download_handler->IsDriveDownload(download)) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 registrar_.Remove(this, 527 registrar_.Remove(this,
513 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 528 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
514 source); 529 source);
515 530
516 scoped_refptr<extensions::CrxInstaller> installer = 531 scoped_refptr<extensions::CrxInstaller> installer =
517 content::Source<extensions::CrxInstaller>(source).ptr(); 532 content::Source<extensions::CrxInstaller>(source).ptr();
518 content::DownloadOpenDelayedCallback callback = crx_installers_[installer]; 533 content::DownloadOpenDelayedCallback callback = crx_installers_[installer];
519 crx_installers_.erase(installer.get()); 534 crx_installers_.erase(installer.get());
520 callback.Run(installer->did_handle_successfully()); 535 callback.Run(installer->did_handle_successfully());
521 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698