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

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

Issue 9809011: GData save package support with MHTML. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add comments and TODOs 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
11 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
12 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
13 #include "chrome/browser/chromeos/gdata/gdata_util.h"
14 #include "chrome/browser/platform_util.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/web_contents.h"
18
19 using content::BrowserThread;
20
21 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS(
22 content::WebContents* web_contents,
23 const FilePath& suggested_path)
24 : content::WebContentsObserver(web_contents) {
25 select_file_dialog_ = SelectFileDialog::Create(this);
26 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE,
27 string16(),
28 suggested_path.ReplaceExtension("mhtml"),
29 NULL,
30 0,
31 "mhtml",
32 web_contents,
33 platform_util::GetTopLevel(
34 web_contents->GetNativeView()),
35 NULL);
36 }
37
38 SavePackageFilePickerChromeOS::~SavePackageFilePickerChromeOS() {
39 }
40
41 void SavePackageFilePickerChromeOS::FileSelected(const FilePath& path,
42 int index,
43 void* params) {
44 if (!web_contents()) {
45 delete this;
46 return;
47 }
48
49 gdata::GDataFileSystem* gdata_filesystem = GetGDataFileSystem();
50 if (gdata_filesystem && gdata::util::IsUnderGDataMountPoint(path)) {
51 FilePath gdata_tmp_download_dir =
52 gdata_filesystem->GetGDataTempDownloadFolderPath();
53
54 selected_path_ = path;
55 FilePath* gdata_tmp_download_path = new FilePath();
56 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
57 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath,
58 gdata_tmp_download_dir,
59 gdata_tmp_download_path),
60 base::Bind(&SavePackageFilePickerChromeOS::GenerateMHTML,
61 base::Unretained(this),
62 base::Owned(gdata_tmp_download_path)));
63 } else {
64 DVLOG(1) << "SavePackageFilePickerChromeOS non-gdata file";
65 GenerateMHTML(&path);
66 }
67 }
68
69 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) {
70 delete this;
71 }
72
73 void SavePackageFilePickerChromeOS::GenerateMHTML(const FilePath* mhtml_path) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 if (!web_contents()) {
76 delete this;
77 return;
78 }
79
80 DVLOG(1) << "GenerateMHTML " << mhtml_path->value();
81 web_contents()->GenerateMHTML(*mhtml_path,
82 base::Bind(&SavePackageFilePickerChromeOS::OnMHTMLGenerated,
83 base::Unretained(this)));
84 }
85
86 void SavePackageFilePickerChromeOS::OnMHTMLGenerated(const FilePath& src_path,
87 int64 file_size) {
asanka 2012/03/27 01:54:33 Nit: Indent
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 if (!web_contents()) {
90 delete this;
91 return;
92 }
93
94 gdata::GDataFileSystem* gdata_filesystem = GetGDataFileSystem();
95 if (gdata_filesystem && !selected_path_.empty()) {
96 DVLOG(1) << "TransferFile from " << src_path.value()
97 << " to " << selected_path_.value();
98 gdata_filesystem->TransferFile(src_path,
99 gdata::util::ExtractGDataPath(selected_path_),
100 base::Bind(&SavePackageFilePickerChromeOS::OnTransferFile,
101 base::Unretained(this)));
102 } else {
103 delete this;
104 }
105 }
106
107 void SavePackageFilePickerChromeOS::OnTransferFile(
108 base::PlatformFileError error) {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 DCHECK_EQ(error, base::PLATFORM_FILE_OK);
111 delete this;
112 }
113
114 gdata::GDataFileSystem*
115 SavePackageFilePickerChromeOS::GetGDataFileSystem() {
116 DCHECK(web_contents());
117 Profile* profile = Profile::FromBrowserContext(
118 web_contents()->GetBrowserContext());
119 DCHECK(profile);
120 gdata::GDataSystemService* system_service =
121 gdata::GDataSystemServiceFactory::GetForProfile(profile);
122 // system_service is NULL in incognito.
123 return system_service ? system_service->file_system() : NULL;
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698