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 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/download/download_util.h" | 27 #include "chrome/browser/download/download_util.h" |
28 #include "chrome/browser/download/save_package_file_picker.h" | 28 #include "chrome/browser/download/save_package_file_picker.h" |
29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
30 #include "chrome/browser/extensions/crx_installer.h" | 30 #include "chrome/browser/extensions/crx_installer.h" |
31 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
32 #include "chrome/browser/extensions/extension_system.h" | 32 #include "chrome/browser/extensions/extension_system.h" |
33 #include "chrome/browser/history/history_service.h" | 33 #include "chrome/browser/history/history_service.h" |
34 #include "chrome/browser/history/history_service_factory.h" | 34 #include "chrome/browser/history/history_service_factory.h" |
35 #include "chrome/browser/intents/web_intents_util.h" | 35 #include "chrome/browser/intents/web_intents_util.h" |
36 #include "chrome/browser/platform_util.h" | 36 #include "chrome/browser/platform_util.h" |
| 37 #include "chrome/browser/prefs/pref_registry_syncable.h" |
37 #include "chrome/browser/prefs/pref_service.h" | 38 #include "chrome/browser/prefs/pref_service.h" |
38 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 40 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
40 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
41 #include "chrome/browser/ui/host_desktop.h" | 42 #include "chrome/browser/ui/host_desktop.h" |
42 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 43 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
43 #include "chrome/common/chrome_notification_types.h" | 44 #include "chrome/common/chrome_notification_types.h" |
44 #include "chrome/common/extensions/feature_switch.h" | 45 #include "chrome/common/extensions/feature_switch.h" |
45 #include "chrome/common/extensions/user_script.h" | 46 #include "chrome/common/extensions/user_script.h" |
46 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 #else | 484 #else |
484 return false; | 485 return false; |
485 #endif | 486 #endif |
486 } | 487 } |
487 | 488 |
488 void ChromeDownloadManagerDelegate::GetSaveDir(BrowserContext* browser_context, | 489 void ChromeDownloadManagerDelegate::GetSaveDir(BrowserContext* browser_context, |
489 FilePath* website_save_dir, | 490 FilePath* website_save_dir, |
490 FilePath* download_save_dir, | 491 FilePath* download_save_dir, |
491 bool* skip_dir_check) { | 492 bool* skip_dir_check) { |
492 Profile* profile = Profile::FromBrowserContext(browser_context); | 493 Profile* profile = Profile::FromBrowserContext(browser_context); |
493 PrefServiceSyncable* prefs = profile->GetPrefs(); | 494 PrefService* prefs = profile->GetPrefs(); |
494 | 495 |
495 // Check whether the preference has the preferred directory for saving file. | 496 // Check whether the preference has the preferred directory for saving file. |
496 // If not, initialize it with default directory. | 497 // If not, initialize it with default directory. |
497 if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) { | 498 if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) { |
498 DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory)); | 499 DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory)); |
499 FilePath default_save_path = prefs->GetFilePath( | 500 FilePath default_save_path = prefs->GetFilePath( |
500 prefs::kDownloadDefaultDirectory); | 501 prefs::kDownloadDefaultDirectory); |
501 prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, | 502 |
502 default_save_path, | 503 // TODO(joi): All registration should be done up front. |
503 PrefServiceSyncable::UNSYNCABLE_PREF); | 504 scoped_refptr<PrefRegistrySyncable> registry( |
| 505 static_cast<PrefRegistrySyncable*>(prefs->DeprecatedGetPrefRegistry())); |
| 506 registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, |
| 507 default_save_path, |
| 508 PrefRegistrySyncable::UNSYNCABLE_PREF); |
504 } | 509 } |
505 | 510 |
506 // Get the directory from preference. | 511 // Get the directory from preference. |
507 *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory); | 512 *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory); |
508 DCHECK(!website_save_dir->empty()); | 513 DCHECK(!website_save_dir->empty()); |
509 | 514 |
510 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); | 515 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); |
511 | 516 |
512 *skip_dir_check = false; | 517 *skip_dir_check = false; |
513 #if defined(OS_CHROMEOS) | 518 #if defined(OS_CHROMEOS) |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a | 905 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a |
901 // directory to persist. Or perhaps, if the Drive path | 906 // directory to persist. Or perhaps, if the Drive path |
902 // substitution logic is moved here, then we would have a | 907 // substitution logic is moved here, then we would have a |
903 // persistable path after the DownloadFilePicker is done. | 908 // persistable path after the DownloadFilePicker is done. |
904 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && | 909 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && |
905 !download->IsTemporary()) | 910 !download->IsTemporary()) |
906 last_download_path_ = target_path.DirName(); | 911 last_download_path_ = target_path.DirName(); |
907 } | 912 } |
908 callback.Run(target_path, disposition, danger_type, intermediate_path); | 913 callback.Run(target_path, disposition, danger_type, intermediate_path); |
909 } | 914 } |
OLD | NEW |