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