Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (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_uploader.h" | |
| 14 #include "chrome/browser/chromeos/gdata/gdata_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 const FilePath::StringType& default_extension, | |
| 25 bool can_save_as_complete, | |
| 26 DownloadPrefs* download_prefs, | |
| 27 content::SaveFilePathPickedCallback callback) : | |
| 28 SavePackageFilePicker(web_contents, suggested_path, default_extension, | |
| 29 can_save_as_complete, download_prefs, callback), | |
|
Randy Smith (Not in Mondays)
2012/03/26 17:13:02
I apologize, as there's probably something basic I
achuithb
2012/03/26 19:44:44
Talked about this in person.
This code isn't idea
| |
| 30 content::WebContentsObserver(web_contents) { | |
| 31 } | |
| 32 | |
| 33 SavePackageFilePickerChromeOS::~SavePackageFilePickerChromeOS() { | |
| 34 } | |
| 35 | |
| 36 void SavePackageFilePickerChromeOS::FileSelected(const FilePath& path, | |
| 37 int index, | |
| 38 void* params) { | |
| 39 if (!web_contents()) { | |
| 40 NOTREACHED(); | |
| 41 return; | |
| 42 } | |
| 43 | |
| 44 if (gdata::util::IsUnderGDataMountPoint(path)) { | |
| 45 FilePath gdata_tmp_download_dir = | |
| 46 GetGDataFileSystem()->GetGDataTempDownloadFolderPath(); | |
| 47 | |
| 48 selected_path_ = path; | |
| 49 FilePath* gdata_tmp_download_path = new FilePath(); | |
| 50 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | |
| 51 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath, | |
| 52 gdata_tmp_download_dir, | |
| 53 gdata_tmp_download_path), | |
| 54 base::Bind(&SavePackageFilePickerChromeOS::GenerateMHTML, | |
| 55 base::Unretained(this), | |
| 56 base::Owned(gdata_tmp_download_path))); | |
| 57 } else { | |
| 58 DVLOG(1) << "SavePackageFilePickerChromeOS non-gdata file"; | |
| 59 SavePackageFilePicker::FileSelected(path, index, params); | |
|
zel
2012/03/26 16:33:41
actually, on ChromeOS we probably want to make sav
achuithb
2012/03/26 21:37:46
Done.
| |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void SavePackageFilePickerChromeOS::GenerateMHTML( | |
| 64 FilePath* gdata_tmp_download_path) { | |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 66 if (!web_contents()) { | |
| 67 NOTREACHED(); | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 DVLOG(1) << "GenerateMHTML " << gdata_tmp_download_path->value(); | |
| 72 web_contents()->GenerateMHTML(*gdata_tmp_download_path, | |
| 73 base::Bind(&SavePackageFilePickerChromeOS::MHTMLGenerated, | |
| 74 base::Unretained(this))); | |
| 75 } | |
| 76 | |
| 77 void SavePackageFilePickerChromeOS::MHTMLGenerated(const FilePath& src_path, | |
| 78 int64 file_size) { | |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 80 if (!web_contents()) { | |
| 81 NOTREACHED(); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 DVLOG(1) << "TransferFile from " << src_path.value() | |
| 86 << " to " << selected_path_.value(); | |
| 87 GetGDataFileSystem()->TransferFile(src_path, selected_path_, | |
|
zel
2012/03/26 16:13:14
if (!GetGDataFileSystem())
return;
see comment
achuithb
2012/03/26 19:44:44
Done.
| |
| 88 base::Bind(&SavePackageFilePickerChromeOS::OnTransferFile, | |
| 89 base::Unretained(this))); | |
| 90 } | |
| 91 | |
| 92 void SavePackageFilePickerChromeOS::OnTransferFile( | |
| 93 base::PlatformFileError error) { | |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 95 DCHECK_EQ(error, base::PLATFORM_FILE_OK); | |
| 96 delete this; | |
| 97 } | |
| 98 | |
| 99 gdata::GDataFileSystem* | |
| 100 SavePackageFilePickerChromeOS::GetGDataFileSystem() { | |
| 101 DCHECK(web_contents()); | |
| 102 Profile* profile = Profile::FromBrowserContext( | |
| 103 web_contents()->GetBrowserContext()); | |
| 104 DCHECK(profile); | |
| 105 gdata::GDataSystemService* system_service = | |
| 106 gdata::GDataSystemServiceFactory::GetForProfile(profile); | |
| 107 DCHECK(system_service); | |
|
zel
2012/03/26 16:13:14
nit: this will be NULL in incognito mode
if (!sys
achuithb
2012/03/26 19:44:44
Done.
| |
| 108 return system_service->file_system(); | |
| 109 } | |
| OLD | NEW |