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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_context.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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/sync_file_system/local/local_file_sync_context.h" 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 void LocalFileSyncContext::HandleRemoteAddOrUpdate( 327 void LocalFileSyncContext::HandleRemoteAddOrUpdate(
328 FileSystemContext* file_system_context, 328 FileSystemContext* file_system_context,
329 const FileChange& change, 329 const FileChange& change,
330 const base::FilePath& local_path, 330 const base::FilePath& local_path,
331 const FileSystemURL& url, 331 const FileSystemURL& url,
332 const SyncStatusCallback& callback) { 332 const SyncStatusCallback& callback) {
333 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( 333 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync(
334 file_system_context, url); 334 file_system_context, url);
335 335
336 if (fileapi::VirtualPath::IsRootPath(url.path())) { 336 if (fileapi::VirtualPath::IsRootPath(url.path())) {
337 DidApplyRemoteChange(url, callback, base::PLATFORM_FILE_OK); 337 DidApplyRemoteChange(url, callback, base::File::FILE_OK);
338 return; 338 return;
339 } 339 }
340 340
341 file_system_context->operation_runner()->Remove( 341 file_system_context->operation_runner()->Remove(
342 url_for_sync, true /* recursive */, 342 url_for_sync, true /* recursive */,
343 base::Bind( 343 base::Bind(
344 &LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate, 344 &LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate,
345 this, 345 this,
346 make_scoped_refptr(file_system_context), 346 make_scoped_refptr(file_system_context),
347 change, 347 change,
348 local_path, 348 local_path,
349 url, 349 url,
350 callback)); 350 callback));
351 } 351 }
352 352
353 void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate( 353 void LocalFileSyncContext::DidRemoveExistingEntryForRemoteAddOrUpdate(
354 FileSystemContext* file_system_context, 354 FileSystemContext* file_system_context,
355 const FileChange& change, 355 const FileChange& change,
356 const base::FilePath& local_path, 356 const base::FilePath& local_path,
357 const FileSystemURL& url, 357 const FileSystemURL& url,
358 const SyncStatusCallback& callback, 358 const SyncStatusCallback& callback,
359 base::PlatformFileError error) { 359 base::File::Error error) {
360 // Remove() may fail if the target entry does not exist (which is ok), 360 // Remove() may fail if the target entry does not exist (which is ok),
361 // so we ignore |error| here. 361 // so we ignore |error| here.
362 362
363 if (shutdown_on_io_) { 363 if (shutdown_on_io_) {
364 callback.Run(SYNC_FILE_ERROR_ABORT); 364 callback.Run(SYNC_FILE_ERROR_ABORT);
365 return; 365 return;
366 } 366 }
367 367
368 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 368 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
369 DCHECK(!sync_status()->IsWritable(url)); 369 DCHECK(!sync_status()->IsWritable(url));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 root_delete_helper_.reset(); 615 root_delete_helper_.reset();
616 sync_status_.reset(); 616 sync_status_.reset();
617 timer_on_io_.reset(); 617 timer_on_io_.reset();
618 } 618 }
619 619
620 void LocalFileSyncContext::InitializeFileSystemContextOnIOThread( 620 void LocalFileSyncContext::InitializeFileSystemContextOnIOThread(
621 const GURL& source_url, 621 const GURL& source_url,
622 FileSystemContext* file_system_context, 622 FileSystemContext* file_system_context,
623 const GURL& /* root */, 623 const GURL& /* root */,
624 const std::string& /* name */, 624 const std::string& /* name */,
625 base::PlatformFileError error) { 625 base::File::Error error) {
626 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 626 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
627 if (shutdown_on_io_) 627 if (shutdown_on_io_)
628 error = base::PLATFORM_FILE_ERROR_ABORT; 628 error = base::File::FILE_ERROR_ABORT;
629 if (error != base::PLATFORM_FILE_OK) { 629 if (error != base::File::FILE_OK) {
630 DidInitialize(source_url, file_system_context, 630 DidInitialize(source_url, file_system_context,
631 PlatformFileErrorToSyncStatusCode(error)); 631 FileErrorToSyncStatusCode(error));
632 return; 632 return;
633 } 633 }
634 DCHECK(file_system_context); 634 DCHECK(file_system_context);
635 SyncFileSystemBackend* backend = 635 SyncFileSystemBackend* backend =
636 SyncFileSystemBackend::GetBackend(file_system_context); 636 SyncFileSystemBackend::GetBackend(file_system_context);
637 DCHECK(backend); 637 DCHECK(backend);
638 if (!backend->change_tracker()) { 638 if (!backend->change_tracker()) {
639 // Create and initialize LocalFileChangeTracker and call back this method 639 // Create and initialize LocalFileChangeTracker and call back this method
640 // later again. 640 // later again.
641 std::set<GURL>* origins_with_changes = new std::set<GURL>; 641 std::set<GURL>* origins_with_changes = new std::set<GURL>;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 SyncFileSystemBackend::GetBackend(file_system_context); 718 SyncFileSystemBackend::GetBackend(file_system_context);
719 DCHECK(backend); 719 DCHECK(backend);
720 backend->SetLocalFileChangeTracker(tracker_ptr->Pass()); 720 backend->SetLocalFileChangeTracker(tracker_ptr->Pass());
721 721
722 origins_with_pending_changes_.insert(origins_with_changes->begin(), 722 origins_with_pending_changes_.insert(origins_with_changes->begin(),
723 origins_with_changes->end()); 723 origins_with_changes->end());
724 ScheduleNotifyChangesUpdatedOnIOThread(); 724 ScheduleNotifyChangesUpdatedOnIOThread();
725 725
726 InitializeFileSystemContextOnIOThread(source_url, file_system_context, 726 InitializeFileSystemContextOnIOThread(source_url, file_system_context,
727 GURL(), std::string(), 727 GURL(), std::string(),
728 base::PLATFORM_FILE_OK); 728 base::File::FILE_OK);
729 } 729 }
730 730
731 void LocalFileSyncContext::DidInitialize( 731 void LocalFileSyncContext::DidInitialize(
732 const GURL& source_url, 732 const GURL& source_url,
733 FileSystemContext* file_system_context, 733 FileSystemContext* file_system_context,
734 SyncStatusCode status) { 734 SyncStatusCode status) {
735 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { 735 if (!ui_task_runner_->RunsTasksOnCurrentThread()) {
736 ui_task_runner_->PostTask( 736 ui_task_runner_->PostTask(
737 FROM_HERE, 737 FROM_HERE,
738 base::Bind(&LocalFileSyncContext::DidInitialize, 738 base::Bind(&LocalFileSyncContext::DidInitialize,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 846 }
847 847
848 SyncFileSystemBackend* backend = 848 SyncFileSystemBackend* backend =
849 SyncFileSystemBackend::GetBackend(file_system_context); 849 SyncFileSystemBackend::GetBackend(file_system_context);
850 DCHECK(backend); 850 DCHECK(backend);
851 DCHECK(backend->change_tracker()); 851 DCHECK(backend->change_tracker());
852 FileChangeList changes; 852 FileChangeList changes;
853 backend->change_tracker()->GetChangesForURL(url, &changes); 853 backend->change_tracker()->GetChangesForURL(url, &changes);
854 854
855 base::FilePath platform_path; 855 base::FilePath platform_path;
856 base::PlatformFileInfo file_info; 856 base::File::Info file_info;
857 FileSystemFileUtil* file_util = 857 FileSystemFileUtil* file_util =
858 file_system_context->sandbox_delegate()->sync_file_util(); 858 file_system_context->sandbox_delegate()->sync_file_util();
859 DCHECK(file_util); 859 DCHECK(file_util);
860 860
861 base::PlatformFileError file_error = file_util->GetFileInfo( 861 base::File::Error file_error = file_util->GetFileInfo(
862 make_scoped_ptr( 862 make_scoped_ptr(
863 new FileSystemOperationContext(file_system_context)).get(), 863 new FileSystemOperationContext(file_system_context)).get(),
864 url, 864 url,
865 &file_info, 865 &file_info,
866 &platform_path); 866 &platform_path);
867 867
868 webkit_blob::ScopedFile snapshot; 868 webkit_blob::ScopedFile snapshot;
869 if (file_error == base::PLATFORM_FILE_OK && sync_mode == SYNC_SNAPSHOT) { 869 if (file_error == base::File::FILE_OK && sync_mode == SYNC_SNAPSHOT) {
870 base::FilePath snapshot_path; 870 base::FilePath snapshot_path;
871 base::CreateTemporaryFileInDir(local_base_path_.Append(kSnapshotDir), 871 base::CreateTemporaryFileInDir(local_base_path_.Append(kSnapshotDir),
872 &snapshot_path); 872 &snapshot_path);
873 if (base::CopyFile(platform_path, snapshot_path)) { 873 if (base::CopyFile(platform_path, snapshot_path)) {
874 platform_path = snapshot_path; 874 platform_path = snapshot_path;
875 snapshot = webkit_blob::ScopedFile( 875 snapshot = webkit_blob::ScopedFile(
876 snapshot_path, 876 snapshot_path,
877 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT, 877 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT,
878 file_system_context->default_file_task_runner()); 878 file_system_context->default_file_task_runner());
879 } 879 }
880 } 880 }
881 881
882 if (status == SYNC_STATUS_OK && 882 if (status == SYNC_STATUS_OK &&
883 file_error != base::PLATFORM_FILE_OK && 883 file_error != base::File::FILE_OK &&
884 file_error != base::PLATFORM_FILE_ERROR_NOT_FOUND) 884 file_error != base::File::FILE_ERROR_NOT_FOUND) {
885 status = PlatformFileErrorToSyncStatusCode(file_error); 885 status = FileErrorToSyncStatusCode(file_error);
886 }
886 887
887 DCHECK(!file_info.is_symbolic_link); 888 DCHECK(!file_info.is_symbolic_link);
888 889
889 SyncFileType file_type = SYNC_FILE_TYPE_FILE; 890 SyncFileType file_type = SYNC_FILE_TYPE_FILE;
890 if (file_error == base::PLATFORM_FILE_ERROR_NOT_FOUND) 891 if (file_error == base::File::FILE_ERROR_NOT_FOUND)
891 file_type = SYNC_FILE_TYPE_UNKNOWN; 892 file_type = SYNC_FILE_TYPE_UNKNOWN;
892 else if (file_info.is_directory) 893 else if (file_info.is_directory)
893 file_type = SYNC_FILE_TYPE_DIRECTORY; 894 file_type = SYNC_FILE_TYPE_DIRECTORY;
894 895
895 LocalFileSyncInfo sync_file_info; 896 LocalFileSyncInfo sync_file_info;
896 sync_file_info.url = url; 897 sync_file_info.url = url;
897 sync_file_info.local_file_path = platform_path; 898 sync_file_info.local_file_path = platform_path;
898 sync_file_info.metadata.file_type = file_type; 899 sync_file_info.metadata.file_type = file_type;
899 sync_file_info.metadata.size = file_info.size; 900 sync_file_info.metadata.size = file_info.size;
900 sync_file_info.metadata.last_modified = file_info.last_modified; 901 sync_file_info.metadata.last_modified = file_info.last_modified;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return; 948 return;
948 sync_status()->EndWriting(url); 949 sync_status()->EndWriting(url);
949 950
950 // Since a sync has finished the number of changes must have been updated. 951 // Since a sync has finished the number of changes must have been updated.
951 UpdateChangesForOrigin(url.origin()); 952 UpdateChangesForOrigin(url.origin());
952 } 953 }
953 954
954 void LocalFileSyncContext::DidApplyRemoteChange( 955 void LocalFileSyncContext::DidApplyRemoteChange(
955 const FileSystemURL& url, 956 const FileSystemURL& url,
956 const SyncStatusCallback& callback_on_ui, 957 const SyncStatusCallback& callback_on_ui,
957 base::PlatformFileError file_error) { 958 base::File::Error file_error) {
958 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 959 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
959 root_delete_helper_.reset(); 960 root_delete_helper_.reset();
960 ui_task_runner_->PostTask( 961 ui_task_runner_->PostTask(
961 FROM_HERE, 962 FROM_HERE,
962 base::Bind(callback_on_ui, 963 base::Bind(callback_on_ui, FileErrorToSyncStatusCode(file_error)));
963 PlatformFileErrorToSyncStatusCode(file_error)));
964 } 964 }
965 965
966 void LocalFileSyncContext::DidGetFileMetadata( 966 void LocalFileSyncContext::DidGetFileMetadata(
967 const SyncFileMetadataCallback& callback, 967 const SyncFileMetadataCallback& callback,
968 base::PlatformFileError file_error, 968 base::File::Error file_error,
969 const base::PlatformFileInfo& file_info) { 969 const base::File::Info& file_info) {
970 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 970 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
971 SyncFileMetadata metadata; 971 SyncFileMetadata metadata;
972 if (file_error == base::PLATFORM_FILE_OK) { 972 if (file_error == base::File::FILE_OK) {
973 metadata.file_type = file_info.is_directory ? 973 metadata.file_type = file_info.is_directory ?
974 SYNC_FILE_TYPE_DIRECTORY : SYNC_FILE_TYPE_FILE; 974 SYNC_FILE_TYPE_DIRECTORY : SYNC_FILE_TYPE_FILE;
975 metadata.size = file_info.size; 975 metadata.size = file_info.size;
976 metadata.last_modified = file_info.last_modified; 976 metadata.last_modified = file_info.last_modified;
977 } 977 }
978 ui_task_runner_->PostTask( 978 ui_task_runner_->PostTask(
979 FROM_HERE, 979 FROM_HERE,
980 base::Bind(callback, 980 base::Bind(callback, FileErrorToSyncStatusCode(file_error), metadata));
981 PlatformFileErrorToSyncStatusCode(file_error),
982 metadata));
983 } 981 }
984 982
985 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { 983 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() {
986 if (mock_notify_changes_duration_in_sec_ >= 0) 984 if (mock_notify_changes_duration_in_sec_ >= 0)
987 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); 985 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_);
988 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); 986 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec);
989 } 987 }
990 988
991 void LocalFileSyncContext::DidCreateDirectoryForCopyIn( 989 void LocalFileSyncContext::DidCreateDirectoryForCopyIn(
992 FileSystemContext* file_system_context, 990 FileSystemContext* file_system_context,
993 const base::FilePath& local_path, 991 const base::FilePath& local_path,
994 const FileSystemURL& dest_url, 992 const FileSystemURL& dest_url,
995 const StatusCallback& callback, 993 const StatusCallback& callback,
996 base::PlatformFileError error) { 994 base::File::Error error) {
997 if (error != base::PLATFORM_FILE_OK) { 995 if (error != base::File::FILE_OK) {
998 callback.Run(error); 996 callback.Run(error);
999 return; 997 return;
1000 } 998 }
1001 999
1002 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( 1000 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync(
1003 file_system_context, dest_url); 1001 file_system_context, dest_url);
1004 file_system_context->operation_runner()->CopyInForeignFile( 1002 file_system_context->operation_runner()->CopyInForeignFile(
1005 local_path, url_for_sync, callback); 1003 local_path, url_for_sync, callback);
1006 } 1004 }
1007 1005
1008 } // namespace sync_file_system 1006 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698