Chromium Code Reviews| Index: chrome/browser/ui/webui/screenshot_source.cc |
| diff --git a/chrome/browser/ui/webui/screenshot_source.cc b/chrome/browser/ui/webui/screenshot_source.cc |
| index 15d0d57090d1a715a60ba9caec211875800aabab..f552b458c876c34a610a02ba3025167398c6a260 100644 |
| --- a/chrome/browser/ui/webui/screenshot_source.cc |
| +++ b/chrome/browser/ui/webui/screenshot_source.cc |
| @@ -21,6 +21,9 @@ |
| #if defined(OS_CHROMEOS) |
| #include "ash/shell.h" |
| #include "ash/shell_delegate.h" |
| +#include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
| +#include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| +#include "chrome/browser/chromeos/gdata/gdata_util.h" |
| #include "content/public/browser/browser_thread.h" |
| #endif |
| @@ -30,8 +33,10 @@ static const char kSavedScreenshotsBasePath[] = "saved/"; |
| #endif |
| ScreenshotSource::ScreenshotSource( |
| - std::vector<unsigned char>* current_screenshot) |
| - : DataSource(chrome::kChromeUIScreenshotPath, MessageLoop::current()) { |
| + std::vector<unsigned char>* current_screenshot, |
| + Profile* profile) |
| + : DataSource(chrome::kChromeUIScreenshotPath, MessageLoop::current()), |
| + profile_(profile) { |
| // Setup the last screenshot taken. |
| if (current_screenshot) |
| current_screenshot_.reset(new ScreenshotData(*current_screenshot)); |
| @@ -76,10 +81,40 @@ void ScreenshotSource::SendScreenshot(const std::string& screenshot_path, |
| } else if (path.compare(0, strlen(kSavedScreenshotsBasePath), |
| kSavedScreenshotsBasePath) == 0) { |
| using content::BrowserThread; |
| - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&ScreenshotSource::SendSavedScreenshot, |
| - base::Unretained(this), path, |
| - request_id)); |
| + |
| + std::string filename = screenshot_path.substr( |
| + strlen(kSavedScreenshotsBasePath)); |
| + |
| + url_canon::RawCanonOutputT<char16> decoded; |
| + url_util::DecodeURLEscapeSequences( |
| + filename.data(), filename.size(), &decoded); |
| + // Screenshot filenames don't use non-ascii characters. |
| + std::string decoded_filename = UTF16ToASCII(string16( |
| + decoded.data(), decoded.length())); |
| + |
| + DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
| + ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); |
| + FilePath download_path = download_prefs->DownloadPath(); |
| + if (gdata::util::IsUnderGDataMountPoint(download_path)) { |
| + gdata::GDataFileSystemInterface* file_system = |
| + gdata::GDataSystemServiceFactory::GetForProfile( |
| + profile_)->file_system(); |
| + file_system->GetFileByResourceId( |
| + decoded_filename, |
| + base::Bind(&ScreenshotSource::SendSavedScreenshot, |
|
kinaba
2012/08/15 09:01:55
This time, SendSavedScreenshot is called back on t
Jun Mukai
2012/08/15 09:18:45
Done.
|
| + base::Unretained(this), screenshot_path, request_id), |
| + gdata::GetContentCallback()); |
| + } else { |
| + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&ScreenshotSource::SendSavedScreenshot, |
| + base::Unretained(this), |
| + screenshot_path, |
| + request_id, |
| + gdata::GDATA_FILE_OK, |
| + download_path.Append(decoded_filename), |
| + "", |
| + gdata::REGULAR_FILE)); |
| + } |
| #endif |
| } else { |
| CacheAndSendScreenshot( |
| @@ -88,24 +123,19 @@ void ScreenshotSource::SendScreenshot(const std::string& screenshot_path, |
| } |
| #if defined(OS_CHROMEOS) |
| -void ScreenshotSource::SendSavedScreenshot(const std::string& screenshot_path, |
| - int request_id) { |
| +void ScreenshotSource::SendSavedScreenshot( |
| + const std::string& screenshot_path, |
| + int request_id, |
| + gdata::GDataFileError error, |
| + const FilePath& file, |
| + const std::string& mime_type, |
| + gdata::GDataFileType file_type) { |
| ScreenshotDataPtr read_bytes(new ScreenshotData); |
| - std::string filename = screenshot_path.substr( |
| - strlen(kSavedScreenshotsBasePath)); |
| - |
| - url_canon::RawCanonOutputT<char16> decoded; |
| - url_util::DecodeURLEscapeSequences( |
| - filename.data(), filename.size(), &decoded); |
| - // Screenshot filenames don't use non-ascii characters. |
| - std::string decoded_filename = UTF16ToASCII(string16( |
| - decoded.data(), decoded.length())); |
| - |
| int64 file_size = 0; |
| - DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
| - ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); |
| - FilePath file = download_prefs->DownloadPath().Append(decoded_filename); |
| - if (!file_util::GetFileSize(file, &file_size)) { |
| + |
| + if (error != gdata::GDATA_FILE_OK || |
| + file_type != gdata::REGULAR_FILE || |
| + !file_util::GetFileSize(file, &file_size)) { |
| CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
| return; |
| } |