| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync_file_system/fake_remote_change_processor.h" | 5 #include "chrome/browser/sync_file_system/fake_remote_change_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 FileChangeList change_list; | 57 FileChangeList change_list; |
| 58 URLToFileChangeList::iterator found_list = local_changes_.find(url); | 58 URLToFileChangeList::iterator found_list = local_changes_.find(url); |
| 59 if (found_list != local_changes_.end()) | 59 if (found_list != local_changes_.end()) |
| 60 change_list = found_list->second; | 60 change_list = found_list->second; |
| 61 | 61 |
| 62 base::ThreadTaskRunnerHandle::Get()->PostTask( | 62 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 63 FROM_HERE, | 63 FROM_HERE, |
| 64 base::Bind(callback, SYNC_STATUS_OK, | 64 base::BindOnce(callback, SYNC_STATUS_OK, local_metadata, change_list)); |
| 65 local_metadata, change_list)); | |
| 66 } | 65 } |
| 67 | 66 |
| 68 void FakeRemoteChangeProcessor::ApplyRemoteChange( | 67 void FakeRemoteChangeProcessor::ApplyRemoteChange( |
| 69 const FileChange& change, | 68 const FileChange& change, |
| 70 const base::FilePath& local_path, | 69 const base::FilePath& local_path, |
| 71 const storage::FileSystemURL& url, | 70 const storage::FileSystemURL& url, |
| 72 const SyncStatusCallback& callback) { | 71 const SyncStatusCallback& callback) { |
| 73 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 72 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 74 base::FilePath ancestor = storage::VirtualPath::DirName(url.path()); | 73 base::FilePath ancestor = storage::VirtualPath::DirName(url.path()); |
| 75 while (true) { | 74 while (true) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 92 base::FilePath ancestor_parent = storage::VirtualPath::DirName(ancestor); | 91 base::FilePath ancestor_parent = storage::VirtualPath::DirName(ancestor); |
| 93 if (ancestor == ancestor_parent) | 92 if (ancestor == ancestor_parent) |
| 94 break; | 93 break; |
| 95 ancestor = ancestor_parent; | 94 ancestor = ancestor_parent; |
| 96 } | 95 } |
| 97 if (status == SYNC_STATUS_UNKNOWN) { | 96 if (status == SYNC_STATUS_UNKNOWN) { |
| 98 applied_changes_[url].push_back(change); | 97 applied_changes_[url].push_back(change); |
| 99 status = SYNC_STATUS_OK; | 98 status = SYNC_STATUS_OK; |
| 100 } | 99 } |
| 101 base::ThreadTaskRunnerHandle::Get()->PostTask( | 100 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 102 FROM_HERE, base::Bind(callback, status)); | 101 FROM_HERE, base::BindOnce(callback, status)); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void FakeRemoteChangeProcessor::FinalizeRemoteSync( | 104 void FakeRemoteChangeProcessor::FinalizeRemoteSync( |
| 106 const storage::FileSystemURL& url, | 105 const storage::FileSystemURL& url, |
| 107 bool clear_local_changes, | 106 bool clear_local_changes, |
| 108 const base::Closure& completion_callback) { | 107 const base::Closure& completion_callback) { |
| 109 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, completion_callback); | 108 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, completion_callback); |
| 110 } | 109 } |
| 111 | 110 |
| 112 void FakeRemoteChangeProcessor::RecordFakeLocalChange( | 111 void FakeRemoteChangeProcessor::RecordFakeLocalChange( |
| 113 const storage::FileSystemURL& url, | 112 const storage::FileSystemURL& url, |
| 114 const FileChange& change, | 113 const FileChange& change, |
| 115 const SyncStatusCallback& callback) { | 114 const SyncStatusCallback& callback) { |
| 116 local_changes_[url].Update(change); | 115 local_changes_[url].Update(change); |
| 117 base::ThreadTaskRunnerHandle::Get()->PostTask( | 116 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 118 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK)); | 117 FROM_HERE, base::BindOnce(callback, SYNC_STATUS_OK)); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void FakeRemoteChangeProcessor::UpdateLocalFileMetadata( | 120 void FakeRemoteChangeProcessor::UpdateLocalFileMetadata( |
| 122 const storage::FileSystemURL& url, | 121 const storage::FileSystemURL& url, |
| 123 const FileChange& change) { | 122 const FileChange& change) { |
| 124 if (change.IsAddOrUpdate()) { | 123 if (change.IsAddOrUpdate()) { |
| 125 local_file_metadata_[url] = SyncFileMetadata( | 124 local_file_metadata_[url] = SyncFileMetadata( |
| 126 change.file_type(), 100 /* size */, base::Time::Now()); | 125 change.file_type(), 100 /* size */, base::Time::Now()); |
| 127 } else { | 126 } else { |
| 128 local_file_metadata_.erase(url); | 127 local_file_metadata_.erase(url); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 for (size_t i = 0; i < applied.size() && i < expected.size(); ++i) { | 166 for (size_t i = 0; i < applied.size() && i < expected.size(); ++i) { |
| 168 EXPECT_EQ(expected[i], applied[i]) | 167 EXPECT_EQ(expected[i], applied[i]) |
| 169 << url.DebugString() | 168 << url.DebugString() |
| 170 << " expected:" << expected[i].DebugString() | 169 << " expected:" << expected[i].DebugString() |
| 171 << " applied:" << applied[i].DebugString(); | 170 << " applied:" << applied[i].DebugString(); |
| 172 } | 171 } |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 } // namespace sync_file_system | 175 } // namespace sync_file_system |
| OLD | NEW |