| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/save_package.h" | 5 #include "chrome/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 g_should_prompt_for_filename = should_prompt; | 956 g_should_prompt_for_filename = should_prompt; |
| 957 } | 957 } |
| 958 | 958 |
| 959 // static | 959 // static |
| 960 FilePath SavePackage::GetSuggestNameForSaveAs(PrefService* prefs, | 960 FilePath SavePackage::GetSuggestNameForSaveAs(PrefService* prefs, |
| 961 const FilePath& name) { | 961 const FilePath& name) { |
| 962 // Check whether the preference has the preferred directory for saving file. | 962 // Check whether the preference has the preferred directory for saving file. |
| 963 // If not, initialize it with default directory. | 963 // If not, initialize it with default directory. |
| 964 if (!prefs->IsPrefRegistered(prefs::kSaveFileDefaultDirectory)) { | 964 if (!prefs->IsPrefRegistered(prefs::kSaveFileDefaultDirectory)) { |
| 965 FilePath default_save_path; | 965 FilePath default_save_path; |
| 966 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, | 966 if (!prefs->IsPrefRegistered(prefs::kDownloadDefaultDirectory)) { |
| 967 &default_save_path)) | 967 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 968 NOTREACHED(); | 968 &default_save_path)) { |
| 969 NOTREACHED(); |
| 970 } |
| 971 } else { |
| 972 StringPrefMember default_download_path; |
| 973 default_download_path.Init(prefs::kDownloadDefaultDirectory, |
| 974 prefs, NULL); |
| 975 default_save_path = FilePath::FromWStringHack( |
| 976 default_download_path.GetValue()); |
| 977 } |
| 969 prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, | 978 prefs->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, |
| 970 default_save_path); | 979 default_save_path); |
| 971 } | 980 } |
| 972 | 981 |
| 973 // Get the directory from preference. | 982 // Get the directory from preference. |
| 974 StringPrefMember save_file_path; | 983 StringPrefMember save_file_path; |
| 975 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); | 984 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); |
| 976 DCHECK(!(*save_file_path).empty()); | 985 DCHECK(!(*save_file_path).empty()); |
| 977 | 986 |
| 978 // Ask user for getting final saving name. | 987 // Ask user for getting final saving name. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 if (available_length > 0) { | 1112 if (available_length > 0) { |
| 1104 *pure_file_name = | 1113 *pure_file_name = |
| 1105 pure_file_name->substr(0, available_length); | 1114 pure_file_name->substr(0, available_length); |
| 1106 return true; | 1115 return true; |
| 1107 } | 1116 } |
| 1108 | 1117 |
| 1109 // Not enough room to even use a shortened |pure_file_name|. | 1118 // Not enough room to even use a shortened |pure_file_name|. |
| 1110 pure_file_name->clear(); | 1119 pure_file_name->clear(); |
| 1111 return false; | 1120 return false; |
| 1112 } | 1121 } |
| OLD | NEW |