OLD | NEW |
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/drive_backend_v1/drive_file_sync_servi
ce.h" | 5 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi
ce.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/sync_file_system/sync_file_metadata.h" | 31 #include "chrome/browser/sync_file_system/sync_file_metadata.h" |
32 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" | 32 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" |
33 #include "chrome/browser/sync_file_system/sync_file_type.h" | 33 #include "chrome/browser/sync_file_system/sync_file_type.h" |
34 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 34 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "extensions/browser/extension_system.h" | 36 #include "extensions/browser/extension_system.h" |
37 #include "extensions/browser/extension_system_provider.h" | 37 #include "extensions/browser/extension_system_provider.h" |
38 #include "extensions/browser/extensions_browser_client.h" | 38 #include "extensions/browser/extensions_browser_client.h" |
39 #include "extensions/common/constants.h" | 39 #include "extensions/common/constants.h" |
40 #include "extensions/common/extension.h" | 40 #include "extensions/common/extension.h" |
41 #include "webkit/browser/fileapi/file_system_url.h" | 41 #include "storage/browser/fileapi/file_system_url.h" |
42 #include "webkit/common/blob/scoped_file.h" | 42 #include "storage/common/blob/scoped_file.h" |
43 #include "webkit/common/fileapi/file_system_util.h" | 43 #include "storage/common/fileapi/file_system_util.h" |
44 | 44 |
45 using fileapi::FileSystemURL; | 45 using storage::FileSystemURL; |
46 | 46 |
47 namespace sync_file_system { | 47 namespace sync_file_system { |
48 | 48 |
49 typedef RemoteFileSyncService::OriginStatusMap OriginStatusMap; | 49 typedef RemoteFileSyncService::OriginStatusMap OriginStatusMap; |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 const base::FilePath::CharType kTempDirName[] = FILE_PATH_LITERAL("tmp"); | 53 const base::FilePath::CharType kTempDirName[] = FILE_PATH_LITERAL("tmp"); |
54 | 54 |
55 void EmptyStatusCallback(SyncStatusCode status) {} | 55 void EmptyStatusCallback(SyncStatusCode status) {} |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 metadata.set_md5_checksum(std::string()); | 793 metadata.set_md5_checksum(std::string()); |
794 metadata.set_conflicted(false); | 794 metadata.set_conflicted(false); |
795 metadata.set_to_be_fetched(true); | 795 metadata.set_to_be_fetched(true); |
796 | 796 |
797 if (file_type == SYNC_FILE_TYPE_FILE) | 797 if (file_type == SYNC_FILE_TYPE_FILE) |
798 metadata.set_type(DriveMetadata::RESOURCE_TYPE_FILE); | 798 metadata.set_type(DriveMetadata::RESOURCE_TYPE_FILE); |
799 else | 799 else |
800 metadata.set_type(DriveMetadata::RESOURCE_TYPE_FOLDER); | 800 metadata.set_type(DriveMetadata::RESOURCE_TYPE_FOLDER); |
801 | 801 |
802 base::FilePath path = TitleToPath(entry.title()); | 802 base::FilePath path = TitleToPath(entry.title()); |
803 fileapi::FileSystemURL url(CreateSyncableFileSystemURL( | 803 storage::FileSystemURL url(CreateSyncableFileSystemURL(origin, path)); |
804 origin, path)); | |
805 // TODO(calvinlo): Write metadata and origin data as single batch command | 804 // TODO(calvinlo): Write metadata and origin data as single batch command |
806 // so it's not possible for the DB to contain a DriveMetadata with an | 805 // so it's not possible for the DB to contain a DriveMetadata with an |
807 // unknown origin. | 806 // unknown origin. |
808 metadata_store_->UpdateEntry(url, metadata, | 807 metadata_store_->UpdateEntry(url, metadata, |
809 base::Bind(&EmptyStatusCallback)); | 808 base::Bind(&EmptyStatusCallback)); |
810 | 809 |
811 AppendFetchChange(origin, path, entry.resource_id(), file_type); | 810 AppendFetchChange(origin, path, entry.resource_id(), file_type); |
812 } | 811 } |
813 | 812 |
814 GURL next_feed_url; | 813 GURL next_feed_url; |
(...skipping 11 matching lines...) Expand all Loading... |
826 | 825 |
827 metadata_store_->AddIncrementalSyncOrigin(origin, resource_id); | 826 metadata_store_->AddIncrementalSyncOrigin(origin, resource_id); |
828 may_have_unfetched_changes_ = true; | 827 may_have_unfetched_changes_ = true; |
829 callback.Run(SYNC_STATUS_OK); | 828 callback.Run(SYNC_STATUS_OK); |
830 } | 829 } |
831 | 830 |
832 void DriveFileSyncService::DidProcessRemoteChange( | 831 void DriveFileSyncService::DidProcessRemoteChange( |
833 const SyncFileCallback& sync_callback, | 832 const SyncFileCallback& sync_callback, |
834 const SyncStatusCallback& completion_callback, | 833 const SyncStatusCallback& completion_callback, |
835 SyncStatusCode status) { | 834 SyncStatusCode status) { |
836 fileapi::FileSystemURL url; | 835 storage::FileSystemURL url; |
837 if (running_remote_sync_task_) | 836 if (running_remote_sync_task_) |
838 url = running_remote_sync_task_->url(); | 837 url = running_remote_sync_task_->url(); |
839 running_remote_sync_task_.reset(); | 838 running_remote_sync_task_.reset(); |
840 | 839 |
841 completion_callback.Run(status); | 840 completion_callback.Run(status); |
842 sync_callback.Run(status, url); | 841 sync_callback.Run(status, url); |
843 } | 842 } |
844 | 843 |
845 void DriveFileSyncService::DidApplyLocalChange( | 844 void DriveFileSyncService::DidApplyLocalChange( |
846 const SyncStatusCallback& callback, | 845 const SyncStatusCallback& callback, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 | 887 |
889 bool DriveFileSyncService::AppendRemoteChangeInternal( | 888 bool DriveFileSyncService::AppendRemoteChangeInternal( |
890 const GURL& origin, | 889 const GURL& origin, |
891 const base::FilePath& path, | 890 const base::FilePath& path, |
892 bool is_deleted, | 891 bool is_deleted, |
893 const std::string& remote_resource_id, | 892 const std::string& remote_resource_id, |
894 int64 changestamp, | 893 int64 changestamp, |
895 const std::string& remote_file_md5, | 894 const std::string& remote_file_md5, |
896 const base::Time& updated_time, | 895 const base::Time& updated_time, |
897 SyncFileType file_type) { | 896 SyncFileType file_type) { |
898 fileapi::FileSystemURL url(CreateSyncableFileSystemURL(origin, path)); | 897 storage::FileSystemURL url(CreateSyncableFileSystemURL(origin, path)); |
899 DCHECK(url.is_valid()); | 898 DCHECK(url.is_valid()); |
900 | 899 |
901 // Note that we create a normalized path from url.path() rather than | 900 // Note that we create a normalized path from url.path() rather than |
902 // path here (as FileSystemURL does extra normalization). | 901 // path here (as FileSystemURL does extra normalization). |
903 base::FilePath::StringType normalized_path = | 902 base::FilePath::StringType normalized_path = |
904 fileapi::VirtualPath::GetNormalizedFilePath(url.path()); | 903 storage::VirtualPath::GetNormalizedFilePath(url.path()); |
905 | 904 |
906 std::string local_resource_id; | 905 std::string local_resource_id; |
907 std::string local_file_md5; | 906 std::string local_file_md5; |
908 | 907 |
909 DriveMetadata metadata; | 908 DriveMetadata metadata; |
910 bool has_db_entry = | 909 bool has_db_entry = |
911 (metadata_store_->ReadEntry(url, &metadata) == SYNC_STATUS_OK); | 910 (metadata_store_->ReadEntry(url, &metadata) == SYNC_STATUS_OK); |
912 if (has_db_entry) { | 911 if (has_db_entry) { |
913 local_resource_id = metadata.resource_id(); | 912 local_resource_id = metadata.resource_id(); |
914 if (!metadata.to_be_fetched()) | 913 if (!metadata.to_be_fetched()) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 << file_change.DebugString(); | 985 << file_change.DebugString(); |
987 | 986 |
988 return true; | 987 return true; |
989 } | 988 } |
990 | 989 |
991 void DriveFileSyncService::RemoveRemoteChange( | 990 void DriveFileSyncService::RemoveRemoteChange( |
992 const FileSystemURL& url) { | 991 const FileSystemURL& url) { |
993 remote_change_handler_.RemoveChangeForURL(url); | 992 remote_change_handler_.RemoveChangeForURL(url); |
994 } | 993 } |
995 | 994 |
996 void DriveFileSyncService::MarkConflict( | 995 void DriveFileSyncService::MarkConflict(const storage::FileSystemURL& url, |
997 const fileapi::FileSystemURL& url, | 996 DriveMetadata* drive_metadata, |
998 DriveMetadata* drive_metadata, | 997 const SyncStatusCallback& callback) { |
999 const SyncStatusCallback& callback) { | |
1000 DCHECK(drive_metadata); | 998 DCHECK(drive_metadata); |
1001 DCHECK(!drive_metadata->resource_id().empty()); | 999 DCHECK(!drive_metadata->resource_id().empty()); |
1002 drive_metadata->set_conflicted(true); | 1000 drive_metadata->set_conflicted(true); |
1003 drive_metadata->set_to_be_fetched(false); | 1001 drive_metadata->set_to_be_fetched(false); |
1004 metadata_store_->UpdateEntry( | 1002 metadata_store_->UpdateEntry( |
1005 url, *drive_metadata, base::Bind( | 1003 url, *drive_metadata, base::Bind( |
1006 &DriveFileSyncService::NotifyConflict, | 1004 &DriveFileSyncService::NotifyConflict, |
1007 AsWeakPtr(), url, callback)); | 1005 AsWeakPtr(), url, callback)); |
1008 } | 1006 } |
1009 | 1007 |
1010 void DriveFileSyncService::NotifyConflict( | 1008 void DriveFileSyncService::NotifyConflict(const storage::FileSystemURL& url, |
1011 const fileapi::FileSystemURL& url, | 1009 const SyncStatusCallback& callback, |
1012 const SyncStatusCallback& callback, | 1010 SyncStatusCode status) { |
1013 SyncStatusCode status) { | |
1014 if (status != SYNC_STATUS_OK) { | 1011 if (status != SYNC_STATUS_OK) { |
1015 callback.Run(status); | 1012 callback.Run(status); |
1016 return; | 1013 return; |
1017 } | 1014 } |
1018 NotifyObserversFileStatusChanged(url, | 1015 NotifyObserversFileStatusChanged(url, |
1019 SYNC_FILE_STATUS_CONFLICTING, | 1016 SYNC_FILE_STATUS_CONFLICTING, |
1020 SYNC_ACTION_NONE, | 1017 SYNC_ACTION_NONE, |
1021 SYNC_DIRECTION_NONE); | 1018 SYNC_DIRECTION_NONE); |
1022 callback.Run(status); | 1019 callback.Run(status); |
1023 } | 1020 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 metadata_store_->SetOriginRootDirectory(origin, resource_id); | 1326 metadata_store_->SetOriginRootDirectory(origin, resource_id); |
1330 } | 1327 } |
1331 callback.Run(status, resource_id); | 1328 callback.Run(status, resource_id); |
1332 } | 1329 } |
1333 | 1330 |
1334 std::string DriveFileSyncService::sync_root_resource_id() { | 1331 std::string DriveFileSyncService::sync_root_resource_id() { |
1335 return metadata_store_->sync_root_directory(); | 1332 return metadata_store_->sync_root_directory(); |
1336 } | 1333 } |
1337 | 1334 |
1338 } // namespace sync_file_system | 1335 } // namespace sync_file_system |
OLD | NEW |