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

Unified Diff: chrome/browser/ui/ash/screenshot_taker.cc

Issue 10830179: gdata: Save screenshot to /drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add bug ID. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/ash/screenshot_taker.cc
diff --git a/chrome/browser/ui/ash/screenshot_taker.cc b/chrome/browser/ui/ash/screenshot_taker.cc
index f11a55f0b0ef34e6f93f489df02cd87a1a302ce7..791442415057f259234f110452bced7bf37aa8db 100644
--- a/chrome/browser/ui/ash/screenshot_taker.cc
+++ b/chrome/browser/ui/ash/screenshot_taker.cc
@@ -30,6 +30,7 @@
#include "ui/aura/window.h"
#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#endif
@@ -49,8 +50,7 @@ bool ShouldUse24HourClock() {
return base::GetHourClockType() == base::k24HourClock;
}
-FilePath GetScreenshotPath(const FilePath& base_directory,
- bool use_24hour_clock) {
+std::string GetScreenShotBaseFilename(bool use_24hour_clock) {
base::Time::Exploded now;
base::Time::Now().LocalExplode(&now);
@@ -76,41 +76,87 @@ FilePath GetScreenshotPath(const FilePath& base_directory,
file_name.append((now.hour >= 12) ? "PM" : "AM");
}
+ return file_name;
+}
+
+FilePath GetScreenshotPath(const FilePath& base_directory,
+ const std::string& base_name) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
for (int retry = 0; retry < INT_MAX; retry++) {
std::string retry_suffix;
if (retry > 0)
retry_suffix = base::StringPrintf(" (%d)", retry + 1);
FilePath file_path = base_directory.AppendASCII(
- file_name + retry_suffix + ".png");
+ base_name + retry_suffix + ".png");
if (!file_util::PathExists(file_path))
return file_path;
}
-
return FilePath();
}
-// |is_logged_in| is used only for ChromeOS. Otherwise it is always true.
-void SaveScreenshot(const FilePath& screenshot_directory,
- bool use_24hour_clock,
- scoped_refptr<base::RefCountedBytes> png_data) {
+void SaveScreenshotToLocalFile(scoped_refptr<base::RefCountedBytes> png_data,
+ const FilePath& screenshot_path) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+ if (static_cast<size_t>(file_util::WriteFile(
+ screenshot_path,
+ reinterpret_cast<char*>(&(png_data->data()[0])),
+ png_data->size())) != png_data->size()) {
+ LOG(ERROR) << "Failed to save to " << screenshot_path.value();
+ }
+}
- FilePath screenshot_path = GetScreenshotPath(
- screenshot_directory, use_24hour_clock);
-
+void SaveScreenshot(const FilePath& screenshot_directory,
+ const std::string& base_name,
+ scoped_refptr<base::RefCountedBytes> png_data) {
+ FilePath screenshot_path = GetScreenshotPath(screenshot_directory, base_name);
if (screenshot_path.empty()) {
LOG(ERROR) << "Failed to find a screenshot file name.";
return;
}
+ SaveScreenshotToLocalFile(png_data, screenshot_path);
+}
- if (static_cast<size_t>(file_util::WriteFile(
- screenshot_path,
- reinterpret_cast<char*>(&(png_data->data()[0])),
- png_data->size())) != png_data->size()) {
- LOG(ERROR) << "Failed to save to " << screenshot_path.value();
+// TODO(kinaba): crbug.com/140425, remove this ungly #ifdef dispatch.
+#ifdef OS_CHROMEOS
+void SaveScreenshotToGData(scoped_refptr<base::RefCountedBytes> png_data,
+ gdata::GDataFileError error,
+ const FilePath& local_path) {
+ if (error != gdata::GDATA_FILE_OK) {
+ LOG(ERROR) << "Failed to write screenshot image to Google Drive: " << error;
+ return;
+ }
+ SaveScreenshotToLocalFile(png_data, local_path);
+}
+
+void PostSaveScreenshotTask(const FilePath& screenshot_directory,
+ const std::string& base_name,
+ scoped_refptr<base::RefCountedBytes> png_data) {
+ if (gdata::util::IsUnderGDataMountPoint(screenshot_directory)) {
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+ if (profile) {
+ // TODO(kinaba,mukai): crbug.com/140749. Take care of the case
+ // "base_name.png" already exists.
+ gdata::util::PrepareWritableFileAndRun(
+ profile,
+ screenshot_directory.Append(base_name + ".png"),
+ base::Bind(&SaveScreenshotToGData, png_data));
+ }
+ } else {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&SaveScreenshot, screenshot_directory, base_name, png_data));
}
}
+#else
+void PostSaveScreenshotTask(const FilePath& screenshot_directory,
+ const std::string& base_name,
+ scoped_refptr<base::RefCountedBytes> png_data) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::FILE, FROM_HERE,
+ base::Bind(&SaveScreenshot, screenshot_directory, base_name, png_data));
+}
+#endif
bool AreScreenshotsDisabled() {
return g_browser_process->local_state()->GetBoolean(
@@ -182,15 +228,12 @@ void ScreenshotTaker::HandleTakePartialScreenshot(
}
}
- bool use_24hour_clock = ShouldUse24HourClock();
-
if (GrabWindowSnapshot(window, rect, &png_data->data())) {
last_screenshot_timestamp_ = base::Time::Now();
DisplayVisualFeedback(rect);
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&SaveScreenshot, screenshot_directory, use_24hour_clock,
- png_data));
+ PostSaveScreenshotTask(screenshot_directory,
+ GetScreenShotBaseFilename(ShouldUse24HourClock()),
+ png_data);
} else {
LOG(ERROR) << "Failed to grab the window screenshot";
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698