Home | History | Annotate | Download | only in sync_file_system
      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::ClearLocalChanges(
     56     const fileapi::FileSystemURL& url,
     57     const base::Closure& completion_callback) {
     58   base::MessageLoopProxy::current()->PostTask(FROM_HERE, completion_callback);
     59 }
     60 
     61 void 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 
     69 const FakeRemoteChangeProcessor::URLToFileChangesMap&
     70 FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const {
     71   return applied_changes_;
     72 }
     73 
     74 }  // namespace sync_file_system
     75