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

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

Issue 3043048: Clean up download code: (Closed)
Patch Set: Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/i18n/file_util_icu.h" 10 #include "base/i18n/file_util_icu.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/thread.h" 17 #include "base/thread.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_thread.h" 19 #include "chrome/browser/chrome_thread.h"
20 #include "chrome/browser/download/download_item.h" 20 #include "chrome/browser/download/download_item.h"
21 #include "chrome/browser/download/download_item_model.h" 21 #include "chrome/browser/download/download_item_model.h"
22 #include "chrome/browser/download/download_manager.h" 22 #include "chrome/browser/download/download_manager.h"
23 #include "chrome/browser/download/download_shelf.h" 23 #include "chrome/browser/download/download_shelf.h"
24 #include "chrome/browser/download/download_util.h"
24 #include "chrome/browser/download/save_file.h" 25 #include "chrome/browser/download/save_file.h"
25 #include "chrome/browser/download/save_file_manager.h" 26 #include "chrome/browser/download/save_file_manager.h"
26 #include "chrome/browser/download/save_item.h" 27 #include "chrome/browser/download/save_item.h"
27 #include "chrome/browser/platform_util.h" 28 #include "chrome/browser/platform_util.h"
28 #include "chrome/browser/pref_service.h" 29 #include "chrome/browser/pref_service.h"
29 #include "chrome/browser/profile.h" 30 #include "chrome/browser/profile.h"
30 #include "chrome/browser/renderer_host/render_process_host.h" 31 #include "chrome/browser/renderer_host/render_process_host.h"
31 #include "chrome/browser/renderer_host/render_view_host.h" 32 #include "chrome/browser/renderer_host/render_view_host.h"
32 #include "chrome/browser/renderer_host/render_view_host_delegate.h" 33 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
33 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 34 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 delete save_params; 1302 delete save_params;
1302 } 1303 }
1303 } 1304 }
1304 1305
1305 // Called after the save file dialog box returns. 1306 // Called after the save file dialog box returns.
1306 void SavePackage::ContinueSave(SavePackageParam* param, 1307 void SavePackage::ContinueSave(SavePackageParam* param,
1307 const FilePath& final_name, 1308 const FilePath& final_name,
1308 int index) { 1309 int index) {
1309 // Ensure the filename is safe. 1310 // Ensure the filename is safe.
1310 param->saved_main_file_path = final_name; 1311 param->saved_main_file_path = final_name;
1311 DownloadManager* dlm = tab_contents_->profile()->GetDownloadManager(); 1312 download_util::GenerateSafeFileName(param->current_tab_mime_type,
1312 DCHECK(dlm); 1313 &param->saved_main_file_path);
1313 dlm->GenerateSafeFileName(param->current_tab_mime_type,
1314 &param->saved_main_file_path);
1315 1314
1316 // The option index is not zero-based. 1315 // The option index is not zero-based.
1317 DCHECK(index > 0 && index < 3); 1316 DCHECK(index > 0 && index < 3);
1318 param->dir = param->saved_main_file_path.DirName(); 1317 param->dir = param->saved_main_file_path.DirName();
1319 1318
1320 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 1319 PrefService* prefs = tab_contents_->profile()->GetPrefs();
1321 StringPrefMember save_file_path; 1320 StringPrefMember save_file_path;
1322 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); 1321 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL);
1323 #if defined(OS_POSIX) 1322 #if defined(OS_POSIX)
1324 std::string path_string = param->dir.value(); 1323 std::string path_string = param->dir.value();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 int index, void* params) { 1375 int index, void* params) {
1377 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); 1376 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params);
1378 ContinueSave(save_params, path, index); 1377 ContinueSave(save_params, path, index);
1379 delete save_params; 1378 delete save_params;
1380 } 1379 }
1381 1380
1382 void SavePackage::FileSelectionCanceled(void* params) { 1381 void SavePackage::FileSelectionCanceled(void* params) {
1383 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); 1382 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params);
1384 delete save_params; 1383 delete save_params;
1385 } 1384 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util_unittest.cc ('k') | chrome/browser/gtk/tab_contents_drag_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698