conflict_resolver.h revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_ 7 8#include <string> 9#include <utility> 10#include <vector> 11 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/gdata_errorcode.h" 17 18namespace drive { 19class DriveServiceInterface; 20} 21 22namespace google_apis { 23class ResourceEntry; 24} 25 26namespace sync_file_system { 27namespace drive_backend { 28 29class MetadataDatabase; 30class SyncEngineContext; 31class TrackerIDSet; 32 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. 39class ConflictResolver : public ExclusiveTask { 40 public: 41 typedef std::vector<std::string> FileIDList; 42 43 explicit ConflictResolver(SyncEngineContext* sync_context); 44 virtual ~ConflictResolver(); 45 virtual void RunExclusive(const SyncStatusCallback& callback) OVERRIDE; 46 47 private: 48 typedef std::pair<std::string, std::string> FileIDAndETag; 49 50 void DetachFromNonPrimaryParents(const SyncStatusCallback& callback); 51 void DidDetachFromParent(const SyncStatusCallback& callback, 52 google_apis::GDataErrorCode error); 53 54 std::string PickPrimaryFile(const TrackerIDSet& trackers); 55 void RemoveNonPrimaryFiles(const SyncStatusCallback& callback); 56 void DidRemoveFile(const SyncStatusCallback& callback, 57 const std::string& file_id, 58 google_apis::GDataErrorCode error); 59 60 void UpdateFileMetadata(const std::string& file_id, 61 const SyncStatusCallback& callback); 62 void DidGetRemoteMetadata(const std::string& file_id, 63 const SyncStatusCallback& callback, 64 google_apis::GDataErrorCode error, 65 scoped_ptr<google_apis::ResourceEntry> entry); 66 67 std::string target_file_id_; 68 std::vector<std::string> parents_to_remove_; 69 70 std::vector<FileIDAndETag> non_primary_file_ids_; 71 FileIDList deleted_file_ids_; 72 73 bool IsContextReady(); 74 drive::DriveServiceInterface* drive_service(); 75 MetadataDatabase* metadata_database(); 76 77 SyncEngineContext* sync_context_; // Not owned. 78 79 base::WeakPtrFactory<ConflictResolver> weak_ptr_factory_; 80 81 DISALLOW_COPY_AND_ASSIGN(ConflictResolver); 82}; 83 84} // namespace drive_backend 85} // namespace sync_file_system 86 87#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_ 88