Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_proxy.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 using fileapi::FileSystemOperationInterface; | 25 using fileapi::FileSystemOperationInterface; |
| 26 using webkit_blob::ShareableFileReference; | 26 using webkit_blob::ShareableFileReference; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const char kGDataRootDirectory[] = "drive"; | 30 const char kGDataRootDirectory[] = "drive"; |
| 31 const char kFeedField[] = "feed"; | 31 const char kFeedField[] = "feed"; |
| 32 | 32 |
| 33 | 33 |
| 34 // Helper function that creates platform file on bocking IO thread pool. | 34 // Helper function that creates platform file on bocking IO thread pool. |
| 35 void CreatePlatformFileOnIOPool(const FilePath& local_path, | 35 void OpenPlatformFileOnIOPool(const FilePath& local_path, |
| 36 int file_flags, | 36 int file_flags, |
| 37 base::PlatformFile* platform_file, | 37 base::PlatformFile* platform_file, |
| 38 base::PlatformFileError* open_error) { | 38 base::PlatformFileError* open_error) { |
| 39 bool created; | 39 bool created; |
| 40 *platform_file = base::CreatePlatformFile(local_path, | 40 *platform_file = base::CreatePlatformFile(local_path, |
| 41 file_flags, | 41 file_flags, |
| 42 &created, | 42 &created, |
| 43 open_error); | 43 open_error); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Helper function to run reply on results of CreatePlatformFileOnIOPool() on | 46 // Helper function to run reply on results of OpenPlatformFileOnIOPool() on |
| 47 // IO thread. | 47 // IO thread. |
| 48 void OnPlatformFileCreated( | 48 void OnPlatformFileOpened( |
| 49 const FileSystemOperationInterface::OpenFileCallback& callback, | 49 const FileSystemOperationInterface::OpenFileCallback& callback, |
| 50 base::ProcessHandle peer_handle, | 50 base::ProcessHandle peer_handle, |
| 51 base::PlatformFile* platform_file, | 51 base::PlatformFile* platform_file, |
| 52 base::PlatformFileError* open_error) { | 52 base::PlatformFileError* open_error) { |
| 53 callback.Run(*open_error, *platform_file, peer_handle); | 53 callback.Run(*open_error, *platform_file, peer_handle); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Helper function to run OpenFileCallback from | 56 // Helper function to run OpenFileCallback from |
| 57 // GDataFileSystemProxy::OpenFile(). | 57 // GDataFileSystemProxy::OpenFile(). |
| 58 void OnGetFileByPathForOpen( | 58 void OnGetFileByPathForOpen( |
| 59 const FileSystemOperationInterface::OpenFileCallback& callback, | 59 const FileSystemOperationInterface::OpenFileCallback& callback, |
| 60 int file_flags, | 60 int file_flags, |
| 61 base::ProcessHandle peer_handle, | 61 base::ProcessHandle peer_handle, |
| 62 base::PlatformFileError error, | 62 base::PlatformFileError error, |
| 63 const FilePath& local_path, | 63 const FilePath& local_path, |
| 64 const std::string& unused_mime_type, | 64 const std::string& unused_mime_type, |
| 65 gdata::GDataFileType file_type) { | 65 gdata::GDataFileType file_type) { |
| 66 if (error != base::PLATFORM_FILE_OK) { | 66 if (error != base::PLATFORM_FILE_OK) { |
| 67 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); | 67 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 | 70 |
| 71 base::PlatformFile* platform_file = new base::PlatformFile( | 71 base::PlatformFile* platform_file = new base::PlatformFile( |
| 72 base::kInvalidPlatformFileValue); | 72 base::kInvalidPlatformFileValue); |
| 73 base::PlatformFileError* open_error = | 73 base::PlatformFileError* open_error = |
| 74 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); | 74 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); |
| 75 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | 75 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, |
| 76 base::Bind(&CreatePlatformFileOnIOPool, | 76 base::Bind(&OpenPlatformFileOnIOPool, |
| 77 local_path, | 77 local_path, |
| 78 file_flags, | 78 file_flags, |
| 79 platform_file, | 79 platform_file, |
| 80 open_error), | 80 open_error), |
| 81 base::Bind(&OnPlatformFileCreated, | 81 base::Bind(&OnPlatformFileOpened, |
| 82 callback, | 82 callback, |
| 83 peer_handle, | 83 peer_handle, |
| 84 base::Owned(platform_file), | 84 base::Owned(platform_file), |
| 85 base::Owned(open_error))); | 85 base::Owned(open_error))); |
| 86 | 86 |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Helper function to run SnapshotFileCallback from | 89 // Helper function to run SnapshotFileCallback from |
| 90 // GDataFileSystemProxy::CreateSnapshotFile(). | 90 // GDataFileSystemProxy::CreateSnapshotFile(). |
| 91 void CallSnapshotFileCallback( | 91 void CallSnapshotFileCallback( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 115 base::PlatformFileInfo final_file_info(file_info); | 115 base::PlatformFileInfo final_file_info(file_info); |
| 116 final_file_info.last_modified = base::Time(); | 116 final_file_info.last_modified = base::Time(); |
| 117 | 117 |
| 118 callback.Run(error, final_file_info, local_path, file_ref); | 118 callback.Run(error, final_file_info, local_path, file_ref); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void OnClose(const FilePath& local_path, base::PlatformFileError error_code) { | 121 void OnClose(const FilePath& local_path, base::PlatformFileError error_code) { |
| 122 DVLOG(1) << "Closed: " << local_path.AsUTF8Unsafe() << ": " << error_code; | 122 DVLOG(1) << "Closed: " << local_path.AsUTF8Unsafe() << ": " << error_code; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void OpenAndTruncateOnIOPool( | |
|
kinaba
2012/06/28 05:52:34
This function is not used now. It can be removed.
zel
2012/06/28 17:50:46
done
| |
| 126 const FilePath& local_cache_path, | |
| 127 base::PlatformFile* platform_file, | |
| 128 base::PlatformFileError* result) { | |
| 129 base::PlatformFile file = base::CreatePlatformFile( | |
| 130 local_cache_path, | |
| 131 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | |
| 132 NULL, | |
| 133 result); | |
| 134 if (*result == base::PLATFORM_FILE_OK) { | |
| 135 DCHECK_NE(base::kInvalidPlatformFileValue, file); | |
| 136 if (!base::TruncatePlatformFile(file, 0)) { | |
| 137 base::ClosePlatformFile(file); | |
| 138 *result = base::PLATFORM_FILE_ERROR_FAILED; | |
| 139 file = base::kInvalidPlatformFileValue; | |
| 140 } | |
| 141 } | |
| 142 *platform_file = file; | |
| 143 } | |
| 144 | |
| 125 void DoTruncateOnFileThread( | 145 void DoTruncateOnFileThread( |
| 126 const FilePath& local_cache_path, | 146 const FilePath& local_cache_path, |
| 127 int64 length, | 147 int64 length, |
| 128 base::PlatformFileError* result) { | 148 base::PlatformFileError* result) { |
| 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 130 | 150 |
| 131 base::PlatformFile file = base::CreatePlatformFile( | 151 base::PlatformFile file = base::CreatePlatformFile( |
| 132 local_cache_path, | 152 local_cache_path, |
| 133 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | 153 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, |
| 134 NULL, | 154 NULL, |
| 135 result); | 155 result); |
| 136 if (*result == base::PLATFORM_FILE_OK) { | 156 if (*result == base::PLATFORM_FILE_OK) { |
| 137 DCHECK_NE(base::kInvalidPlatformFileValue, file); | 157 DCHECK_NE(base::kInvalidPlatformFileValue, file); |
| 138 if (!base::TruncatePlatformFile(file, length)) | 158 if (!base::TruncatePlatformFile(file, length)) |
| 139 *result = base::PLATFORM_FILE_ERROR_FAILED; | 159 *result = base::PLATFORM_FILE_ERROR_FAILED; |
| 140 base::ClosePlatformFile(file); | 160 base::ClosePlatformFile(file); |
| 141 } | 161 } |
| 142 } | 162 } |
| 143 | 163 |
| 144 void DidCloseFileForTruncate( | 164 void DidCloseFileForTruncate( |
| 145 const fileapi::FileSystemOperationInterface::StatusCallback& callback, | 165 const FileSystemOperationInterface::StatusCallback& callback, |
| 146 base::PlatformFileError truncate_result, | 166 base::PlatformFileError truncate_result, |
| 147 base::PlatformFileError close_result) { | 167 base::PlatformFileError close_result) { |
| 148 // Reports the first error. | 168 // Reports the first error. |
| 149 callback.Run(truncate_result == base::PLATFORM_FILE_OK ? close_result | 169 callback.Run(truncate_result == base::PLATFORM_FILE_OK ? close_result |
| 150 : truncate_result); | 170 : truncate_result); |
| 151 } | 171 } |
| 152 | 172 |
| 153 } // namespace | 173 } // namespace |
| 154 | 174 |
| 155 namespace gdata { | 175 namespace gdata { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 173 GDataFileSystemInterface* file_system) | 193 GDataFileSystemInterface* file_system) |
| 174 : file_system_(file_system) { | 194 : file_system_(file_system) { |
| 175 // Should be created from the file browser extension API (AddMountFunction) | 195 // Should be created from the file browser extension API (AddMountFunction) |
| 176 // on UI thread. | 196 // on UI thread. |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 } | 198 } |
| 179 | 199 |
| 180 void GDataFileSystemProxy::GetFileInfo(const GURL& file_url, | 200 void GDataFileSystemProxy::GetFileInfo(const GURL& file_url, |
| 181 const FileSystemOperationInterface::GetMetadataCallback& callback) { | 201 const FileSystemOperationInterface::GetMetadataCallback& callback) { |
| 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 183 | |
| 184 FilePath file_path; | 203 FilePath file_path; |
| 185 if (!ValidateUrl(file_url, &file_path)) { | 204 if (!ValidateUrl(file_url, &file_path)) { |
| 186 base::MessageLoopProxy::current()->PostTask( | 205 MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 187 FROM_HERE, | 206 base::Bind(callback, |
| 188 base::Bind(callback, | 207 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 189 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 208 base::PlatformFileInfo(), |
| 190 base::PlatformFileInfo(), | 209 FilePath())); |
| 191 FilePath())); | |
| 192 return; | 210 return; |
| 193 } | 211 } |
| 194 | 212 |
| 195 file_system_->GetEntryInfoByPath( | 213 file_system_->GetEntryInfoByPath( |
| 196 file_path, | 214 file_path, |
| 197 base::Bind(&GDataFileSystemProxy::OnGetMetadata, | 215 base::Bind(&GDataFileSystemProxy::OnGetMetadata, |
| 198 this, | 216 this, |
| 199 file_path, | 217 file_path, |
| 200 callback)); | 218 callback)); |
| 201 } | 219 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 if (!ValidateUrl(file_url, &file_path)) { | 297 if (!ValidateUrl(file_url, &file_path)) { |
| 280 MessageLoopProxy::current()->PostTask(FROM_HERE, | 298 MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 281 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | 299 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); |
| 282 return; | 300 return; |
| 283 } | 301 } |
| 284 | 302 |
| 285 file_system_->CreateDirectory(file_path, exclusive, recursive, callback); | 303 file_system_->CreateDirectory(file_path, exclusive, recursive, callback); |
| 286 } | 304 } |
| 287 | 305 |
| 288 void GDataFileSystemProxy::Truncate(const GURL& file_url, int64 length, | 306 void GDataFileSystemProxy::Truncate(const GURL& file_url, int64 length, |
| 289 const fileapi::FileSystemOperationInterface::StatusCallback& callback) { | 307 const FileSystemOperationInterface::StatusCallback& callback) { |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 291 | 309 |
| 292 if (length < 0) { | 310 if (length < 0) { |
| 293 MessageLoopProxy::current()->PostTask(FROM_HERE, | 311 MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 294 base::Bind(callback, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); | 312 base::Bind(callback, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); |
| 295 return; | 313 return; |
| 296 } | 314 } |
| 297 | 315 |
| 298 FilePath file_path; | 316 FilePath file_path; |
| 299 if (!ValidateUrl(file_url, &file_path)) { | 317 if (!ValidateUrl(file_url, &file_path)) { |
| 300 MessageLoopProxy::current()->PostTask(FROM_HERE, | 318 MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 301 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | 319 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); |
| 302 return; | 320 return; |
| 303 } | 321 } |
| 304 | 322 |
| 305 // TODO(kinaba): http://crbug.com/132780. | 323 // TODO(kinaba): http://crbug.com/132780. |
| 306 // Optimize the cases for small |length|, at least for |length| == 0. | 324 // Optimize the cases for small |length|, at least for |length| == 0. |
| 307 // CreateWritableSnapshotFile downloads the whole content unnecessarily. | 325 // CreateWritableSnapshotFile downloads the whole content unnecessarily. |
| 308 file_system_->OpenFile( | 326 file_system_->OpenFile( |
| 309 file_path, | 327 file_path, |
| 310 base::Bind(&GDataFileSystemProxy::OnFileOpenedForTruncate, | 328 base::Bind(&GDataFileSystemProxy::OnFileOpenedForTruncate, |
| 311 this, | 329 this, |
| 312 file_path, | 330 file_path, |
| 313 length, | 331 length, |
| 314 callback)); | 332 callback)); |
| 315 } | 333 } |
| 316 | 334 |
| 335 void GDataFileSystemProxy::OnOpenFileForWriting( | |
| 336 int file_flags, | |
| 337 base::ProcessHandle peer_handle, | |
| 338 const FileSystemOperationInterface::OpenFileCallback& callback, | |
| 339 base::PlatformFileError open_result, | |
| 340 const FilePath& local_cache_path) { | |
| 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 342 | |
| 343 if (open_result != base::PLATFORM_FILE_OK) { | |
| 344 callback.Run(open_result, base::kInvalidPlatformFileValue, peer_handle); | |
| 345 return; | |
| 346 } | |
| 347 | |
| 348 // Cache file prepared for modification is available. Truncate it. | |
| 349 // File operation must be done on FILE thread, so relay the operation. | |
| 350 base::PlatformFileError* result = | |
| 351 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); | |
| 352 base::PlatformFile* platform_file = new base::PlatformFile( | |
| 353 base::kInvalidPlatformFileValue); | |
| 354 bool posted = BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | |
| 355 base::Bind(&OpenPlatformFileOnIOPool, | |
| 356 local_cache_path, | |
| 357 file_flags, | |
| 358 platform_file, | |
| 359 result), | |
| 360 base::Bind(&OnPlatformFileOpened, | |
| 361 callback, | |
| 362 peer_handle, | |
| 363 base::Owned(platform_file), | |
| 364 base::Owned(result))); | |
| 365 DCHECK(posted); | |
| 366 } | |
| 367 | |
| 317 void GDataFileSystemProxy::OnFileOpenedForTruncate( | 368 void GDataFileSystemProxy::OnFileOpenedForTruncate( |
| 318 const FilePath& virtual_path, | 369 const FilePath& virtual_path, |
| 319 int64 length, | 370 int64 length, |
| 320 const fileapi::FileSystemOperationInterface::StatusCallback& callback, | 371 const FileSystemOperationInterface::StatusCallback& callback, |
| 321 base::PlatformFileError open_result, | 372 base::PlatformFileError open_result, |
| 322 const FilePath& local_cache_path) { | 373 const FilePath& local_cache_path) { |
| 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 324 | 375 |
| 325 if (open_result != base::PLATFORM_FILE_OK) { | 376 if (open_result != base::PLATFORM_FILE_OK) { |
| 326 callback.Run(open_result); | 377 callback.Run(open_result); |
| 327 return; | 378 return; |
| 328 } | 379 } |
| 329 | 380 |
| 330 // Cache file prepared for modification is available. Truncate it. | 381 // Cache file prepared for modification is available. Truncate it. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 341 base::Bind(&GDataFileSystemProxy::DidTruncate, | 392 base::Bind(&GDataFileSystemProxy::DidTruncate, |
| 342 this, | 393 this, |
| 343 virtual_path, | 394 virtual_path, |
| 344 callback, | 395 callback, |
| 345 base::Owned(result))); | 396 base::Owned(result))); |
| 346 DCHECK(posted); | 397 DCHECK(posted); |
| 347 } | 398 } |
| 348 | 399 |
| 349 void GDataFileSystemProxy::DidTruncate( | 400 void GDataFileSystemProxy::DidTruncate( |
| 350 const FilePath& virtual_path, | 401 const FilePath& virtual_path, |
| 351 const fileapi::FileSystemOperationInterface::StatusCallback& callback, | 402 const FileSystemOperationInterface::StatusCallback& callback, |
| 352 base::PlatformFileError* truncate_result) { | 403 base::PlatformFileError* truncate_result) { |
| 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 354 | 405 |
| 355 // Truncation finished. We must close the file no matter |truncate_result| | 406 // Truncation finished. We must close the file no matter |truncate_result| |
| 356 // indicates an error or not. | 407 // indicates an error or not. |
| 357 file_system_->CloseFile(virtual_path, base::Bind(&DidCloseFileForTruncate, | 408 file_system_->CloseFile(virtual_path, base::Bind(&DidCloseFileForTruncate, |
| 358 callback, | 409 callback, |
| 359 *truncate_result)); | 410 *truncate_result)); |
| 360 } | 411 } |
| 361 | 412 |
| 362 void GDataFileSystemProxy::OpenFile( | 413 void GDataFileSystemProxy::OpenFile( |
| 363 const GURL& file_url, | 414 const GURL& file_url, |
| 364 int file_flags, | 415 int file_flags, |
| 365 base::ProcessHandle peer_handle, | 416 base::ProcessHandle peer_handle, |
| 366 const FileSystemOperationInterface::OpenFileCallback& callback) { | 417 const FileSystemOperationInterface::OpenFileCallback& callback) { |
| 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 368 | 419 |
| 369 FilePath file_path; | 420 FilePath file_path; |
| 370 if (!ValidateUrl(file_url, &file_path)) { | 421 if (!ValidateUrl(file_url, &file_path)) { |
| 371 MessageLoopProxy::current()->PostTask(FROM_HERE, | 422 MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 372 base::Bind(callback, | 423 base::Bind(callback, |
| 373 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 424 base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 374 base::kInvalidPlatformFileValue, | 425 base::kInvalidPlatformFileValue, |
| 375 peer_handle)); | 426 peer_handle)); |
| 376 return; | 427 return; |
| 377 } | 428 } |
| 378 | 429 |
| 379 file_system_->GetFileByPath(file_path, | 430 // TODO(zelidrag): Wire all other file open operations. |
| 380 base::Bind(&OnGetFileByPathForOpen, | 431 if ((file_flags & base::PLATFORM_FILE_CREATE) || |
| 381 callback, | 432 (file_flags & base::PLATFORM_FILE_OPEN_ALWAYS) || |
| 382 file_flags, | 433 (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS) || |
| 383 peer_handle), | 434 (file_flags & base::PLATFORM_FILE_DELETE_ON_CLOSE)) { |
| 384 GetDownloadDataCallback()); | 435 NOTIMPLEMENTED() << "File create/write operations not yet supported " |
| 436 << file_path.value(); | |
| 437 MessageLoopProxy::current()->PostTask(FROM_HERE, | |
| 438 base::Bind(callback, | |
| 439 base::PLATFORM_FILE_ERROR_FAILED, | |
| 440 base::kInvalidPlatformFileValue, | |
| 441 peer_handle)); | |
| 442 return; | |
| 443 } | |
| 444 | |
| 445 if ((file_flags & base::PLATFORM_FILE_OPEN) || | |
| 446 (file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED)) { | |
| 447 if ((file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED) || | |
| 448 (file_flags & base::PLATFORM_FILE_WRITE) || | |
| 449 (file_flags & base::PLATFORM_FILE_EXCLUSIVE_WRITE)) { | |
| 450 // Open existing file for writing. | |
| 451 file_system_->OpenFile( | |
| 452 file_path, | |
| 453 base::Bind(&GDataFileSystemProxy::OnOpenFileForWriting, | |
| 454 this, | |
| 455 file_flags, | |
| 456 peer_handle, | |
| 457 callback)); | |
| 458 } else { | |
| 459 // Read-only file open. | |
| 460 file_system_->GetFileByPath(file_path, | |
| 461 base::Bind(&OnGetFileByPathForOpen, | |
| 462 callback, | |
| 463 file_flags, | |
| 464 peer_handle), | |
| 465 GetDownloadDataCallback()); | |
| 466 } | |
| 467 } else { | |
| 468 // TODO(zelidrag): Wire file create operation. | |
| 469 | |
| 470 NOTREACHED() << "Unhandled file flags combination " << file_flags; | |
| 471 MessageLoopProxy::current()->PostTask(FROM_HERE, | |
| 472 base::Bind(callback, | |
| 473 base::PLATFORM_FILE_ERROR_FAILED, | |
| 474 base::kInvalidPlatformFileValue, | |
| 475 peer_handle)); | |
| 476 } | |
| 477 } | |
| 478 | |
| 479 void GDataFileSystemProxy::NotifyFileClosed( | |
| 480 const GURL& file_url, | |
| 481 const FileSystemOperationInterface::StatusCallback& callback) { | |
| 482 FilePath file_path; | |
| 483 if (!ValidateUrl(file_url, &file_path)) { | |
| 484 MessageLoopProxy::current()->PostTask(FROM_HERE, | |
| 485 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | |
| 486 return; | |
| 487 } | |
| 488 file_system_->CloseFile(file_path, callback); | |
| 385 } | 489 } |
| 386 | 490 |
| 387 void GDataFileSystemProxy::CreateSnapshotFile( | 491 void GDataFileSystemProxy::CreateSnapshotFile( |
| 388 const GURL& file_url, | 492 const GURL& file_url, |
| 389 const FileSystemOperationInterface::SnapshotFileCallback& callback) { | 493 const FileSystemOperationInterface::SnapshotFileCallback& callback) { |
| 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 391 | 495 |
| 392 FilePath file_path; | 496 FilePath file_path; |
| 393 if (!ValidateUrl(file_url, &file_path)) { | 497 if (!ValidateUrl(file_url, &file_path)) { |
| 394 MessageLoopProxy::current()->PostTask(FROM_HERE, | 498 MessageLoopProxy::current()->PostTask(FROM_HERE, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 | 656 |
| 553 void GDataFileSystemProxy::CloseWritableSnapshotFile( | 657 void GDataFileSystemProxy::CloseWritableSnapshotFile( |
| 554 const FilePath& virtual_path, | 658 const FilePath& virtual_path, |
| 555 const FilePath& local_path) { | 659 const FilePath& local_path) { |
| 556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 557 | 661 |
| 558 file_system_->CloseFile(virtual_path, base::Bind(&OnClose, virtual_path)); | 662 file_system_->CloseFile(virtual_path, base::Bind(&OnClose, virtual_path)); |
| 559 } | 663 } |
| 560 | 664 |
| 561 } // namespace gdata | 665 } // namespace gdata |
| OLD | NEW |