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

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

Issue 12662032: Merge SavePackageFilePicker{,ChromeOS} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r202870 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 26 matching lines...) Expand all
37 #include "chrome/common/extensions/extension.h" 37 #include "chrome/common/extensions/extension.h"
38 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
39 #include "components/user_prefs/pref_registry_syncable.h" 39 #include "components/user_prefs/pref_registry_syncable.h"
40 #include "content/public/browser/download_item.h" 40 #include "content/public/browser/download_item.h"
41 #include "content/public/browser/download_manager.h" 41 #include "content/public/browser/download_manager.h"
42 #include "content/public/browser/notification_source.h" 42 #include "content/public/browser/notification_source.h"
43 43
44 #if defined(OS_CHROMEOS) 44 #if defined(OS_CHROMEOS)
45 #include "chrome/browser/chromeos/drive/download_handler.h" 45 #include "chrome/browser/chromeos/drive/download_handler.h"
46 #include "chrome/browser/chromeos/drive/file_system_util.h" 46 #include "chrome/browser/chromeos/drive/file_system_util.h"
47 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
48 #endif 47 #endif
49 48
50 using content::BrowserContext;
51 using content::BrowserThread; 49 using content::BrowserThread;
52 using content::DownloadId; 50 using content::DownloadId;
53 using content::DownloadItem; 51 using content::DownloadItem;
54 using content::DownloadManager; 52 using content::DownloadManager;
55 using safe_browsing::DownloadProtectionService; 53 using safe_browsing::DownloadProtectionService;
56 54
57 namespace { 55 namespace {
58 56
59 // String pointer used for identifying safebrowing data associated with 57 // String pointer used for identifying safebrowing data associated with
60 // a download item. 58 // a download item.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } else { 144 } else {
147 // If the URL is malicious, we'll use that as the danger type. The results 145 // If the URL is malicious, we'll use that as the danger type. The results
148 // of the content check, if one is performed, will be ignored. 146 // of the content check, if one is performed, will be ignored.
149 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; 147 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL;
150 } 148 }
151 callback.Run(danger_type); 149 callback.Run(danger_type);
152 } 150 }
153 151
154 } // namespace 152 } // namespace
155 153
156 // static
157 void ChromeDownloadManagerDelegate::RegisterUserPrefs(
158 user_prefs::PrefRegistrySyncable* registry) {
159 const base::FilePath& default_download_path =
160 download_util::GetDefaultDownloadDirectory();
161 registry->RegisterFilePathPref(
162 prefs::kSaveFileDefaultDirectory,
163 default_download_path,
164 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
165 }
166
167 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) 154 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
168 : profile_(profile), 155 : profile_(profile),
169 next_download_id_(0), 156 next_download_id_(0),
170 download_prefs_(new DownloadPrefs(profile)) { 157 download_prefs_(new DownloadPrefs(profile)) {
171 } 158 }
172 159
173 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { 160 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
174 } 161 }
175 162
176 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { 163 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
177 download_manager_ = dm; 164 download_manager_ = dm;
178 } 165 }
179 166
180 void ChromeDownloadManagerDelegate::Shutdown() { 167 void ChromeDownloadManagerDelegate::Shutdown() {
181 download_prefs_.reset(); 168 download_prefs_.reset();
182 } 169 }
183 170
184 DownloadId ChromeDownloadManagerDelegate::GetNextId() { 171 DownloadId ChromeDownloadManagerDelegate::GetNextId() {
185 if (!profile_->IsOffTheRecord()) 172 if (!profile_->IsOffTheRecord())
186 return DownloadId(this, next_download_id_++); 173 return DownloadId(this, next_download_id_++);
187 174
188 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> 175 return content::BrowserContext::GetDownloadManager(
189 GetDelegate()->GetNextId(); 176 profile_->GetOriginalProfile())->GetDelegate()->GetNextId();
190 } 177 }
191 178
192 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( 179 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget(
193 DownloadItem* download, 180 DownloadItem* download,
194 const content::DownloadTargetCallback& callback) { 181 const content::DownloadTargetCallback& callback) {
195 DownloadTargetDeterminer::Start(download, 182 DownloadTargetDeterminer::Start(download,
196 download_prefs_.get(), 183 download_prefs_.get(),
197 last_download_path_,
198 this, 184 this,
199 callback); 185 callback);
200 return true; 186 return true;
201 } 187 }
202 188
203 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( 189 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
204 const base::FilePath& path) { 190 const base::FilePath& path) {
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
206 if (path.Extension().empty()) 192 if (path.Extension().empty())
207 return false; 193 return false;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 bool ChromeDownloadManagerDelegate::GenerateFileHash() { 291 bool ChromeDownloadManagerDelegate::GenerateFileHash() {
306 #if defined(FULL_SAFE_BROWSING) 292 #if defined(FULL_SAFE_BROWSING)
307 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && 293 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
308 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); 294 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded();
309 #else 295 #else
310 return false; 296 return false;
311 #endif 297 #endif
312 } 298 }
313 299
314 void ChromeDownloadManagerDelegate::GetSaveDir( 300 void ChromeDownloadManagerDelegate::GetSaveDir(
315 BrowserContext* browser_context, 301 content::BrowserContext* browser_context,
316 base::FilePath* website_save_dir, 302 base::FilePath* website_save_dir,
317 base::FilePath* download_save_dir, 303 base::FilePath* download_save_dir,
318 bool* skip_dir_check) { 304 bool* skip_dir_check) {
319 Profile* profile = Profile::FromBrowserContext(browser_context); 305 *website_save_dir = download_prefs_->SaveFilePath();
320 PrefService* prefs = profile->GetPrefs();
321
322 // Check whether the preference for the preferred directory for
323 // saving file has been explicitly set. If not, and the preference
324 // for the default download directory has been set, initialize it
325 // with the latter. Note that the defaults for both are the same.
326 const PrefService::Preference* download_default_directory =
327 prefs->FindPreference(prefs::kDownloadDefaultDirectory);
328 if (!download_default_directory->IsDefaultValue() &&
329 prefs->FindPreference(
330 prefs::kSaveFileDefaultDirectory)->IsDefaultValue()) {
331 prefs->Set(prefs::kSaveFileDefaultDirectory,
332 *(download_default_directory->GetValue()));
333 }
334
335 // Get the directory from preference.
336 *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory);
337 DCHECK(!website_save_dir->empty()); 306 DCHECK(!website_save_dir->empty());
338 307 *download_save_dir = download_prefs_->DownloadPath();
339 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory);
340
341 *skip_dir_check = false; 308 *skip_dir_check = false;
342 #if defined(OS_CHROMEOS) 309 #if defined(OS_CHROMEOS)
343 *skip_dir_check = drive::util::IsUnderDriveMountPoint(*website_save_dir); 310 *skip_dir_check = drive::util::IsUnderDriveMountPoint(*website_save_dir);
344 #endif 311 #endif
345 } 312 }
346 313
347 void ChromeDownloadManagerDelegate::ChooseSavePath( 314 void ChromeDownloadManagerDelegate::ChooseSavePath(
348 content::WebContents* web_contents, 315 content::WebContents* web_contents,
349 const base::FilePath& suggested_path, 316 const base::FilePath& suggested_path,
350 const base::FilePath::StringType& default_extension, 317 const base::FilePath::StringType& default_extension,
351 bool can_save_as_complete, 318 bool can_save_as_complete,
352 const content::SavePackagePathPickedCallback& callback) { 319 const content::SavePackagePathPickedCallback& callback) {
353 // Deletes itself. 320 // Deletes itself.
354 #if defined(OS_CHROMEOS)
355 new SavePackageFilePickerChromeOS(
356 web_contents,
357 suggested_path,
358 can_save_as_complete,
359 callback);
360 #else
361 new SavePackageFilePicker( 321 new SavePackageFilePicker(
362 web_contents, 322 web_contents,
363 suggested_path, 323 suggested_path,
364 default_extension, 324 default_extension,
365 can_save_as_complete, 325 can_save_as_complete,
366 download_prefs_.get(), 326 download_prefs_.get(),
367 callback); 327 callback);
368 #endif
369 } 328 }
370 329
371 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { 330 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) {
372 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); 331 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState());
373 if (!download->CanOpenDownload()) 332 if (!download->CanOpenDownload())
374 return; 333 return;
375 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); 334 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download));
376 } 335 }
377 336
378 void ChromeDownloadManagerDelegate::ShowDownloadInShell( 337 void ChromeDownloadManagerDelegate::ShowDownloadInShell(
(...skipping 14 matching lines...) Expand all
393 drive_download_handler->CheckForFileExistence(download, callback); 352 drive_download_handler->CheckForFileExistence(download, callback);
394 return; 353 return;
395 } 354 }
396 #endif 355 #endif
397 BrowserThread::PostTaskAndReplyWithResult( 356 BrowserThread::PostTaskAndReplyWithResult(
398 BrowserThread::FILE, FROM_HERE, 357 BrowserThread::FILE, FROM_HERE,
399 base::Bind(&file_util::PathExists, download->GetTargetFilePath()), 358 base::Bind(&file_util::PathExists, download->GetTargetFilePath()),
400 callback); 359 callback);
401 } 360 }
402 361
403 void ChromeDownloadManagerDelegate::ClearLastDownloadPath() {
404 last_download_path_.clear();
405 }
406
407 DownloadProtectionService* 362 DownloadProtectionService*
408 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { 363 ChromeDownloadManagerDelegate::GetDownloadProtectionService() {
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
410 #if defined(FULL_SAFE_BROWSING) 365 #if defined(FULL_SAFE_BROWSING)
411 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 366 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
412 if (sb_service && sb_service->download_protection_service() && 367 if (sb_service && sb_service->download_protection_service() &&
413 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { 368 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) {
414 return sb_service->download_protection_service(); 369 return sb_service->download_protection_service();
415 } 370 }
416 #endif 371 #endif
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 DownloadPathReservationTracker::GetReservedPath( 413 DownloadPathReservationTracker::GetReservedPath(
459 *download, virtual_path, download_prefs_->DownloadPath(), 414 *download, virtual_path, download_prefs_->DownloadPath(),
460 create_directory, conflict_action, callback); 415 create_directory, conflict_action, callback);
461 } 416 }
462 417
463 void ChromeDownloadManagerDelegate::PromptUserForDownloadPath( 418 void ChromeDownloadManagerDelegate::PromptUserForDownloadPath(
464 DownloadItem* download, 419 DownloadItem* download,
465 const base::FilePath& suggested_path, 420 const base::FilePath& suggested_path,
466 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { 421 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
468 DownloadFilePicker::ShowFilePicker( 423 DownloadFilePicker::ShowFilePicker(download, suggested_path, callback);
469 download,
470 suggested_path,
471 base::Bind(&ChromeDownloadManagerDelegate::OnDownloadPathSelected,
472 this,
473 callback));
474 }
475
476 void ChromeDownloadManagerDelegate::OnDownloadPathSelected(
477 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback,
478 const base::FilePath& virtual_path) {
479 if (!virtual_path.empty())
480 last_download_path_ = virtual_path.DirName();
481 callback.Run(virtual_path);
482 } 424 }
483 425
484 void ChromeDownloadManagerDelegate::DetermineLocalPath( 426 void ChromeDownloadManagerDelegate::DetermineLocalPath(
485 DownloadItem* download, 427 DownloadItem* download,
486 const base::FilePath& virtual_path, 428 const base::FilePath& virtual_path,
487 const DownloadTargetDeterminerDelegate::LocalPathCallback& callback) { 429 const DownloadTargetDeterminerDelegate::LocalPathCallback& callback) {
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
489 #if defined(OS_CHROMEOS) 431 #if defined(OS_CHROMEOS)
490 drive::DownloadHandler* drive_download_handler = 432 drive::DownloadHandler* drive_download_handler =
491 drive::DownloadHandler::GetForProfile(profile_); 433 drive::DownloadHandler::GetForProfile(profile_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 registrar_.Remove(this, 512 registrar_.Remove(this,
571 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 513 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
572 source); 514 source);
573 515
574 scoped_refptr<extensions::CrxInstaller> installer = 516 scoped_refptr<extensions::CrxInstaller> installer =
575 content::Source<extensions::CrxInstaller>(source).ptr(); 517 content::Source<extensions::CrxInstaller>(source).ptr();
576 content::DownloadOpenDelayedCallback callback = crx_installers_[installer]; 518 content::DownloadOpenDelayedCallback callback = crx_installers_[installer];
577 crx_installers_.erase(installer.get()); 519 crx_installers_.erase(installer.get());
578 callback.Run(installer->did_handle_successfully()); 520 callback.Run(installer->did_handle_successfully());
579 } 521 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698