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), | |
| 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()) { | |
|
Randy Smith (Not in Mondays)
2012/03/26 21:08:33
It looks to me (WebContentsObserver::TabContentsDe
achuithb
2012/03/26 21:35:54
Yup. Done.
| |
| 40 NOTREACHED(); | |
| 41 return; | |
| 42 } | |
| 43 | |
| 44 gdata::GDataFileSystem* gdata_filesystem = GetGDataFileSystem(); | |
| 45 if (gdata_filesystem && gdata::util::IsUnderGDataMountPoint(path)) { | |
| 46 FilePath gdata_tmp_download_dir = | |
| 47 gdata_filesystem->GetGDataTempDownloadFolderPath(); | |
| 48 | |
| 49 selected_path_ = path; | |
| 50 FilePath* gdata_tmp_download_path = new FilePath(); | |
| 51 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | |
| 52 base::Bind(&gdata::GDataDownloadObserver::GetGDataTempDownloadPath, | |
| 53 gdata_tmp_download_dir, | |
| 54 gdata_tmp_download_path), | |
| 55 base::Bind(&SavePackageFilePickerChromeOS::GenerateMHTML, | |
| 56 base::Unretained(this), | |
| 57 base::Owned(gdata_tmp_download_path))); | |
| 58 } else { | |
| 59 DVLOG(1) << "SavePackageFilePickerChromeOS non-gdata file"; | |
| 60 SavePackageFilePicker::FileSelected(path, index, params); | |
|
Randy Smith (Not in Mondays)
2012/03/26 21:08:33
It looks like you haven't incorporated Zel's comme
achuithb
2012/03/26 21:35:54
It's done now.
| |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void SavePackageFilePickerChromeOS::GenerateMHTML( | |
| 65 FilePath* gdata_tmp_download_path) { | |
| 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 67 if (!web_contents()) { | |
| 68 NOTREACHED(); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 DVLOG(1) << "GenerateMHTML " << gdata_tmp_download_path->value(); | |
| 73 web_contents()->GenerateMHTML(*gdata_tmp_download_path, | |
| 74 base::Bind(&SavePackageFilePickerChromeOS::OnMHTMLGenerated, | |
| 75 base::Unretained(this))); | |
| 76 } | |
| 77 | |
| 78 void SavePackageFilePickerChromeOS::OnMHTMLGenerated(const FilePath& src_path, | |
| 79 int64 file_size) { | |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 81 if (!web_contents()) { | |
| 82 NOTREACHED(); | |
| 83 return; | |
| 84 } | |
| 85 | |
| 86 DVLOG(1) << "TransferFile from " << src_path.value() | |
| 87 << " to " << selected_path_.value(); | |
| 88 gdata::GDataFileSystem* gdata_filesystem = GetGDataFileSystem(); | |
| 89 if (gdata_filesystem) { | |
| 90 gdata_filesystem->TransferFile(src_path, selected_path_, | |
| 91 base::Bind(&SavePackageFilePickerChromeOS::OnTransferFile, | |
| 92 base::Unretained(this))); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void SavePackageFilePickerChromeOS::OnTransferFile( | |
| 97 base::PlatformFileError error) { | |
| 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 99 DCHECK_EQ(error, base::PLATFORM_FILE_OK); | |
| 100 delete this; | |
| 101 } | |
| 102 | |
| 103 gdata::GDataFileSystem* | |
| 104 SavePackageFilePickerChromeOS::GetGDataFileSystem() { | |
| 105 DCHECK(web_contents()); | |
| 106 Profile* profile = Profile::FromBrowserContext( | |
| 107 web_contents()->GetBrowserContext()); | |
| 108 DCHECK(profile); | |
| 109 gdata::GDataSystemService* system_service = | |
| 110 gdata::GDataSystemServiceFactory::GetForProfile(profile); | |
| 111 // system_service is NULL in incognito. | |
| 112 return system_service ? system_service->file_system() : NULL; | |
| 113 } | |
| OLD | NEW |