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

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

Issue 10069014: Save Page As MHTML (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nonconst nonref params Created 8 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/gdata/gdata_download_observer.h" 11 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
12 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 12 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
13 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 13 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
14 #include "chrome/browser/chromeos/gdata/gdata_util.h" 14 #include "chrome/browser/chromeos/gdata/gdata_util.h"
15 #include "chrome/browser/platform_util.h" 15 #include "chrome/browser/platform_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/download_item.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 20
20 using content::BrowserThread; 21 namespace {
22
23 void OnSavePackageDownloadCreated(
achuithb 2012/04/24 22:06:09 Could you add a function comment explaining that w
benjhayden 2012/04/26 15:05:57 Done.
24 const FilePath& true_path,
achuithb 2012/04/24 22:06:09 Could we call this gdata_path instead?
benjhayden 2012/04/26 15:05:57 Done.
25 content::DownloadItem* download) {
26 gdata::GDataDownloadObserver::SetGDataPath(download, true_path);
27 download->SetDisplayName(true_path.BaseName());
28 download->SetIsTemporary(true);
29 }
30
31 void ContinueSettingUpGDataDownload(
achuithb 2012/04/24 22:06:09 Function comment please.
benjhayden 2012/04/26 15:05:57 Done.
32 content::SaveFilePathPickedCallback callback,
33 FilePath* gdata_tmp_download_path,
34 const FilePath& true_path) {
35 callback.Run(*gdata_tmp_download_path, content::SAVE_PAGE_TYPE_AS_MHTML,
36 base::Bind(&OnSavePackageDownloadCreated, true_path));
37 }
38
39 } // anonymous namespace
21 40
22 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS( 41 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS(
23 content::WebContents* web_contents, 42 content::WebContents* web_contents,
24 const FilePath& suggested_path) 43 const FilePath& suggested_path,
25 : content::WebContentsObserver(web_contents) { 44 content::SaveFilePathPickedCallback callback)
45 : content::WebContentsObserver(web_contents),
46 callback_(callback) {
26 select_file_dialog_ = SelectFileDialog::Create(this); 47 select_file_dialog_ = SelectFileDialog::Create(this);
27 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, 48 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE,
28 string16(), 49 string16(),
29 suggested_path.ReplaceExtension("mhtml"), 50 suggested_path.ReplaceExtension("mhtml"),
30 NULL, 51 NULL,
31 0, 52 0,
32 "mhtml", 53 "mhtml",
33 web_contents, 54 web_contents,
34 platform_util::GetTopLevel( 55 platform_util::GetTopLevel(
35 web_contents->GetNativeView()), 56 web_contents->GetNativeView()),
36 NULL); 57 NULL);
37 } 58 }
38 59
39 SavePackageFilePickerChromeOS::~SavePackageFilePickerChromeOS() { 60 SavePackageFilePickerChromeOS::~SavePackageFilePickerChromeOS() {
40 } 61 }
41 62
42 void SavePackageFilePickerChromeOS::FileSelected(const FilePath& selected_path, 63 void SavePackageFilePickerChromeOS::FileSelected(
43 int index, 64 const FilePath& selected_path_const,
44 void* params) { 65 int index,
66 void* params) {
45 if (!web_contents()) { 67 if (!web_contents()) {
46 delete this; 68 delete this;
47 return; 69 return;
48 } 70 }
49 71 FilePath selected_path = selected_path_const;
50 FilePath path = selected_path; 72 file_util::NormalizeFileNameEncoding(&selected_path);
51 file_util::NormalizeFileNameEncoding(&path); 73 gdata::GDataSystemService* system_service =
52 74 gdata::GDataSystemServiceFactory::GetForProfile(
53 gdata::GDataFileSystem* gdata_filesystem = GetGDataFileSystem(); 75 ProfileManager::GetDefaultProfile());
54 if (gdata_filesystem && gdata::util::IsUnderGDataMountPoint(path)) { 76 if (system_service && gdata::util::IsUnderGDataMountPoint(selected_path)) {
55 FilePath gdata_tmp_download_dir = 77 // GetGDataTempDownloadPath ->
achuithb 2012/04/24 22:06:09 This is a bit cryptic. A line explaining that this
benjhayden 2012/04/26 15:05:57 Done.
56 gdata_filesystem->GetCacheDirectoryPath( 78 // ContinueSettingUpGDataDownload ->
57 gdata::GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS); 79 // SavePackage::OnPathPicked ->
58 80 // download_created_callback ->
59 selected_path_ = path; 81 // OnSavePackageDownloadCreated
60 FilePath* gdata_tmp_download_path = new FilePath(); 82 const FilePath gdata_tmp_download_dir =
61 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, 83 system_service->file_system()->GetGDataTempDownloadFolderPath();
84 FilePath* gdata_tmp_download_path(new FilePath());
85 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
62 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath, 86 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath,
63 gdata_tmp_download_dir, 87 gdata_tmp_download_dir,
64 gdata_tmp_download_path), 88 gdata_tmp_download_path),
65 base::Bind(&SavePackageFilePickerChromeOS::GenerateMHTML, 89 base::Bind(&ContinueSettingUpGDataDownload,
66 base::Unretained(this), 90 callback_,
67 base::Owned(gdata_tmp_download_path))); 91 base::Owned(gdata_tmp_download_path),
92 selected_path));
68 } else { 93 } else {
69 DVLOG(1) << "SavePackageFilePickerChromeOS non-gdata file"; 94 callback_.Run(selected_path, content::SAVE_PAGE_TYPE_AS_MHTML,
70 GenerateMHTML(&path); 95 content::SaveFileDownloadCreatedCallback());
71 } 96 }
97 delete this;
72 } 98 }
73 99
74 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) { 100 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) {
75 delete this; 101 delete this;
76 } 102 }
77
78 void SavePackageFilePickerChromeOS::GenerateMHTML(const FilePath* mhtml_path) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
80 if (!web_contents()) {
81 delete this;
82 return;
83 }
84
85 DVLOG(1) << "GenerateMHTML " << mhtml_path->value();
86 web_contents()->GenerateMHTML(*mhtml_path,
87 base::Bind(&SavePackageFilePickerChromeOS::OnMHTMLGenerated,
88 base::Unretained(this)));
89 }
90
91 void SavePackageFilePickerChromeOS::OnMHTMLGenerated(const FilePath& src_path,
92 int64 file_size) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
94 if (!web_contents()) {
95 delete this;
96 return;
97 }
98
99 gdata::GDataFileSystem* gdata_filesystem = GetGDataFileSystem();
100 if (gdata_filesystem && !selected_path_.empty()) {
101 DVLOG(1) << "TransferFile from " << src_path.value()
102 << " to " << selected_path_.value();
103 gdata_filesystem->TransferFile(src_path,
104 gdata::util::ExtractGDataPath(selected_path_),
105 base::Bind(&SavePackageFilePickerChromeOS::OnTransferFile,
106 base::Unretained(this)));
107 } else {
108 delete this;
109 }
110 }
111
112 void SavePackageFilePickerChromeOS::OnTransferFile(
113 base::PlatformFileError error) {
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
115 DCHECK_EQ(error, base::PLATFORM_FILE_OK);
116 delete this;
117 }
118
119 gdata::GDataFileSystem*
120 SavePackageFilePickerChromeOS::GetGDataFileSystem() {
121 DCHECK(web_contents());
122 Profile* profile = Profile::FromBrowserContext(
123 web_contents()->GetBrowserContext());
124 DCHECK(profile);
125 gdata::GDataSystemService* system_service =
126 gdata::GDataSystemServiceFactory::GetForProfile(profile);
127 // system_service is NULL in incognito.
128 return system_service ? system_service->file_system() : NULL;
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698