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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.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: Add mock method. 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 4150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4161 // All the invocation of |callback| from operations initiated from CloseFile 4161 // All the invocation of |callback| from operations initiated from CloseFile
4162 // must go through here. Removes the |file_path| from the remembered set so 4162 // must go through here. Removes the |file_path| from the remembered set so
4163 // that subsequent operations can open the file again. 4163 // that subsequent operations can open the file again.
4164 open_files_.erase(file_path); 4164 open_files_.erase(file_path);
4165 4165
4166 // Then invokes the user-supplied callback function. 4166 // Then invokes the user-supplied callback function.
4167 if (!callback.is_null()) 4167 if (!callback.is_null())
4168 callback.Run(result); 4168 callback.Run(result);
4169 } 4169 }
4170 4170
4171 void GDataFileSystem::PrepareWritableFileAndRun(
4172 const FilePath& file_path,
4173 const OpenFileCallback& callback) {
4174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
4175 BrowserThread::CurrentlyOn(BrowserThread::IO));
4176 RunTaskOnUIThread(
4177 base::Bind(&GDataFileSystem::PrepareWritableFileAndRunOnUIThread,
4178 ui_weak_ptr_,
4179 file_path,
4180 callback));
4181 }
4182
4183 void GDataFileSystem::PrepareWritableFileAndRunOnUIThread(
4184 const FilePath& file_path,
4185 const OpenFileCallback& callback) {
4186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4187
4188 CreateFileOnUIThread(
4189 file_path,
4190 false, // it is not an error, even if the path already exists.
4191 base::Bind(&GDataFileSystem::PrepareWritableFileAndRunAfterCreateFile,
4192 ui_weak_ptr_,
4193 file_path,
4194 callback));
4195 }
4196
4197 void GDataFileSystem::PrepareWritableFileAndRunAfterCreateFile(
4198 const FilePath& file_path,
4199 const OpenFileCallback& callback,
4200 GDataFileError result) {
satorux1 2012/07/27 22:56:29 result -> error
kinaba 2012/08/01 13:48:45 Done.
4201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4202
4203 if (result != gdata::GDATA_FILE_OK) {
4204 if (!callback.is_null()) {
4205 content::BrowserThread::GetBlockingPool()->PostTask(
4206 FROM_HERE,
4207 base::Bind(callback, result, FilePath()));
satorux1 2012/07/27 22:56:29 we should just run the callback here. PostTask sh
kinaba 2012/08/01 13:48:45 This is not a PostTask to the current thread, it i
4208 }
4209 return;
4210 }
4211 OpenFileOnUIThread(
4212 file_path,
4213 base::Bind(&GDataFileSystem::PrepareWritableFileAndRunAfterOpenFile,
4214 ui_weak_ptr_,
4215 file_path,
4216 callback));
4217 }
4218
4219 void GDataFileSystem::PrepareWritableFileAndRunAfterOpenFile(
4220 const FilePath& file_path,
4221 const OpenFileCallback& callback,
4222 GDataFileError result,
satorux1 2012/07/27 22:56:29 error
kinaba 2012/08/01 13:48:45 Done.
4223 const FilePath& local_cache_path) {
4224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4225
4226 if (result != gdata::GDATA_FILE_OK) {
4227 if (!callback.is_null()) {
4228 content::BrowserThread::GetBlockingPool()->PostTask(
satorux1 2012/07/27 22:56:29 ditto
kinaba 2012/08/01 13:48:45 See the reply above.
4229 FROM_HERE,
4230 base::Bind(callback, result, FilePath()));
4231 }
4232 return;
4233 }
4234
4235 if (!callback.is_null()) {
4236 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(
4237 FROM_HERE,
4238 base::Bind(callback, GDATA_FILE_OK, local_cache_path),
4239 base::Bind(&GDataFileSystem::PrepareWritableFileAndRunAfterCallback,
4240 ui_weak_ptr_,
4241 file_path));
4242 } else {
4243 PrepareWritableFileAndRunAfterCallback(file_path);
4244 }
4245 }
4246
4247 void GDataFileSystem::PrepareWritableFileAndRunAfterCallback(
4248 const FilePath& file_path) {
4249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4250 CloseFileOnUIThread(file_path, FileOperationCallback());
4251 }
4252
4171 } // namespace gdata 4253 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698