1 // Copyright (c) 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_FAKE_REMOTE_CHANGE_PROCESSOR_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_FAKE_REMOTE_CHANGE_PROCESSOR_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include "base/callback.h" 13 #include "chrome/browser/sync_file_system/remote_change_processor.h" 14 #include "chrome/browser/sync_file_system/sync_callbacks.h" 15 16 namespace base { 17 class FilePath; 18 } 19 20 namespace fileapi { 21 class FileSystemURL; 22 } 23 24 namespace sync_file_system { 25 26 class FileChange; 27 28 class FakeRemoteChangeProcessor : public RemoteChangeProcessor { 29 public: 30 typedef std::map<fileapi::FileSystemURL, std::vector<FileChange>, 31 fileapi::FileSystemURL::Comparator> URLToFileChangesMap; 32 typedef std::map<fileapi::FileSystemURL, FileChangeList, 33 fileapi::FileSystemURL::Comparator> URLToFileChangeList; 34 typedef std::map<fileapi::FileSystemURL, SyncFileMetadata, 35 fileapi::FileSystemURL::Comparator> URLToFileMetadata; 36 37 FakeRemoteChangeProcessor(); 38 virtual ~FakeRemoteChangeProcessor(); 39 40 // RemoteChangeProcessor overrides. 41 virtual void PrepareForProcessRemoteChange( 42 const fileapi::FileSystemURL& url, 43 const PrepareChangeCallback& callback) OVERRIDE; 44 virtual void ApplyRemoteChange( 45 const FileChange& change, 46 const base::FilePath& local_path, 47 const fileapi::FileSystemURL& url, 48 const SyncStatusCallback& callback) OVERRIDE; 49 virtual void FinalizeRemoteSync( 50 const fileapi::FileSystemURL& url, 51 bool clear_local_changes, 52 const base::Closure& completion_callback) OVERRIDE; 53 virtual void RecordFakeLocalChange( 54 const fileapi::FileSystemURL& url, 55 const FileChange& change, 56 const SyncStatusCallback& callback) OVERRIDE; 57 58 void UpdateLocalFileMetadata( 59 const fileapi::FileSystemURL& url, 60 const FileChange& change); 61 void ClearLocalChanges(const fileapi::FileSystemURL& url); 62 63 const URLToFileChangesMap& GetAppliedRemoteChanges() const; 64 65 // Compare |applied_changes_| with |expected_changes|. 66 // This internally calls EXPECT_FOO, ASSERT_FOO methods in the 67 // verification. 68 void VerifyConsistency(const URLToFileChangesMap& expected_changes); 69 70 private: 71 // History of file changes given by ApplyRemoteChange(). Changes are arranged 72 // in chronological order, that is, the end of the vector represents the last 73 // change. 74 URLToFileChangesMap applied_changes_; 75 76 // History of local file changes. 77 URLToFileChangeList local_changes_; 78 79 // Initial local file metadata. These are overridden by applied changes. 80 URLToFileMetadata local_file_metadata_; 81 82 DISALLOW_COPY_AND_ASSIGN(FakeRemoteChangeProcessor); 83 }; 84 85 } // namespace sync_file_system 86 87 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_FAKE_REMOTE_CHANGE_PROCESSOR_H_ 88