fake_remote_change_processor.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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/browser/fileapi/file_system_url.h"
12#include "webkit/browser/fileapi/syncable/file_change.h"
13#include "webkit/browser/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 PrepareChangeCallback& callback) {
26  SyncFileMetadata local_metadata;
27
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(),
35          100 /* size */,
36          base::Time::Now());
37    }
38  }
39  base::MessageLoopProxy::current()->PostTask(
40      FROM_HERE,
41      base::Bind(callback, SYNC_STATUS_OK,
42                 local_metadata, FileChangeList()));
43}
44
45void 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));
53}
54
55void FakeRemoteChangeProcessor::ClearLocalChanges(
56    const fileapi::FileSystemURL& url,
57    const base::Closure& completion_callback) {
58  base::MessageLoopProxy::current()->PostTask(FROM_HERE, completion_callback);
59}
60
61void FakeRemoteChangeProcessor::RecordFakeLocalChange(
62    const fileapi::FileSystemURL& url,
63    const FileChange& change,
64    const SyncStatusCallback& callback) {
65  base::MessageLoopProxy::current()->PostTask(
66      FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
67}
68
69const FakeRemoteChangeProcessor::URLToFileChangesMap&
70FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const {
71  return applied_changes_;
72}
73
74}  // namespace sync_file_system
75