fake_remote_change_processor.cc revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
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#include "chrome/browser/sync_file_system/fake_remote_change_processor.h"
6
7#include "base/bind.h"
8#include "base/files/file_path.h"
9#include "base/location.h"
10#include "base/message_loop/message_loop_proxy.h"
11#include "webkit/fileapi/file_system_url.h"
12#include "webkit/fileapi/syncable/file_change.h"
13#include "webkit/fileapi/syncable/sync_file_metadata.h"
14
15namespace sync_file_system {
16
17FakeRemoteChangeProcessor::FakeRemoteChangeProcessor() {
18}
19
20FakeRemoteChangeProcessor::~FakeRemoteChangeProcessor() {
21}
22
23void FakeRemoteChangeProcessor::PrepareForProcessRemoteChange(
24    const fileapi::FileSystemURL& url,
25    const std::string& service_name,
26    const PrepareChangeCallback& callback) {
27  SyncFileMetadata local_metadata;
28
29  URLToFileChangesMap::iterator found = applied_changes_.find(url);
30  if (found != applied_changes_.end()) {
31    DCHECK(!found->second.empty());
32    const FileChange& applied_change = found->second.back();
33    if (applied_change.IsAddOrUpdate()) {
34      local_metadata = SyncFileMetadata(
35          applied_change.file_type(),
36          100 /* size */,
37          base::Time::Now());
38    }
39  }
40  base::MessageLoopProxy::current()->PostTask(
41      FROM_HERE,
42      base::Bind(callback, SYNC_STATUS_OK,
43                 local_metadata, FileChangeList()));
44}
45
46void FakeRemoteChangeProcessor::ApplyRemoteChange(
47    const FileChange& change,
48    const base::FilePath& local_path,
49    const fileapi::FileSystemURL& url,
50    const SyncStatusCallback& callback) {
51  applied_changes_[url].push_back(change);
52  base::MessageLoopProxy::current()->PostTask(
53      FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
54}
55
56void FakeRemoteChangeProcessor::ClearLocalChanges(
57    const fileapi::FileSystemURL& url,
58    const base::Closure& completion_callback) {
59  base::MessageLoopProxy::current()->PostTask(FROM_HERE, completion_callback);
60}
61
62void 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));
68}
69
70const FakeRemoteChangeProcessor::URLToFileChangesMap&
71FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const {
72  return applied_changes_;
73}
74
75}  // namespace sync_file_system
76