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

Side by Side Diff: chrome/browser/chromeos/drive/fileapi_worker.cc

Issue 19596003: Remove CloseFile from FileSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/drive/fileapi_worker.h" 5 #include "chrome/browser/chromeos/drive/fileapi_worker.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT : 129 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT :
130 webkit_blob::ScopedFile::DONT_DELETE_ON_SCOPE_OUT; 130 webkit_blob::ScopedFile::DONT_DELETE_ON_SCOPE_OUT;
131 131
132 callback.Run(base::PLATFORM_FILE_OK, file_info, local_path, scope_out_policy); 132 callback.Run(base::PLATFORM_FILE_OK, file_info, local_path, scope_out_policy);
133 } 133 }
134 134
135 // Runs |callback| with arguments converted from |error| and |local_path|. 135 // Runs |callback| with arguments converted from |error| and |local_path|.
136 void RunCreateWritableSnapshotFileCallback( 136 void RunCreateWritableSnapshotFileCallback(
137 const CreateWritableSnapshotFileCallback& callback, 137 const CreateWritableSnapshotFileCallback& callback,
138 FileError error, 138 FileError error,
139 const base::FilePath& local_path) { 139 const base::FilePath& local_path,
140 const base::Closure& close_callback) {
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
141 callback.Run(FileErrorToPlatformError(error), local_path); 142 callback.Run(FileErrorToPlatformError(error), local_path, close_callback);
142 } 143 }
143 144
144 // Runs |callback| with |error| and |platform_file|. 145 // Runs |callback| with |error| and |platform_file|.
145 void RunOpenFileCallback(const OpenFileCallback& callback, 146 void RunOpenFileCallback(const OpenFileCallback& callback,
147 const base::Closure& close_callback,
146 base::PlatformFileError* error, 148 base::PlatformFileError* error,
147 base::PlatformFile platform_file) { 149 base::PlatformFile platform_file) {
148 callback.Run(*error, platform_file); 150 callback.Run(*error, platform_file, close_callback);
149 } 151 }
150 152
151 // Part of OpenFile(). Called after FileSystem::OpenFile(). 153 // Part of OpenFile(). Called after FileSystem::OpenFile().
152 void OpenFileAfterFileSystemOpenFile(int file_flags, 154 void OpenFileAfterFileSystemOpenFile(int file_flags,
153 const OpenFileCallback& callback, 155 const OpenFileCallback& callback,
154 FileError error, 156 FileError error,
155 const base::FilePath& local_path) { 157 const base::FilePath& local_path,
158 const base::Closure& close_callback) {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
157 160
158 if (error != FILE_ERROR_OK) { 161 if (error != FILE_ERROR_OK) {
159 callback.Run(FileErrorToPlatformError(error), 162 callback.Run(FileErrorToPlatformError(error),
160 base::kInvalidPlatformFileValue); 163 base::kInvalidPlatformFileValue,
164 base::Closure());
161 return; 165 return;
162 } 166 }
163 167
164 // Here, the file should be at |local_path|, but there may be timing issue. 168 // Here, the file should be at |local_path|, but there may be timing issue.
165 // Because the file is managed by Drive file system, so, in order to avoid 169 // Because the file is managed by Drive file system, so, in order to avoid
166 // unexpected file creation, CREATE, OPEN_ALWAYS and CREATE_ALWAYS are 170 // unexpected file creation, CREATE, OPEN_ALWAYS and CREATE_ALWAYS are
167 // translated into OPEN or OPEN_TRUNCATED, here. Keep OPEN and OPEN_TRUNCATED 171 // translated into OPEN or OPEN_TRUNCATED, here. Keep OPEN and OPEN_TRUNCATED
168 // as is. 172 // as is.
169 if (file_flags & (base::PLATFORM_FILE_CREATE | 173 if (file_flags & (base::PLATFORM_FILE_CREATE |
170 base::PLATFORM_FILE_OPEN_ALWAYS)) { 174 base::PLATFORM_FILE_OPEN_ALWAYS)) {
171 file_flags &= ~(base::PLATFORM_FILE_CREATE | 175 file_flags &= ~(base::PLATFORM_FILE_CREATE |
172 base::PLATFORM_FILE_OPEN_ALWAYS); 176 base::PLATFORM_FILE_OPEN_ALWAYS);
173 file_flags |= base::PLATFORM_FILE_OPEN; 177 file_flags |= base::PLATFORM_FILE_OPEN;
174 } else if (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS) { 178 } else if (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS) {
175 file_flags &= ~base::PLATFORM_FILE_CREATE_ALWAYS; 179 file_flags &= ~base::PLATFORM_FILE_CREATE_ALWAYS;
176 file_flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; 180 file_flags |= base::PLATFORM_FILE_OPEN_TRUNCATED;
177 } 181 }
178 182
179 // Cache file prepared for modification is available. Open it locally. 183 // Cache file prepared for modification is available. Open it locally.
180 base::PlatformFileError* result = 184 base::PlatformFileError* result =
181 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); 185 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED);
182 bool posted = base::PostTaskAndReplyWithResult( 186 bool posted = base::PostTaskAndReplyWithResult(
183 BrowserThread::GetBlockingPool(), FROM_HERE, 187 BrowserThread::GetBlockingPool(), FROM_HERE,
184 base::Bind(&base::CreatePlatformFile, 188 base::Bind(&base::CreatePlatformFile,
185 local_path, file_flags, static_cast<bool*>(NULL), result), 189 local_path, file_flags, static_cast<bool*>(NULL), result),
186 base::Bind(&RunOpenFileCallback, callback, base::Owned(result))); 190 base::Bind(&RunOpenFileCallback,
191 callback, close_callback, base::Owned(result)));
187 DCHECK(posted); 192 DCHECK(posted);
188 } 193 }
189 194
190 // Emits debug log when FileSystem::CloseFile() is complete.
191 void EmitDebugLogForCloseFile(const base::FilePath& local_path,
192 FileError file_error) {
193 DVLOG(1) << "Closed: " << local_path.AsUTF8Unsafe() << ": " << file_error;
194 }
195
196 } // namespace 195 } // namespace
197 196
198 void RunFileSystemCallback( 197 void RunFileSystemCallback(
199 const FileSystemGetter& file_system_getter, 198 const FileSystemGetter& file_system_getter,
200 const base::Callback<void(FileSystemInterface*)>& callback, 199 const base::Callback<void(FileSystemInterface*)>& callback,
201 const base::Closure& on_error_callback) { 200 const base::Closure& on_error_callback) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
203 FileSystemInterface* file_system = file_system_getter.Run(); 202 FileSystemInterface* file_system = file_system_getter.Run();
204 203
205 if (!file_system) { 204 if (!file_system) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 base::PLATFORM_FILE_CREATE_ALWAYS | 328 base::PLATFORM_FILE_CREATE_ALWAYS |
330 base::PLATFORM_FILE_OPEN_TRUNCATED | 329 base::PLATFORM_FILE_OPEN_TRUNCATED |
331 base::PLATFORM_FILE_READ | 330 base::PLATFORM_FILE_READ |
332 base::PLATFORM_FILE_WRITE | 331 base::PLATFORM_FILE_WRITE |
333 base::PLATFORM_FILE_WRITE_ATTRIBUTES | 332 base::PLATFORM_FILE_WRITE_ATTRIBUTES |
334 base::PLATFORM_FILE_APPEND)) { 333 base::PLATFORM_FILE_APPEND)) {
335 base::MessageLoopProxy::current()->PostTask( 334 base::MessageLoopProxy::current()->PostTask(
336 FROM_HERE, 335 FROM_HERE,
337 base::Bind(callback, 336 base::Bind(callback,
338 base::PLATFORM_FILE_ERROR_FAILED, 337 base::PLATFORM_FILE_ERROR_FAILED,
339 base::kInvalidPlatformFileValue)); 338 base::kInvalidPlatformFileValue,
339 base::Closure()));
340 return; 340 return;
341 } 341 }
342 342
343 file_system->OpenFile( 343 file_system->OpenFile(
344 file_path, GetOpenMode(file_flags), 344 file_path, GetOpenMode(file_flags),
345 base::Bind(&OpenFileAfterFileSystemOpenFile, file_flags, callback)); 345 base::Bind(&OpenFileAfterFileSystemOpenFile, file_flags, callback));
346 } 346 }
347 347
348 void CloseFile(const base::FilePath& file_path,
349 FileSystemInterface* file_system) {
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
351 file_system->CloseFile(file_path,
352 base::Bind(&EmitDebugLogForCloseFile, file_path));
353 }
354
355 void TouchFile(const base::FilePath& file_path, 348 void TouchFile(const base::FilePath& file_path,
356 const base::Time& last_access_time, 349 const base::Time& last_access_time,
357 const base::Time& last_modified_time, 350 const base::Time& last_modified_time,
358 const StatusCallback& callback, 351 const StatusCallback& callback,
359 FileSystemInterface* file_system) { 352 FileSystemInterface* file_system) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361 file_system->TouchFile(file_path, last_access_time, last_modified_time, 354 file_system->TouchFile(file_path, last_access_time, last_modified_time,
362 base::Bind(&RunStatusCallbackByFileError, callback)); 355 base::Bind(&RunStatusCallbackByFileError, callback));
363 356
364 } 357 }
365 358
366 } // namespace fileapi_internal 359 } // namespace fileapi_internal
367 } // namespace drive 360 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/fileapi_worker.h ('k') | chrome/browser/chromeos/drive/webkit_file_stream_writer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698