conflict_resolver.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 <vector> 10 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" 16 17namespace drive { 18class DriveServiceInterface; 19} 20 21namespace google_apis { 22class ResourceEntry; 23} 24 25namespace sync_file_system { 26namespace drive_backend { 27 28class MetadataDatabase; 29class SyncEngineContext; 30class TrackerSet; 31 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. 38class ConflictResolver : public SyncTask { 39 public: 40 explicit ConflictResolver(SyncEngineContext* sync_context); 41 virtual ~ConflictResolver(); 42 virtual void Run(const SyncStatusCallback& callback) OVERRIDE; 43 44 private: 45 typedef std::pair<std::string, std::string> FileIDAndETag; 46 47 void DetachFromNonPrimaryParents(const SyncStatusCallback& callback); 48 void DidDetachFromParent(const SyncStatusCallback& callback, 49 google_apis::GDataErrorCode error); 50 51 std::string PickPrimaryFile(const TrackerSet& trackers); 52 void RemoveNonPrimaryFiles(const SyncStatusCallback& callback); 53 void DidRemoveFile(const SyncStatusCallback& callback, 54 const std::string& file_id, 55 google_apis::GDataErrorCode error); 56 57 std::string target_file_id_; 58 std::vector<std::string> parents_to_remove_; 59 60 std::vector<FileIDAndETag> non_primary_file_ids_; 61 62 bool IsContextReady(); 63 drive::DriveServiceInterface* drive_service(); 64 MetadataDatabase* metadata_database(); 65 66 SyncEngineContext* sync_context_; // Not owned. 67 68 base::WeakPtrFactory<ConflictResolver> weak_ptr_factory_; 69 70 DISALLOW_COPY_AND_ASSIGN(ConflictResolver); 71}; 72 73} // namespace drive_backend 74} // namespace sync_file_system 75 76#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_CONFLICT_RESOLVER_H_ 77