| 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/sync_file_system/drive_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 const SyncStatusCallback& status_callback, | 82 const SyncStatusCallback& status_callback, |
| 83 const SyncFileCallback& callback, | 83 const SyncFileCallback& callback, |
| 84 SyncStatusCode status, | 84 SyncStatusCode status, |
| 85 const FileSystemURL& url) { | 85 const FileSystemURL& url) { |
| 86 status_callback.Run(status); | 86 status_callback.Run(status); |
| 87 callback.Run(status, url); | 87 callback.Run(status, url); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 const char DriveFileSyncService::kServiceName[] = "syncfs"; | |
| 93 ConflictResolutionPolicy DriveFileSyncService::kDefaultPolicy = | 92 ConflictResolutionPolicy DriveFileSyncService::kDefaultPolicy = |
| 94 CONFLICT_RESOLUTION_LAST_WRITE_WIN; | 93 CONFLICT_RESOLUTION_LAST_WRITE_WIN; |
| 95 | 94 |
| 96 struct DriveFileSyncService::ProcessRemoteChangeParam { | 95 struct DriveFileSyncService::ProcessRemoteChangeParam { |
| 97 RemoteChangeHandler::RemoteChange remote_change; | 96 RemoteChangeHandler::RemoteChange remote_change; |
| 98 SyncFileCallback callback; | 97 SyncFileCallback callback; |
| 99 | 98 |
| 100 DriveMetadata drive_metadata; | 99 DriveMetadata drive_metadata; |
| 101 SyncFileMetadata local_metadata; | 100 SyncFileMetadata local_metadata; |
| 102 bool metadata_updated; | 101 bool metadata_updated; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 241 } |
| 243 return metadata.conflicted(); | 242 return metadata.conflicted(); |
| 244 } | 243 } |
| 245 | 244 |
| 246 RemoteServiceState DriveFileSyncService::GetCurrentState() const { | 245 RemoteServiceState DriveFileSyncService::GetCurrentState() const { |
| 247 if (!sync_enabled_) | 246 if (!sync_enabled_) |
| 248 return REMOTE_SERVICE_DISABLED; | 247 return REMOTE_SERVICE_DISABLED; |
| 249 return state_; | 248 return state_; |
| 250 } | 249 } |
| 251 | 250 |
| 252 const char* DriveFileSyncService::GetServiceName() const { | |
| 253 return kServiceName; | |
| 254 } | |
| 255 | |
| 256 void DriveFileSyncService::SetSyncEnabled(bool enabled) { | 251 void DriveFileSyncService::SetSyncEnabled(bool enabled) { |
| 257 if (sync_enabled_ == enabled) | 252 if (sync_enabled_ == enabled) |
| 258 return; | 253 return; |
| 259 | 254 |
| 260 RemoteServiceState old_state = GetCurrentState(); | 255 RemoteServiceState old_state = GetCurrentState(); |
| 261 sync_enabled_ = enabled; | 256 sync_enabled_ = enabled; |
| 262 if (old_state == GetCurrentState()) | 257 if (old_state == GetCurrentState()) |
| 263 return; | 258 return; |
| 264 | 259 |
| 265 const char* status_message = enabled ? "Sync is enabled" : "Sync is disabled"; | 260 const char* status_message = enabled ? "Sync is enabled" : "Sync is disabled"; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 remote_change_handler_.GetChange(&remote_change); | 574 remote_change_handler_.GetChange(&remote_change); |
| 580 DCHECK(has_remote_change); | 575 DCHECK(has_remote_change); |
| 581 | 576 |
| 582 DVLOG(1) << "ProcessRemoteChange for " << remote_change.url.DebugString() | 577 DVLOG(1) << "ProcessRemoteChange for " << remote_change.url.DebugString() |
| 583 << " remote_change:" << remote_change.change.DebugString(); | 578 << " remote_change:" << remote_change.change.DebugString(); |
| 584 | 579 |
| 585 scoped_ptr<ProcessRemoteChangeParam> param(new ProcessRemoteChangeParam( | 580 scoped_ptr<ProcessRemoteChangeParam> param(new ProcessRemoteChangeParam( |
| 586 remote_change, callback)); | 581 remote_change, callback)); |
| 587 remote_change_processor_->PrepareForProcessRemoteChange( | 582 remote_change_processor_->PrepareForProcessRemoteChange( |
| 588 remote_change.url, | 583 remote_change.url, |
| 589 kServiceName, | |
| 590 base::Bind(&DriveFileSyncService::DidPrepareForProcessRemoteChange, | 584 base::Bind(&DriveFileSyncService::DidPrepareForProcessRemoteChange, |
| 591 AsWeakPtr(), base::Passed(¶m))); | 585 AsWeakPtr(), base::Passed(¶m))); |
| 592 } | 586 } |
| 593 | 587 |
| 594 void DriveFileSyncService::DoApplyLocalChange( | 588 void DriveFileSyncService::DoApplyLocalChange( |
| 595 const FileChange& local_file_change, | 589 const FileChange& local_file_change, |
| 596 const base::FilePath& local_file_path, | 590 const base::FilePath& local_file_path, |
| 597 const SyncFileMetadata& local_file_metadata, | 591 const SyncFileMetadata& local_file_metadata, |
| 598 const FileSystemURL& url, | 592 const FileSystemURL& url, |
| 599 const SyncStatusCallback& callback) { | 593 const SyncStatusCallback& callback) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 | 763 |
| 770 // Save to be fetched file to DB for restore in case of crash. | 764 // Save to be fetched file to DB for restore in case of crash. |
| 771 DriveMetadata metadata; | 765 DriveMetadata metadata; |
| 772 metadata.set_resource_id(entry.resource_id()); | 766 metadata.set_resource_id(entry.resource_id()); |
| 773 metadata.set_md5_checksum(std::string()); | 767 metadata.set_md5_checksum(std::string()); |
| 774 metadata.set_conflicted(false); | 768 metadata.set_conflicted(false); |
| 775 metadata.set_to_be_fetched(true); | 769 metadata.set_to_be_fetched(true); |
| 776 | 770 |
| 777 base::FilePath path = TitleToPath(entry.title()); | 771 base::FilePath path = TitleToPath(entry.title()); |
| 778 fileapi::FileSystemURL url(CreateSyncableFileSystemURL( | 772 fileapi::FileSystemURL url(CreateSyncableFileSystemURL( |
| 779 origin, kServiceName, path)); | 773 origin, path)); |
| 780 // TODO(calvinlo): Write metadata and origin data as single batch command | 774 // TODO(calvinlo): Write metadata and origin data as single batch command |
| 781 // so it's not possible for the DB to contain a DriveMetadata with an | 775 // so it's not possible for the DB to contain a DriveMetadata with an |
| 782 // unknown origin. | 776 // unknown origin. |
| 783 metadata_store_->UpdateEntry(url, metadata, | 777 metadata_store_->UpdateEntry(url, metadata, |
| 784 base::Bind(&EmptyStatusCallback)); | 778 base::Bind(&EmptyStatusCallback)); |
| 785 } | 779 } |
| 786 | 780 |
| 787 GURL next_feed_url; | 781 GURL next_feed_url; |
| 788 if (feed->GetNextFeedURL(&next_feed_url)) { | 782 if (feed->GetNextFeedURL(&next_feed_url)) { |
| 789 api_util_->ContinueListing( | 783 api_util_->ContinueListing( |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 bool DriveFileSyncService::AppendRemoteChangeInternal( | 1278 bool DriveFileSyncService::AppendRemoteChangeInternal( |
| 1285 const GURL& origin, | 1279 const GURL& origin, |
| 1286 const base::FilePath& path, | 1280 const base::FilePath& path, |
| 1287 bool is_deleted, | 1281 bool is_deleted, |
| 1288 const std::string& remote_resource_id, | 1282 const std::string& remote_resource_id, |
| 1289 int64 changestamp, | 1283 int64 changestamp, |
| 1290 const std::string& remote_file_md5, | 1284 const std::string& remote_file_md5, |
| 1291 const base::Time& updated_time, | 1285 const base::Time& updated_time, |
| 1292 SyncFileType file_type, | 1286 SyncFileType file_type, |
| 1293 RemoteChangeHandler::RemoteSyncType sync_type) { | 1287 RemoteChangeHandler::RemoteSyncType sync_type) { |
| 1294 fileapi::FileSystemURL url( | 1288 fileapi::FileSystemURL url(CreateSyncableFileSystemURL(origin, path)); |
| 1295 CreateSyncableFileSystemURL(origin, kServiceName, path)); | |
| 1296 DCHECK(url.is_valid()); | 1289 DCHECK(url.is_valid()); |
| 1297 | 1290 |
| 1298 // Note that we create a normalized path from url.path() rather than | 1291 // Note that we create a normalized path from url.path() rather than |
| 1299 // path here (as FileSystemURL does extra normalization). | 1292 // path here (as FileSystemURL does extra normalization). |
| 1300 base::FilePath::StringType normalized_path = | 1293 base::FilePath::StringType normalized_path = |
| 1301 fileapi::VirtualPath::GetNormalizedFilePath(url.path()); | 1294 fileapi::VirtualPath::GetNormalizedFilePath(url.path()); |
| 1302 | 1295 |
| 1303 std::string local_resource_id; | 1296 std::string local_resource_id; |
| 1304 std::string local_file_md5; | 1297 std::string local_file_md5; |
| 1305 | 1298 |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 metadata_store_->SetOriginRootDirectory(origin, resource_id); | 1727 metadata_store_->SetOriginRootDirectory(origin, resource_id); |
| 1735 } | 1728 } |
| 1736 callback.Run(status, resource_id); | 1729 callback.Run(status, resource_id); |
| 1737 } | 1730 } |
| 1738 | 1731 |
| 1739 std::string DriveFileSyncService::sync_root_resource_id() { | 1732 std::string DriveFileSyncService::sync_root_resource_id() { |
| 1740 return metadata_store_->sync_root_directory(); | 1733 return metadata_store_->sync_root_directory(); |
| 1741 } | 1734 } |
| 1742 | 1735 |
| 1743 } // namespace sync_file_system | 1736 } // namespace sync_file_system |
| OLD | NEW |