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

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

Issue 12662032: Merge SavePackageFilePicker{,ChromeOS} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r196175 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/save_package_file_picker_chromeos.h" 5 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/browser/chromeos/drive/download_handler.h" 11 #include "chrome/browser/chromeos/drive/download_handler.h"
12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
13 #include "chrome/browser/platform_util.h" 13 #include "chrome/browser/platform_util.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/chrome_select_file_policy.h" 15 #include "chrome/browser/ui/chrome_select_file_policy.h"
16 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/download_item.h" 17 #include "content/public/browser/download_item.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_view.h" 19 #include "content/public/browser/web_contents_view.h"
19 #include "ui/shell_dialogs/selected_file_info.h" 20 #include "ui/shell_dialogs/selected_file_info.h"
20 21
21 namespace { 22 namespace {
22 23
23 // If false, we don't prompt the user as to where to save the file. This 24 // If false, we don't prompt the user as to where to save the file. This
24 // exists only for testing. 25 // exists only for testing.
25 bool g_should_prompt_for_filename = true; 26 bool g_should_prompt_for_filename = true;
26 27
27 // Trampoline callback between SubstituteDriveDownloadPath() and |callback|. 28 // Trampoline callback between SubstituteDriveDownloadPath() and |callback|.
28 void ContinueSettingUpDriveDownload( 29 void ContinueSettingUpDriveDownload(
29 const content::SavePackagePathPickedCallback& callback, 30 const content::SavePackagePathPickedCallback& callback,
30 bool is_html, 31 content::SavePageType save_type,
31 Profile* profile, 32 Profile* profile,
32 const base::FilePath& drive_path, 33 const base::FilePath& drive_path,
33 const base::FilePath& drive_tmp_download_path) { 34 const base::FilePath& drive_tmp_download_path) {
34 if (drive_tmp_download_path.empty()) // Substitution failed. 35 if (drive_tmp_download_path.empty()) // Substitution failed.
35 return; 36 return;
36 37
37 callback.Run( 38 content::SavePackageDownloadCreatedCallback download_created = base::Bind(
38 drive_tmp_download_path, 39 &drive::DownloadHandler::SetDownloadParams,
39 (is_html ? 40 base::Unretained(drive::DownloadHandler::GetForProfile(profile)),
40 content::SAVE_PAGE_TYPE_AS_MHTML : 41 drive_path);
41 content::SAVE_PAGE_TYPE_AS_ONLY_HTML), 42 callback.Run(drive_tmp_download_path, save_type, download_created);
42 base::Bind(&drive::DownloadHandler::SetDownloadParams,
43 base::Unretained(
44 drive::DownloadHandler::GetForProfile(profile)),
45 drive_path));
46 } 43 }
47 44
48 } // namespace 45 } // namespace
49 46
50 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS( 47 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS(
51 content::WebContents* web_contents, 48 content::WebContents* web_contents,
52 const base::FilePath& suggested_path, 49 const base::FilePath& suggested_path,
53 bool is_html, 50 bool is_html,
51 const base::Callback<void(const base::FilePath&)>& on_chosen,
54 const content::SavePackagePathPickedCallback& callback) 52 const content::SavePackagePathPickedCallback& callback)
55 : content::WebContentsObserver(web_contents), 53 : content::WebContentsObserver(web_contents),
54 on_chosen_(on_chosen),
56 callback_(callback), 55 callback_(callback),
57 is_html_(is_html) { 56 save_type_(is_html ? content::SAVE_PAGE_TYPE_AS_MHTML :
58 base::FilePath suggested_path_copy(is_html_ ? 57 content::SAVE_PAGE_TYPE_AS_ONLY_HTML) {
59 suggested_path.ReplaceExtension("mhtml") : 58 base::FilePath suggested_path_copy(
60 suggested_path); 59 is_html ? suggested_path.ReplaceExtension("mhtml") : suggested_path);
61 if (g_should_prompt_for_filename) { 60 if (g_should_prompt_for_filename) {
62 select_file_dialog_ = ui::SelectFileDialog::Create( 61 select_file_dialog_ = ui::SelectFileDialog::Create(
63 this, new ChromeSelectFilePolicy(web_contents)); 62 this, new ChromeSelectFilePolicy(web_contents));
64 ui::SelectFileDialog::FileTypeInfo file_types; 63 ui::SelectFileDialog::FileTypeInfo file_types;
65 file_types.support_drive = true; 64 file_types.support_drive = true;
66 select_file_dialog_->SelectFile( 65 select_file_dialog_->SelectFile(
67 ui::SelectFileDialog::SELECT_SAVEAS_FILE, 66 ui::SelectFileDialog::SELECT_SAVEAS_FILE,
68 string16(), 67 string16(),
69 suggested_path_copy, 68 suggested_path_copy,
70 &file_types, 69 &file_types,
(...skipping 30 matching lines...) Expand all
101 if (!web_contents()) { 100 if (!web_contents()) {
102 delete this; 101 delete this;
103 return; 102 return;
104 } 103 }
105 base::FilePath selected_path = selected_file_info.file_path; 104 base::FilePath selected_path = selected_file_info.file_path;
106 file_util::NormalizeFileNameEncoding(&selected_path); 105 file_util::NormalizeFileNameEncoding(&selected_path);
107 Profile* profile = Profile::FromBrowserContext( 106 Profile* profile = Profile::FromBrowserContext(
108 web_contents()->GetBrowserContext()); 107 web_contents()->GetBrowserContext());
109 DCHECK(profile); 108 DCHECK(profile);
110 109
110 on_chosen_.Run(selected_path);
111
111 if (drive::util::IsUnderDriveMountPoint(selected_path)) { 112 if (drive::util::IsUnderDriveMountPoint(selected_path)) {
112 // Here's a map to the callback chain: 113 // Here's a map to the callback chain:
113 // SubstituteDriveDownloadPath -> 114 // SubstituteDriveDownloadPath ->
114 // ContinueSettingUpDriveDownload -> 115 // ContinueSettingUpDriveDownload ->
115 // callback_ = SavePackage::OnPathPicked -> 116 // callback_ = SavePackage::OnPathPicked ->
116 // download_created_callback = OnSavePackageDownloadCreated 117 // download_created_callback = OnSavePackageDownloadCreated
117 drive::DownloadHandler* drive_download_handler = 118 drive::DownloadHandler* drive_download_handler =
118 drive::DownloadHandler::GetForProfile(profile); 119 drive::DownloadHandler::GetForProfile(profile);
119 DCHECK(drive_download_handler); 120 DCHECK(drive_download_handler);
120 drive_download_handler-> 121 drive_download_handler->
121 SubstituteDriveDownloadPath(selected_path, NULL, 122 SubstituteDriveDownloadPath(selected_path, NULL,
122 base::Bind(&ContinueSettingUpDriveDownload, 123 base::Bind(&ContinueSettingUpDriveDownload,
123 callback_, 124 callback_,
124 is_html_, 125 save_type_,
125 profile, 126 profile,
126 selected_path)); 127 selected_path));
127 } else { 128 } else {
128 callback_.Run(selected_path, 129 callback_.Run(selected_path,
129 (is_html_ ? 130 save_type_,
130 content::SAVE_PAGE_TYPE_AS_MHTML :
131 content::SAVE_PAGE_TYPE_AS_ONLY_HTML),
132 content::SavePackageDownloadCreatedCallback()); 131 content::SavePackageDownloadCreatedCallback());
133 } 132 }
134 delete this; 133 delete this;
135 } 134 }
136 135
137 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) { 136 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) {
138 delete this; 137 delete this;
139 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698