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

Side by Side Diff: chrome/browser/chromeos/gdata/file_write_helper.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/chromeos/gdata/file_write_helper.h"
6
7 #include "base/threading/sequenced_worker_pool.h"
8 #include "content/public/browser/browser_thread.h"
9
10 using content::BrowserThread;
11
12 namespace gdata {
13
14 FileWriteHelper::FileWriteHelper(GDataFileSystemInterface* file_system)
15 : file_system_(file_system),
16 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
17 // Must be created in GDataSystemService.
18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
19 }
20
21 FileWriteHelper::~FileWriteHelper() {
22 // Must be destroyed in GDataSystemService.
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
24 }
25
26 void FileWriteHelper::PrepareWritableFileAndRun(
27 const FilePath& file_path,
28 const OpenFileCallback& callback) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
30
31 file_system_->CreateFile(
32 file_path,
33 false, // it is not an error, even if the path already exists.
34 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile,
35 weak_ptr_factory_.GetWeakPtr(),
36 file_path,
37 callback));
38 }
39
40 void FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile(
41 const FilePath& file_path,
42 const OpenFileCallback& callback,
43 GDataFileError error) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45
46 if (error != gdata::GDATA_FILE_OK) {
47 if (!callback.is_null()) {
48 content::BrowserThread::GetBlockingPool()->PostTask(
49 FROM_HERE,
50 base::Bind(callback, error, FilePath()));
51 }
52 return;
53 }
54 file_system_->OpenFile(
55 file_path,
56 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile,
57 weak_ptr_factory_.GetWeakPtr(),
58 file_path,
59 callback));
60 }
61
62 void FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile(
63 const FilePath& file_path,
64 const OpenFileCallback& callback,
65 GDataFileError error,
66 const FilePath& local_cache_path) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
68
69 if (error != gdata::GDATA_FILE_OK) {
70 if (!callback.is_null()) {
71 content::BrowserThread::GetBlockingPool()->PostTask(
72 FROM_HERE,
73 base::Bind(callback, error, FilePath()));
74 }
75 return;
76 }
77
78 if (!callback.is_null()) {
79 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(
80 FROM_HERE,
81 base::Bind(callback, GDATA_FILE_OK, local_cache_path),
82 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCallback,
83 weak_ptr_factory_.GetWeakPtr(),
84 file_path));
85 } else {
86 PrepareWritableFileAndRunAfterCallback(file_path);
87 }
88 }
89
90 void FileWriteHelper::PrepareWritableFileAndRunAfterCallback(
91 const FilePath& file_path) {
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
93 file_system_->CloseFile(file_path, FileOperationCallback());
94 }
95
96 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/file_write_helper.h ('k') | chrome/browser/chromeos/gdata/file_write_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698