Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: chrome/browser/sync_file_system/fake_remote_change_processor.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/sync_file_system/file_change.h" 12 #include "chrome/browser/sync_file_system/file_change.h"
13 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 13 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
14 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 14 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/browser/fileapi/file_system_url.h" 16 #include "storage/browser/fileapi/file_system_url.h"
17 #include "webkit/common/fileapi/file_system_util.h" 17 #include "storage/common/fileapi/file_system_util.h"
18 18
19 namespace sync_file_system { 19 namespace sync_file_system {
20 20
21 FakeRemoteChangeProcessor::FakeRemoteChangeProcessor() { 21 FakeRemoteChangeProcessor::FakeRemoteChangeProcessor() {
22 } 22 }
23 23
24 FakeRemoteChangeProcessor::~FakeRemoteChangeProcessor() { 24 FakeRemoteChangeProcessor::~FakeRemoteChangeProcessor() {
25 } 25 }
26 26
27 void FakeRemoteChangeProcessor::PrepareForProcessRemoteChange( 27 void FakeRemoteChangeProcessor::PrepareForProcessRemoteChange(
28 const fileapi::FileSystemURL& url, 28 const storage::FileSystemURL& url,
29 const PrepareChangeCallback& callback) { 29 const PrepareChangeCallback& callback) {
30 SyncFileMetadata local_metadata; 30 SyncFileMetadata local_metadata;
31 31
32 if (fileapi::VirtualPath::IsRootPath(url.path())) { 32 if (storage::VirtualPath::IsRootPath(url.path())) {
33 // Origin root directory case. 33 // Origin root directory case.
34 local_metadata = SyncFileMetadata( 34 local_metadata = SyncFileMetadata(
35 SYNC_FILE_TYPE_DIRECTORY, 0, base::Time::Now()); 35 SYNC_FILE_TYPE_DIRECTORY, 0, base::Time::Now());
36 } 36 }
37 37
38 URLToFileMetadata::iterator found_metadata = local_file_metadata_.find(url); 38 URLToFileMetadata::iterator found_metadata = local_file_metadata_.find(url);
39 if (found_metadata != local_file_metadata_.end()) 39 if (found_metadata != local_file_metadata_.end())
40 local_metadata = found_metadata->second; 40 local_metadata = found_metadata->second;
41 41
42 // Override |local_metadata| by applied changes. 42 // Override |local_metadata| by applied changes.
(...skipping 16 matching lines...) Expand all
59 59
60 base::ThreadTaskRunnerHandle::Get()->PostTask( 60 base::ThreadTaskRunnerHandle::Get()->PostTask(
61 FROM_HERE, 61 FROM_HERE,
62 base::Bind(callback, SYNC_STATUS_OK, 62 base::Bind(callback, SYNC_STATUS_OK,
63 local_metadata, change_list)); 63 local_metadata, change_list));
64 } 64 }
65 65
66 void FakeRemoteChangeProcessor::ApplyRemoteChange( 66 void FakeRemoteChangeProcessor::ApplyRemoteChange(
67 const FileChange& change, 67 const FileChange& change,
68 const base::FilePath& local_path, 68 const base::FilePath& local_path,
69 const fileapi::FileSystemURL& url, 69 const storage::FileSystemURL& url,
70 const SyncStatusCallback& callback) { 70 const SyncStatusCallback& callback) {
71 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 71 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
72 base::FilePath ancestor = fileapi::VirtualPath::DirName(url.path()); 72 base::FilePath ancestor = storage::VirtualPath::DirName(url.path());
73 while (true) { 73 while (true) {
74 fileapi::FileSystemURL ancestor_url = 74 storage::FileSystemURL ancestor_url =
75 CreateSyncableFileSystemURL(url.origin(), ancestor); 75 CreateSyncableFileSystemURL(url.origin(), ancestor);
76 if (!ancestor_url.is_valid()) 76 if (!ancestor_url.is_valid())
77 break; 77 break;
78 78
79 URLToFileChangeList::iterator found_list = 79 URLToFileChangeList::iterator found_list =
80 local_changes_.find(ancestor_url); 80 local_changes_.find(ancestor_url);
81 if (found_list != local_changes_.end()) { 81 if (found_list != local_changes_.end()) {
82 const FileChange& local_change = found_list->second.back(); 82 const FileChange& local_change = found_list->second.back();
83 if (local_change.IsAddOrUpdate() && 83 if (local_change.IsAddOrUpdate() &&
84 local_change.file_type() != SYNC_FILE_TYPE_DIRECTORY) { 84 local_change.file_type() != SYNC_FILE_TYPE_DIRECTORY) {
85 status = SYNC_FILE_ERROR_NOT_A_DIRECTORY; 85 status = SYNC_FILE_ERROR_NOT_A_DIRECTORY;
86 break; 86 break;
87 } 87 }
88 } 88 }
89 89
90 base::FilePath ancestor_parent = fileapi::VirtualPath::DirName(ancestor); 90 base::FilePath ancestor_parent = storage::VirtualPath::DirName(ancestor);
91 if (ancestor == ancestor_parent) 91 if (ancestor == ancestor_parent)
92 break; 92 break;
93 ancestor = ancestor_parent; 93 ancestor = ancestor_parent;
94 } 94 }
95 if (status == SYNC_STATUS_UNKNOWN) { 95 if (status == SYNC_STATUS_UNKNOWN) {
96 applied_changes_[url].push_back(change); 96 applied_changes_[url].push_back(change);
97 status = SYNC_STATUS_OK; 97 status = SYNC_STATUS_OK;
98 } 98 }
99 base::ThreadTaskRunnerHandle::Get()->PostTask( 99 base::ThreadTaskRunnerHandle::Get()->PostTask(
100 FROM_HERE, base::Bind(callback, status)); 100 FROM_HERE, base::Bind(callback, status));
101 } 101 }
102 102
103 void FakeRemoteChangeProcessor::FinalizeRemoteSync( 103 void FakeRemoteChangeProcessor::FinalizeRemoteSync(
104 const fileapi::FileSystemURL& url, 104 const storage::FileSystemURL& url,
105 bool clear_local_changes, 105 bool clear_local_changes,
106 const base::Closure& completion_callback) { 106 const base::Closure& completion_callback) {
107 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, completion_callback); 107 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, completion_callback);
108 } 108 }
109 109
110 void FakeRemoteChangeProcessor::RecordFakeLocalChange( 110 void FakeRemoteChangeProcessor::RecordFakeLocalChange(
111 const fileapi::FileSystemURL& url, 111 const storage::FileSystemURL& url,
112 const FileChange& change, 112 const FileChange& change,
113 const SyncStatusCallback& callback) { 113 const SyncStatusCallback& callback) {
114 local_changes_[url].Update(change); 114 local_changes_[url].Update(change);
115 base::ThreadTaskRunnerHandle::Get()->PostTask( 115 base::ThreadTaskRunnerHandle::Get()->PostTask(
116 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK)); 116 FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
117 } 117 }
118 118
119 void FakeRemoteChangeProcessor::UpdateLocalFileMetadata( 119 void FakeRemoteChangeProcessor::UpdateLocalFileMetadata(
120 const fileapi::FileSystemURL& url, 120 const storage::FileSystemURL& url,
121 const FileChange& change) { 121 const FileChange& change) {
122 if (change.IsAddOrUpdate()) { 122 if (change.IsAddOrUpdate()) {
123 local_file_metadata_[url] = SyncFileMetadata( 123 local_file_metadata_[url] = SyncFileMetadata(
124 change.file_type(), 100 /* size */, base::Time::Now()); 124 change.file_type(), 100 /* size */, base::Time::Now());
125 } else { 125 } else {
126 local_file_metadata_.erase(url); 126 local_file_metadata_.erase(url);
127 } 127 }
128 local_changes_[url].Update(change); 128 local_changes_[url].Update(change);
129 } 129 }
130 130
131 void FakeRemoteChangeProcessor::ClearLocalChanges( 131 void FakeRemoteChangeProcessor::ClearLocalChanges(
132 const fileapi::FileSystemURL& url) { 132 const storage::FileSystemURL& url) {
133 local_changes_.erase(url); 133 local_changes_.erase(url);
134 } 134 }
135 135
136 const FakeRemoteChangeProcessor::URLToFileChangesMap& 136 const FakeRemoteChangeProcessor::URLToFileChangesMap&
137 FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const { 137 FakeRemoteChangeProcessor::GetAppliedRemoteChanges() const {
138 return applied_changes_; 138 return applied_changes_;
139 } 139 }
140 140
141 void FakeRemoteChangeProcessor::VerifyConsistency( 141 void FakeRemoteChangeProcessor::VerifyConsistency(
142 const URLToFileChangesMap& expected_changes) { 142 const URLToFileChangesMap& expected_changes) {
143 EXPECT_EQ(expected_changes.size(), applied_changes_.size()); 143 EXPECT_EQ(expected_changes.size(), applied_changes_.size());
144 for (URLToFileChangesMap::const_iterator itr = applied_changes_.begin(); 144 for (URLToFileChangesMap::const_iterator itr = applied_changes_.begin();
145 itr != applied_changes_.end(); ++itr) { 145 itr != applied_changes_.end(); ++itr) {
146 const fileapi::FileSystemURL& url = itr->first; 146 const storage::FileSystemURL& url = itr->first;
147 URLToFileChangesMap::const_iterator found = expected_changes.find(url); 147 URLToFileChangesMap::const_iterator found = expected_changes.find(url);
148 if (found == expected_changes.end()) { 148 if (found == expected_changes.end()) {
149 EXPECT_TRUE(found != expected_changes.end()) 149 EXPECT_TRUE(found != expected_changes.end())
150 << "Change not expected for " << url.DebugString(); 150 << "Change not expected for " << url.DebugString();
151 continue; 151 continue;
152 } 152 }
153 153
154 const std::vector<FileChange>& applied = itr->second; 154 const std::vector<FileChange>& applied = itr->second;
155 const std::vector<FileChange>& expected = found->second; 155 const std::vector<FileChange>& expected = found->second;
156 156
157 if (applied.empty() || expected.empty()) { 157 if (applied.empty() || expected.empty()) {
158 EXPECT_TRUE(!applied.empty()); 158 EXPECT_TRUE(!applied.empty());
159 EXPECT_TRUE(!expected.empty()); 159 EXPECT_TRUE(!expected.empty());
160 continue; 160 continue;
161 } 161 }
162 162
163 EXPECT_EQ(expected.size(), applied.size()); 163 EXPECT_EQ(expected.size(), applied.size());
164 164
165 for (size_t i = 0; i < applied.size() && i < expected.size(); ++i) { 165 for (size_t i = 0; i < applied.size() && i < expected.size(); ++i) {
166 EXPECT_EQ(expected[i], applied[i]) 166 EXPECT_EQ(expected[i], applied[i])
167 << url.DebugString() 167 << url.DebugString()
168 << " expected:" << expected[i].DebugString() 168 << " expected:" << expected[i].DebugString()
169 << " applied:" << applied[i].DebugString(); 169 << " applied:" << applied[i].DebugString();
170 } 170 }
171 } 171 }
172 } 172 }
173 173
174 } // namespace sync_file_system 174 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/fake_remote_change_processor.h ('k') | chrome/browser/sync_file_system/file_change.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698