Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / conflict_resolution_resolver.cc
blob50fed10823fb74b9e531bf51da55b4daa3bd1c4b
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.
5 #include "chrome/browser/sync_file_system/conflict_resolution_resolver.h"
7 #include "base/logging.h"
8 #include "base/time/time.h"
10 namespace sync_file_system {
12 ConflictResolutionResolver::ConflictResolutionResolver(
13 ConflictResolutionPolicy policy)
14 : policy_(policy) {}
16 ConflictResolutionResolver::~ConflictResolutionResolver() {}
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;
28 if (policy_ == CONFLICT_RESOLUTION_POLICY_MANUAL)
29 return CONFLICT_RESOLUTION_MARK_CONFLICT;
31 // Remote time is null, cannot determine the resolution.
32 if (remote_update_time.is_null())
33 return CONFLICT_RESOLUTION_UNKNOWN;
35 // Local time should be always given.
36 DCHECK(!local_update_time.is_null());
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;
44 return CONFLICT_RESOLUTION_REMOTE_WIN;
47 } // namespace sync_file_system