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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/sync_file_system/conflict_resolution_resolver.h" 6 7 #include "base/logging.h" 8 #include "base/time/time.h" 9 10 namespace sync_file_system { 11 12 ConflictResolutionResolver::ConflictResolutionResolver( 13 ConflictResolutionPolicy policy) 14 : policy_(policy) {} 15 16 ConflictResolutionResolver::~ConflictResolutionResolver() {} 17 18 ConflictResolution ConflictResolutionResolver::Resolve( 19 SyncFileType local_file_type, 20 const base::Time& local_update_time, 21 SyncFileType remote_file_type, 22 const base::Time& remote_update_time) { 23 // Currently we always prioritize directories over files regardless of 24 // conflict resolution policy. 25 if (remote_file_type == SYNC_FILE_TYPE_DIRECTORY) 26 return CONFLICT_RESOLUTION_REMOTE_WIN; 27 28 if (policy_ == CONFLICT_RESOLUTION_POLICY_MANUAL) 29 return CONFLICT_RESOLUTION_MARK_CONFLICT; 30 31 // Remote time is null, cannot determine the resolution. 32 if (remote_update_time.is_null()) 33 return CONFLICT_RESOLUTION_UNKNOWN; 34 35 // Local time should be always given. 36 DCHECK(!local_update_time.is_null()); 37 38 DCHECK_EQ(CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN, policy_); 39 if (local_update_time >= remote_update_time || 40 remote_file_type == SYNC_FILE_TYPE_UNKNOWN) { 41 return CONFLICT_RESOLUTION_LOCAL_WIN; 42 } 43 44 return CONFLICT_RESOLUTION_REMOTE_WIN; 45 } 46 47 } // namespace sync_file_system 48