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

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: Merge with r203194 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 the intended usage of the
90 // platform_util::OpenItem/ShowItemInFolder, including any transformation 90 // returned path.
91 // required for download abstractions layered on top of the core system, 91 enum PlatformPathUsage {
92 // e.g. download to Drive. 92 PATH_FOR_OPEN,
93 PATH_FOR_SHOW_IN_FOLDER,
94 PATH_FOR_TARGET_DETERMINATION
95 };
96
97 // Returns a path in the form that that is expected by platform_util::OpenItem /
98 // platform_util::ShowItemInFolder / DownloadTargetDeterminer.
99 //
100 // DownloadItems corresponding to Drive downloads use a temporary file as the
101 // target path. The paths returned by DownloadItem::GetFullPath() /
102 // GetTargetFilePath() refer to this temporary file. This function looks up the
103 // corresponding path in Drive for these downloads.
104 //
105 // For downloads that target the local filesystem, this function returns either
106 // the path to the intermediate file or the target path depending on
107 // |path_usage|:
108 // PATH_FOR_OPEN: Always returns the target path.
109 // PATH_FOR_SHOW_IN_FOLDER: Path to the intermediate file if the download is
110 // still in progress. Otherwise returns the target path.
111 // PATH_FOR_TARGET_DETERMINATION: Always returns the target path.
Randy Smith (Not in Mondays) 2013/05/30 21:26:24 Is there a reason not to make this an "always_retu
asanka 2013/05/31 19:23:59 Done.
93 base::FilePath GetPlatformDownloadPath(Profile* profile, 112 base::FilePath GetPlatformDownloadPath(Profile* profile,
94 const DownloadItem* download) { 113 const DownloadItem* download,
114 PlatformPathUsage path_usage) {
95 #if defined(OS_CHROMEOS) 115 #if defined(OS_CHROMEOS)
116 // Drive downloads always return the target path for all usages.
96 drive::DownloadHandler* drive_download_handler = 117 drive::DownloadHandler* drive_download_handler =
97 drive::DownloadHandler::GetForProfile(profile); 118 drive::DownloadHandler::GetForProfile(profile);
98 if (drive_download_handler && 119 if (drive_download_handler &&
99 drive_download_handler->IsDriveDownload(download)) 120 drive_download_handler->IsDriveDownload(download))
100 return drive_download_handler->GetTargetPath(download); 121 return drive_download_handler->GetTargetPath(download);
101 #endif 122 #endif
102 // The caller wants to open the download or show it in a file browser. The 123
103 // download could be in one of three states: 124 switch (path_usage) {
104 // - Complete: The path we want is GetTargetFilePath(). 125 case PATH_FOR_OPEN:
105 // - Not complete, but there's an intermediate file: GetFullPath() will be 126 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState());
106 // non-empty and is the location of the intermediate file. Since no target 127 return download->GetTargetFilePath();
107 // file exits yet, use GetFullPath(). This should only happen during 128
108 // ShowDownloadInShell(). 129 case PATH_FOR_SHOW_IN_FOLDER:
109 // - Not Complete, and there's no intermediate file: GetFullPath() will be 130 DCHECK(download->GetState() == DownloadItem::IN_PROGRESS ||
110 // empty. This shouldn't happen since CanShowInFolder() returns false and 131 download->GetState() == DownloadItem::COMPLETE);
111 // this function shouldn't have been called. 132 return (download->GetState() == DownloadItem::IN_PROGRESS)
112 if (download->GetState() == DownloadItem::COMPLETE) { 133 ? download->GetFullPath()
113 DCHECK(!download->GetTargetFilePath().empty()); 134 : download->GetTargetFilePath();
114 return download->GetTargetFilePath(); 135
136 case PATH_FOR_TARGET_DETERMINATION:
137 DCHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState());
138 return download->GetTargetFilePath();
115 } 139 }
116 140
117 DCHECK(!download->GetFullPath().empty()); 141 NOTREACHED();
118 return download->GetFullPath(); 142 return base::FilePath();
119 } 143 }
120 144
121 // Callback invoked by DownloadProtectionService::CheckClientDownload. 145 // Callback invoked by DownloadProtectionService::CheckClientDownload.
122 // |is_content_check_supported| is true if the SB service supports scanning the 146 // |is_content_check_supported| is true if the SB service supports scanning the
123 // download for malicious content. 147 // download for malicious content.
124 // |callback| is invoked with a danger type determined as follows: 148 // |callback| is invoked with a danger type determined as follows:
125 // 149 //
126 // Danger type is (in order of preference): 150 // Danger type is (in order of preference):
127 // * DANGEROUS_URL, if the URL is a known malware site. 151 // * DANGEROUS_URL, if the URL is a known malware site.
128 // * MAYBE_DANGEROUS_CONTENT, if the content will be scanned for 152 // * MAYBE_DANGEROUS_CONTENT, if the content will be scanned for
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!profile_->IsOffTheRecord()) 196 if (!profile_->IsOffTheRecord())
173 return DownloadId(this, next_download_id_++); 197 return DownloadId(this, next_download_id_++);
174 198
175 return content::BrowserContext::GetDownloadManager( 199 return content::BrowserContext::GetDownloadManager(
176 profile_->GetOriginalProfile())->GetDelegate()->GetNextId(); 200 profile_->GetOriginalProfile())->GetDelegate()->GetNextId();
177 } 201 }
178 202
179 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( 203 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget(
180 DownloadItem* download, 204 DownloadItem* download,
181 const content::DownloadTargetCallback& callback) { 205 const content::DownloadTargetCallback& callback) {
182 DownloadTargetDeterminer::Start(download, 206 DownloadTargetDeterminer::Start(
183 download_prefs_.get(), 207 download,
184 this, 208 GetPlatformDownloadPath(
185 callback); 209 profile_, download, PATH_FOR_TARGET_DETERMINATION),
210 download_prefs_.get(),
211 this,
212 callback);
186 return true; 213 return true;
187 } 214 }
188 215
189 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( 216 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
190 const base::FilePath& path) { 217 const base::FilePath& path) {
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
192 if (path.Extension().empty()) 219 if (path.Extension().empty())
193 return false; 220 return false;
194 // TODO(asanka): This determination is done based on |path|, while 221 // TODO(asanka): This determination is done based on |path|, while
195 // ShouldOpenDownload() detects extension downloads based on the 222 // ShouldOpenDownload() detects extension downloads based on the
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 default_extension, 351 default_extension,
325 can_save_as_complete, 352 can_save_as_complete,
326 download_prefs_.get(), 353 download_prefs_.get(),
327 callback); 354 callback);
328 } 355 }
329 356
330 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { 357 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) {
331 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); 358 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState());
332 if (!download->CanOpenDownload()) 359 if (!download->CanOpenDownload())
333 return; 360 return;
334 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); 361 base::FilePath platform_path(
362 GetPlatformDownloadPath(profile_, download, PATH_FOR_OPEN));
363 DCHECK(!platform_path.empty());
364 platform_util::OpenItem(platform_path);
335 } 365 }
336 366
337 void ChromeDownloadManagerDelegate::ShowDownloadInShell( 367 void ChromeDownloadManagerDelegate::ShowDownloadInShell(
338 DownloadItem* download) { 368 DownloadItem* download) {
339 if (!download->CanShowInFolder()) 369 if (!download->CanShowInFolder())
340 return; 370 return;
341 platform_util::ShowItemInFolder(GetPlatformDownloadPath(profile_, download)); 371 base::FilePath platform_path(
372 GetPlatformDownloadPath(profile_, download, PATH_FOR_SHOW_IN_FOLDER));
373 DCHECK(!platform_path.empty());
374 platform_util::ShowItemInFolder(platform_path);
342 } 375 }
343 376
344 void ChromeDownloadManagerDelegate::CheckForFileExistence( 377 void ChromeDownloadManagerDelegate::CheckForFileExistence(
345 DownloadItem* download, 378 DownloadItem* download,
346 const content::CheckForFileExistenceCallback& callback) { 379 const content::CheckForFileExistenceCallback& callback) {
347 #if defined(OS_CHROMEOS) 380 #if defined(OS_CHROMEOS)
348 drive::DownloadHandler* drive_download_handler = 381 drive::DownloadHandler* drive_download_handler =
349 drive::DownloadHandler::GetForProfile(profile_); 382 drive::DownloadHandler::GetForProfile(profile_);
350 if (drive_download_handler && 383 if (drive_download_handler &&
351 drive_download_handler->IsDriveDownload(download)) { 384 drive_download_handler->IsDriveDownload(download)) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 registrar_.Remove(this, 545 registrar_.Remove(this,
513 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 546 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
514 source); 547 source);
515 548
516 scoped_refptr<extensions::CrxInstaller> installer = 549 scoped_refptr<extensions::CrxInstaller> installer =
517 content::Source<extensions::CrxInstaller>(source).ptr(); 550 content::Source<extensions::CrxInstaller>(source).ptr();
518 content::DownloadOpenDelayedCallback callback = crx_installers_[installer]; 551 content::DownloadOpenDelayedCallback callback = crx_installers_[installer];
519 crx_installers_.erase(installer.get()); 552 crx_installers_.erase(installer.get());
520 callback.Run(installer->did_handle_successfully()); 553 callback.Run(installer->did_handle_successfully());
521 } 554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698