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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 base::PlatformFileError* open_error) { | 43 base::PlatformFileError* open_error) { |
44 bool created; | 44 bool created; |
45 *platform_file = base::CreatePlatformFile(local_path, | 45 *platform_file = base::CreatePlatformFile(local_path, |
46 file_flags, | 46 file_flags, |
47 &created, | 47 &created, |
48 open_error); | 48 open_error); |
49 } | 49 } |
50 | 50 |
51 // Helper function to run reply on results of OpenPlatformFileOnIOPool() on | 51 // Helper function to run reply on results of OpenPlatformFileOnIOPool() on |
52 // IO thread. | 52 // IO thread. |
53 void OnPlatformFileOpened( | 53 void OnPlatformFileOpened( |
kochi
2012/08/08 10:59:38
Can you move these top-level functions into
gdata:
Haruki Sato
2012/08/09 04:22:04
Done.
Thank you for the helpful adivce.
It is actu
| |
54 const FileSystemOperationInterface::OpenFileCallback& callback, | 54 const FileSystemOperationInterface::OpenFileCallback& callback, |
55 base::ProcessHandle peer_handle, | 55 base::ProcessHandle peer_handle, |
56 base::PlatformFile* platform_file, | 56 base::PlatformFile* platform_file, |
57 base::PlatformFileError* open_error) { | 57 base::PlatformFileError* open_error) { |
58 callback.Run(*open_error, *platform_file, peer_handle); | 58 callback.Run(*open_error, *platform_file, peer_handle); |
59 } | 59 } |
60 | 60 |
61 // Helper function to run OpenFileCallback from | 61 // Helper function to run OpenFileCallback from |
62 // GDataFileSystemProxy::OpenFile(). | 62 // GDataFileSystemProxy::OpenFile(). |
63 void OnGetFileByPathForOpen( | 63 void OnGetFileByPathForOpen( |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 | 359 |
360 void GDataFileSystemProxy::OnOpenFileForWriting( | 360 void GDataFileSystemProxy::OnOpenFileForWriting( |
361 int file_flags, | 361 int file_flags, |
362 base::ProcessHandle peer_handle, | 362 base::ProcessHandle peer_handle, |
363 const FileSystemOperationInterface::OpenFileCallback& callback, | 363 const FileSystemOperationInterface::OpenFileCallback& callback, |
364 GDataFileError gdata_error, | 364 GDataFileError gdata_error, |
365 const FilePath& local_cache_path) { | 365 const FilePath& local_cache_path) { |
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
367 | 367 |
368 base::PlatformFileError error = | 368 base::PlatformFileError error = |
369 gdata::util::GDataFileErrorToPlatformError(gdata_error); | 369 util::GDataFileErrorToPlatformError(gdata_error); |
370 | 370 |
371 if (error != base::PLATFORM_FILE_OK) { | 371 if (error != base::PLATFORM_FILE_OK) { |
372 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); | 372 callback.Run(error, base::kInvalidPlatformFileValue, peer_handle); |
373 return; | 373 return; |
374 } | 374 } |
375 | 375 |
376 // Cache file prepared for modification is available. Truncate it. | 376 // Cache file prepared for modification is available. Truncate it. |
377 // File operation must be done on FILE thread, so relay the operation. | 377 // File operation must be done on FILE thread, so relay the operation. |
378 base::PlatformFileError* result = | 378 base::PlatformFileError* result = |
379 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); | 379 new base::PlatformFileError(base::PLATFORM_FILE_ERROR_FAILED); |
(...skipping 14 matching lines...) Expand all Loading... | |
394 } | 394 } |
395 | 395 |
396 void GDataFileSystemProxy::OnCreateFileForOpen( | 396 void GDataFileSystemProxy::OnCreateFileForOpen( |
397 const FilePath& file_path, | 397 const FilePath& file_path, |
398 int file_flags, | 398 int file_flags, |
399 base::ProcessHandle peer_handle, | 399 base::ProcessHandle peer_handle, |
400 const FileSystemOperationInterface::OpenFileCallback& callback, | 400 const FileSystemOperationInterface::OpenFileCallback& callback, |
401 GDataFileError gdata_error) { | 401 GDataFileError gdata_error) { |
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
403 base::PlatformFileError create_result = | 403 base::PlatformFileError create_result = |
404 gdata::util::GDataFileErrorToPlatformError(gdata_error); | 404 util::GDataFileErrorToPlatformError(gdata_error); |
405 | 405 |
406 if ((create_result == base::PLATFORM_FILE_OK) || | 406 if ((create_result == base::PLATFORM_FILE_OK) || |
407 ((create_result == base::PLATFORM_FILE_ERROR_EXISTS) && | 407 ((create_result == base::PLATFORM_FILE_ERROR_EXISTS) && |
408 (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS))) { | 408 (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS))) { |
409 // If we are trying to always create an existing file, then | 409 // If we are trying to always create an existing file, then |
410 // if it really exists open it as truncated. | 410 // if it really exists open it as truncated. |
411 file_flags &= ~base::PLATFORM_FILE_CREATE; | 411 file_flags &= ~base::PLATFORM_FILE_CREATE; |
412 file_flags &= ~base::PLATFORM_FILE_CREATE_ALWAYS; | 412 file_flags &= ~base::PLATFORM_FILE_CREATE_ALWAYS; |
413 file_flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; | 413 file_flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; |
414 } else { | 414 } else { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 // what platform you're on. | 643 // what platform you're on. |
644 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeExternal) { | 644 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeExternal) { |
645 return false; | 645 return false; |
646 } | 646 } |
647 *file_path = url.path(); | 647 *file_path = url.path(); |
648 return true; | 648 return true; |
649 } | 649 } |
650 | 650 |
651 void GDataFileSystemProxy::OnStatusCallback( | 651 void GDataFileSystemProxy::OnStatusCallback( |
652 const fileapi::FileSystemOperationInterface::StatusCallback& callback, | 652 const fileapi::FileSystemOperationInterface::StatusCallback& callback, |
653 gdata::GDataFileError error) { | 653 GDataFileError error) { |
654 callback.Run(util::GDataFileErrorToPlatformError(error)); | 654 callback.Run(util::GDataFileErrorToPlatformError(error)); |
655 } | 655 } |
656 | 656 |
657 void GDataFileSystemProxy::OnGetMetadata( | 657 void GDataFileSystemProxy::OnGetMetadata( |
658 const FilePath& file_path, | 658 const FilePath& file_path, |
659 const FileSystemOperationInterface::GetMetadataCallback& callback, | 659 const FileSystemOperationInterface::GetMetadataCallback& callback, |
660 GDataFileError error, | 660 GDataFileError error, |
661 scoped_ptr<gdata::GDataEntryProto> entry_proto) { | 661 scoped_ptr<GDataEntryProto> entry_proto) { |
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
663 | 663 |
664 if (error != GDATA_FILE_OK) { | 664 if (error != GDATA_FILE_OK) { |
665 callback.Run(util::GDataFileErrorToPlatformError(error), | 665 callback.Run(util::GDataFileErrorToPlatformError(error), |
666 base::PlatformFileInfo(), | 666 base::PlatformFileInfo(), |
667 FilePath()); | 667 FilePath()); |
668 return; | 668 return; |
669 } | 669 } |
670 DCHECK(entry_proto.get()); | 670 DCHECK(entry_proto.get()); |
671 | 671 |
672 base::PlatformFileInfo file_info; | 672 base::PlatformFileInfo file_info; |
673 GDataEntry::ConvertProtoToPlatformFileInfo( | 673 GDataEntry::ConvertProtoToPlatformFileInfo( |
674 entry_proto->file_info(), | 674 entry_proto->file_info(), |
675 &file_info); | 675 &file_info); |
676 | 676 |
677 callback.Run(base::PLATFORM_FILE_OK, file_info, file_path); | 677 callback.Run(base::PLATFORM_FILE_OK, file_info, file_path); |
678 } | 678 } |
679 | 679 |
680 void GDataFileSystemProxy::OnReadDirectory( | 680 void GDataFileSystemProxy::OnReadDirectory( |
681 const FileSystemOperationInterface::ReadDirectoryCallback& | 681 const FileSystemOperationInterface::ReadDirectoryCallback& |
682 callback, | 682 callback, |
683 GDataFileError error, | 683 GDataFileError error, |
684 scoped_ptr<gdata::GDataEntryProtoVector> proto_entries) { | 684 scoped_ptr<GDataEntryProtoVector> proto_entries) { |
685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
686 | 686 |
687 PrefService* pref_service = profile_->GetPrefs(); | 687 PrefService* pref_service = profile_->GetPrefs(); |
688 const bool hide_hosted_documents = | 688 const bool hide_hosted_documents = |
689 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | 689 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); |
690 | 690 |
691 if (error != GDATA_FILE_OK) { | 691 if (error != GDATA_FILE_OK) { |
692 callback.Run(util::GDataFileErrorToPlatformError(error), | 692 callback.Run(util::GDataFileErrorToPlatformError(error), |
693 std::vector<base::FileUtilProxy::Entry>(), | 693 std::vector<base::FileUtilProxy::Entry>(), |
694 false); | 694 false); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 | 737 |
738 void GDataFileSystemProxy::CloseWritableSnapshotFile( | 738 void GDataFileSystemProxy::CloseWritableSnapshotFile( |
739 const FilePath& virtual_path, | 739 const FilePath& virtual_path, |
740 const FilePath& local_path) { | 740 const FilePath& local_path) { |
741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
742 | 742 |
743 file_system_->CloseFile(virtual_path, base::Bind(&OnClose, virtual_path)); | 743 file_system_->CloseFile(virtual_path, base::Bind(&OnClose, virtual_path)); |
744 } | 744 } |
745 | 745 |
746 } // namespace gdata | 746 } // namespace gdata |
OLD | NEW |