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

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

Issue 12850002: Move download filename determintion into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/download_file_picker.h" 5 #include "chrome/browser/download/download_file_picker.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/download/download_prefs.h" 8 #include "chrome/browser/download/download_prefs.h"
9 #include "chrome/browser/platform_util.h" 9 #include "chrome/browser/platform_util.h"
10 #include "chrome/browser/ui/chrome_select_file_policy.h" 10 #include "chrome/browser/ui/chrome_select_file_policy.h"
11 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/download_item.h" 12 #include "content/public/browser/download_item.h"
12 #include "content/public/browser/download_manager.h" 13 #include "content/public/browser/download_manager.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_view.h" 15 #include "content/public/browser/web_contents_view.h"
15 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 18
18 using content::DownloadItem; 19 using content::DownloadItem;
19 using content::DownloadManager; 20 using content::DownloadManager;
20 using content::WebContents; 21 using content::WebContents;
(...skipping 28 matching lines...) Expand all
49 const base::FilePath& actual_path) { 50 const base::FilePath& actual_path) {
50 if (suggested_path == actual_path) 51 if (suggested_path == actual_path)
51 return FILE_PICKER_SAME; 52 return FILE_PICKER_SAME;
52 if (suggested_path.DirName() != actual_path.DirName()) 53 if (suggested_path.DirName() != actual_path.DirName())
53 return FILE_PICKER_DIFFERENT_DIR; 54 return FILE_PICKER_DIFFERENT_DIR;
54 return FILE_PICKER_DIFFERENT_NAME; 55 return FILE_PICKER_DIFFERENT_NAME;
55 } 56 }
56 57
57 } // namespace 58 } // namespace
58 59
59 DownloadFilePicker::DownloadFilePicker() : download_id_(0) { 60 DownloadFilePicker::DownloadFilePicker(
60 }
61
62 void DownloadFilePicker::Init(
63 DownloadManager* download_manager,
64 DownloadItem* item, 61 DownloadItem* item,
65 const base::FilePath& suggested_path, 62 const base::FilePath& suggested_path,
66 const ChromeDownloadManagerDelegate::FileSelectedCallback& callback) { 63 const FileSelectedCallback& callback) : download_id_(0) {
benjhayden 2013/04/09 15:46:32 Why not download_id_(item->GetId())?
asanka 2013/04/16 20:34:01 Done.
67 download_manager_ = download_manager; 64 download_manager_ =
65 content::BrowserContext::GetDownloadManager(item->GetBrowserContext());
68 download_id_ = item->GetId(); 66 download_id_ = item->GetId();
69 file_selected_callback_ = callback; 67 file_selected_callback_ = callback;
70 InitSuggestedPath(item, suggested_path); 68 InitSuggestedPath(item, suggested_path);
71 69
72 DCHECK(download_manager_); 70 DCHECK(download_manager_);
73 WebContents* web_contents = item->GetWebContents(); 71 WebContents* web_contents = item->GetWebContents();
74 select_file_dialog_ = ui::SelectFileDialog::Create( 72 select_file_dialog_ = ui::SelectFileDialog::Create(
75 this, new ChromeSelectFilePolicy(web_contents)); 73 this, new ChromeSelectFilePolicy(web_contents));
76 ui::SelectFileDialog::FileTypeInfo file_type_info; 74 ui::SelectFileDialog::FileTypeInfo file_type_info;
77 base::FilePath::StringType extension = suggested_path_.Extension(); 75 base::FilePath::StringType extension = suggested_path_.Extension();
(...skipping 21 matching lines...) Expand all
99 97
100 DownloadFilePicker::~DownloadFilePicker() { 98 DownloadFilePicker::~DownloadFilePicker() {
101 } 99 }
102 100
103 void DownloadFilePicker::InitSuggestedPath( 101 void DownloadFilePicker::InitSuggestedPath(
104 DownloadItem* item, 102 DownloadItem* item,
105 const base::FilePath& suggested_path) { 103 const base::FilePath& suggested_path) {
106 set_suggested_path(suggested_path); 104 set_suggested_path(suggested_path);
107 } 105 }
108 106
109 void DownloadFilePicker::OnFileSelected(const base::FilePath& path) { 107 void DownloadFilePicker::OnFileSelected(const base::FilePath& virtual_path,
110 file_selected_callback_.Run(path); 108 const base::FilePath& local_path) {
109 file_selected_callback_.Run(virtual_path, local_path);
111 delete this; 110 delete this;
112 } 111 }
113 112
114 void DownloadFilePicker::RecordFileSelected(const base::FilePath& path) { 113 void DownloadFilePicker::RecordFileSelected(const base::FilePath& path) {
115 FilePickerResult result = ComparePaths(suggested_path_, path); 114 FilePickerResult result = ComparePaths(suggested_path_, path);
116 RecordFilePickerResult(download_manager_, result); 115 RecordFilePickerResult(download_manager_, result);
117 } 116 }
118 117
119 void DownloadFilePicker::FileSelected(const base::FilePath& path, 118 void DownloadFilePicker::FileSelected(const base::FilePath& path,
120 int index, 119 int index,
121 void* params) { 120 void* params) {
122 RecordFileSelected(path); 121 RecordFileSelected(path);
123 OnFileSelected(path); 122 OnFileSelected(path, path);
124 // Deletes |this| 123 // Deletes |this|
125 } 124 }
126 125
127 void DownloadFilePicker::FileSelectionCanceled(void* params) { 126 void DownloadFilePicker::FileSelectionCanceled(void* params) {
128 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); 127 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL);
129 OnFileSelected(base::FilePath()); 128 OnFileSelected(base::FilePath(), base::FilePath());
130 // Deletes |this| 129 // Deletes |this|
131 } 130 }
131
132 #if !defined(OS_CHROMEOS)
133 // static
134 void DownloadFilePicker::ShowFilePicker(DownloadItem* item,
135 const base::FilePath& suggested_path,
136 const FileSelectedCallback& callback) {
137 new DownloadFilePicker(item, suggested_path, callback);
138 // DownloadFilePicker deletes itself.
139 }
140 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698