Rename gdata_errorcode.h to drive_api_error_codes.h
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / conflict_resolver.h
blobe0cfef747befef3c3fe960cb02972f9ef7cead3f
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_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h"
15 #include "chrome/browser/sync_file_system/sync_callbacks.h"
16 #include "google_apis/drive/drive_api_error_codes.h"
18 namespace drive {
19 class DriveServiceInterface;
22 namespace google_apis {
23 class FileResource;
26 namespace sync_file_system {
27 namespace drive_backend {
29 class MetadataDatabase;
30 class SyncEngineContext;
31 class TrackerIDSet;
33 // Resolves server side file confliction.
34 // If a remote file has an active tracker and multiple managed parents,
35 // ConflictResolver detaches the file from all parents other than the parent
36 // of the active tracker.
37 // If multiple trackers have the same local path or the same remote file,
38 // ConflictResolver picks up one of them and delete others.
39 class ConflictResolver : public SyncTask {
40 public:
41 typedef std::vector<std::string> FileIDList;
43 explicit ConflictResolver(SyncEngineContext* sync_context);
44 ~ConflictResolver() override;
45 void RunPreflight(scoped_ptr<SyncTaskToken> token) override;
46 void RunExclusive(scoped_ptr<SyncTaskToken> token);
48 private:
49 typedef std::pair<std::string, std::string> FileIDAndETag;
51 void DetachFromNonPrimaryParents(scoped_ptr<SyncTaskToken> token);
52 void DidDetachFromParent(scoped_ptr<SyncTaskToken> token,
53 google_apis::DriveApiErrorCode error);
55 std::string PickPrimaryFile(const TrackerIDSet& trackers);
56 void RemoveNonPrimaryFiles(scoped_ptr<SyncTaskToken> token);
57 void DidRemoveFile(scoped_ptr<SyncTaskToken> token,
58 const std::string& file_id,
59 google_apis::DriveApiErrorCode error);
61 void UpdateFileMetadata(const std::string& file_id,
62 scoped_ptr<SyncTaskToken> token);
63 void DidGetRemoteMetadata(const std::string& file_id,
64 scoped_ptr<SyncTaskToken> token,
65 google_apis::DriveApiErrorCode error,
66 scoped_ptr<google_apis::FileResource> entry);
68 std::string target_file_id_;
69 std::vector<std::string> parents_to_remove_;
71 std::vector<FileIDAndETag> non_primary_file_ids_;
72 FileIDList deleted_file_ids_;
74 bool IsContextReady();
75 drive::DriveServiceInterface* drive_service();
76 MetadataDatabase* metadata_database();
78 SyncEngineContext* sync_context_; // Not owned.
80 base::WeakPtrFactory<ConflictResolver> weak_ptr_factory_;
82 DISALLOW_COPY_AND_ASSIGN(ConflictResolver);
85 } // namespace drive_backend
86 } // namespace sync_file_system
88 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_