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

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

Issue 12079097: Introduce PrefRegistrySyncable, simplifying PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more merge to head. Created 7 years, 10 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 16 matching lines...) Expand all
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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 #else 500 #else
500 return false; 501 return false;
501 #endif 502 #endif
502 } 503 }
503 504
504 void ChromeDownloadManagerDelegate::GetSaveDir(BrowserContext* browser_context, 505 void ChromeDownloadManagerDelegate::GetSaveDir(BrowserContext* browser_context,
505 FilePath* website_save_dir, 506 FilePath* website_save_dir,
506 FilePath* download_save_dir, 507 FilePath* download_save_dir,
507 bool* skip_dir_check) { 508 bool* skip_dir_check) {
508 Profile* profile = Profile::FromBrowserContext(browser_context); 509 Profile* profile = Profile::FromBrowserContext(browser_context);
509 PrefServiceSyncable* prefs = profile->GetPrefs(); 510 PrefService* prefs = profile->GetPrefs();
510 511
511 // Check whether the preference has the preferred directory for saving file. 512 // Check whether the preference has the preferred directory for saving file.
512 // If not, initialize it with default directory. 513 // If not, initialize it with default directory.
513 if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) { 514 if (!prefs->FindPreference(prefs::kSaveFileDefaultDirectory)) {
514 DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory)); 515 DCHECK(prefs->FindPreference(prefs::kDownloadDefaultDirectory));
515 FilePath default_save_path = prefs->GetFilePath( 516 FilePath default_save_path = prefs->GetFilePath(
516 prefs::kDownloadDefaultDirectory); 517 prefs::kDownloadDefaultDirectory);
517 prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, 518
518 default_save_path, 519 // TODO(joi): All registration should be done up front.
519 PrefServiceSyncable::UNSYNCABLE_PREF); 520 scoped_refptr<PrefRegistrySyncable> registry(
521 static_cast<PrefRegistrySyncable*>(prefs->DeprecatedGetPrefRegistry()));
522 registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory,
523 default_save_path,
524 PrefRegistrySyncable::UNSYNCABLE_PREF);
520 } 525 }
521 526
522 // Get the directory from preference. 527 // Get the directory from preference.
523 *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory); 528 *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory);
524 DCHECK(!website_save_dir->empty()); 529 DCHECK(!website_save_dir->empty());
525 530
526 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); 531 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory);
527 532
528 *skip_dir_check = false; 533 *skip_dir_check = false;
529 #if defined(OS_CHROMEOS) 534 #if defined(OS_CHROMEOS)
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a 930 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a
926 // directory to persist. Or perhaps, if the Drive path 931 // directory to persist. Or perhaps, if the Drive path
927 // substitution logic is moved here, then we would have a 932 // substitution logic is moved here, then we would have a
928 // persistable path after the DownloadFilePicker is done. 933 // persistable path after the DownloadFilePicker is done.
929 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && 934 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT &&
930 !download->IsTemporary()) 935 !download->IsTemporary())
931 last_download_path_ = target_path.DirName(); 936 last_download_path_ = target_path.DirName();
932 } 937 }
933 callback.Run(target_path, disposition, danger_type, intermediate_path); 938 callback.Run(target_path, disposition, danger_type, intermediate_path);
934 } 939 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698