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.
5 #include "chrome/browser/sync_file_system/fake_remote_change_processor.h"
8 #include "base/files/file_path.h"
9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "chrome/browser/sync_file_system/file_change.h"
12 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
13 #include "webkit/browser/fileapi/file_system_url.h"
15 namespace sync_file_system {
17 FakeRemoteChangeProcessor::FakeRemoteChangeProcessor() {
20 FakeRemoteChangeProcessor::~FakeRemoteChangeProcessor() {
23 void FakeRemoteChangeProcessor::PrepareForProcessRemoteChange(
24 const fileapi::FileSystemURL& url,
25 const PrepareChangeCallback& callback) {
26 SyncFileMetadata local_metadata;
28 URLToFileChangesMap::iterator found = applied_changes_.find(url);
29 if (found != applied_changes_.end()) {
30 DCHECK(!found->second.empty());
31 const FileChange& applied_change = found->second.back();
32 if (applied_change.IsAddOrUpdate()) {
33 local_metadata = SyncFileMetadata(
34 applied_change.file_type(),
39 base::MessageLoopProxy::current()->PostTask(
41 base::Bind(callback, SYNC_STATUS_OK,
42 local_metadata, FileChangeList()));
45 void FakeRemoteChangeProcessor::ApplyRemoteChange(
46 const FileChange& change,
47 const base::FilePath& local_path,
48 const fileapi::FileSystemURL& url,
49 const SyncStatusCallback& callback) {
50 applied_changes_[url].push_back(change);
51 base::MessageLoopProxy::current()->PostTask(
52 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
55 void FakeRemoteChangeProcessor::FinalizeRemoteSync(
56 const fileapi::FileSystemURL& url,
57 bool clear_local_changes,
58 const base::Closure& completion_callback) {
59 base::MessageLoopProxy::current()->PostTask(FROM_HERE, completion_callback);
62 void FakeRemoteChangeProcessor::RecordFakeLocalChange(
63 const fileapi::FileSystemURL& url,
64 const FileChange& change,
65 const SyncStatusCallback& callback) {
66 base::MessageLoopProxy::current()->PostTask(
67 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
70 const FakeRemoteChangeProcessor::URLToFileChangesMap&
71 FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const {
72 return applied_changes_;
75 } // namespace sync_file_system