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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/sync_file_system/sync_callbacks.h"
14 #include "chrome/browser/sync_file_system/sync_task.h"
15 #include "google_apis/drive/gdata_errorcode.h"
18 class DriveServiceInterface
;
21 namespace google_apis
{
25 namespace sync_file_system
{
26 namespace drive_backend
{
28 class MetadataDatabase
;
29 class SyncEngineContext
;
32 // Resolves server side file confliction.
33 // If a remote file has an active tracker and multiple managed parents,
34 // ConflictResolver detaches the file from all parents other than the parent
35 // of the active tracker.
36 // If multiple trackers have the same local path or the same remote file,
37 // ConflictResolver picks up one of them and delete others.
38 class ConflictResolver
: public SyncTask
{
40 typedef std::vector
<std::string
> FileIDList
;
42 explicit ConflictResolver(SyncEngineContext
* sync_context
);
43 virtual ~ConflictResolver();
44 virtual void Run(const SyncStatusCallback
& callback
) OVERRIDE
;
47 typedef std::pair
<std::string
, std::string
> FileIDAndETag
;
49 void DetachFromNonPrimaryParents(const SyncStatusCallback
& callback
);
50 void DidDetachFromParent(const SyncStatusCallback
& callback
,
51 google_apis::GDataErrorCode error
);
53 std::string
PickPrimaryFile(const TrackerSet
& trackers
);
54 void RemoveNonPrimaryFiles(const SyncStatusCallback
& callback
);
55 void DidRemoveFile(const SyncStatusCallback
& callback
,
56 const std::string
& file_id
,
57 google_apis::GDataErrorCode error
);
59 void UpdateFileMetadata(const std::string
& file_id
,
60 const SyncStatusCallback
& callback
);
61 void DidGetRemoteMetadata(const std::string
& file_id
,
62 const SyncStatusCallback
& callback
,
63 google_apis::GDataErrorCode error
,
64 scoped_ptr
<google_apis::ResourceEntry
> entry
);
66 std::string target_file_id_
;
67 std::vector
<std::string
> parents_to_remove_
;
69 std::vector
<FileIDAndETag
> non_primary_file_ids_
;
70 FileIDList deleted_file_ids_
;
72 bool IsContextReady();
73 drive::DriveServiceInterface
* drive_service();
74 MetadataDatabase
* metadata_database();
76 SyncEngineContext
* sync_context_
; // Not owned.
78 base::WeakPtrFactory
<ConflictResolver
> weak_ptr_factory_
;
80 DISALLOW_COPY_AND_ASSIGN(ConflictResolver
);
83 } // namespace drive_backend
84 } // namespace sync_file_system
86 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_