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

Unified Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 10827068: gdata: Fix "save as pdf" to work on Google Drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + add bug id + drive-by comment typo fix. 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 | « chrome/browser/chromeos/gdata/gdata_util.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/print_preview/print_preview_handler.cc
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index 66009cba46129547c7b38beca918586eb25c8814..db933fa6cf48f72d0ddbb14818d1081f0ac8ca9b 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -59,6 +59,12 @@
#include "printing/print_settings.h"
#include "unicode/ulocdata.h"
+#ifdef OS_CHROMEOS
+// TODO(kinaba): provide more non-intrusive way for handling local/remote
+// distinction and remove these ugly #ifdef's. http://crbug.com/140425
+#include "chrome/browser/chromeos/gdata/gdata_util.h"
+#endif
+
#if !defined(OS_MACOSX)
#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
@@ -122,7 +128,7 @@ void ReportPrintDestinationHistogram(enum PrintDestinationBuckets event) {
PRINT_DESTINATION_BUCKET_BOUNDARY);
}
-// Name of a dictionary fielad holdong cloud print related data;
+// Name of a dictionary field holding cloud print related data;
const char kCloudPrintData[] = "cloudPrintData";
// Name of a dictionary field holding the initiator tab title.
const char kInitiatorTabTitle[] = "initiatorTabTitle";
@@ -213,6 +219,22 @@ void PrintToPdfCallback(Metafile* metafile, const FilePath& path) {
base::Bind(&base::DeletePointer<Metafile>, metafile));
}
+#ifdef OS_CHROMEOS
+void PrintToPdfCallbackWithCheck(Metafile* metafile,
+ gdata::GDataFileError error,
+ const FilePath& path) {
+ if (error != gdata::GDATA_FILE_OK) {
+ LOG(ERROR) << "Save to pdf failed to write: " << error;
+ } else {
+ metafile->SaveTo(path);
+ }
+ // |metafile| must be deleted on the UI thread.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&base::DeletePointer<Metafile>, metafile));
+}
+#endif
+
static base::LazyInstance<printing::StickySettings> sticky_settings =
LAZY_INSTANCE_INITIALIZER;
@@ -911,9 +933,18 @@ void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) {
printing::PreviewMetafile* metafile = new printing::PreviewMetafile;
metafile->InitFromData(static_cast<const void*>(data->front()), data->size());
// PrintToPdfCallback takes ownership of |metafile|.
+#ifdef OS_CHROMEOS
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ gdata::util::PrepareWritableFileAndRun(
+ Profile::FromBrowserContext(preview_web_contents()->GetBrowserContext()),
+ *print_to_pdf_path_,
+ base::Bind(&PrintToPdfCallbackWithCheck, metafile));
+#else
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&PrintToPdfCallback, metafile,
*print_to_pdf_path_));
+#endif
+
print_to_pdf_path_.reset();
ActivateInitiatorTabAndClosePreviewTab();
}
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_util.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698