- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / fake_remote_change_processor.cc
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 "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"
14
15 namespace sync_file_system {
16
17 FakeRemoteChangeProcessor::FakeRemoteChangeProcessor() {
18 }
19
20 FakeRemoteChangeProcessor::~FakeRemoteChangeProcessor() {
21 }
22
23 void 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
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));
53 }
54
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);
60 }
61
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));
68 }
69
70 const FakeRemoteChangeProcessor::URLToFileChangesMap&
71 FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const {
72   return applied_changes_;
73 }
74
75 }  // namespace sync_file_system