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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/fake_drive_service_helper.cc

Issue 1873683002: Convert //chrome/browser/sync_file_system from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/drive_backend/fake_drive_service_helpe r.h" 5 #include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helpe r.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 12 matching lines...) Expand all
23 using google_apis::FileList; 23 using google_apis::FileList;
24 using google_apis::FileResource; 24 using google_apis::FileResource;
25 using google_apis::DriveApiErrorCode; 25 using google_apis::DriveApiErrorCode;
26 26
27 namespace sync_file_system { 27 namespace sync_file_system {
28 namespace drive_backend { 28 namespace drive_backend {
29 29
30 namespace { 30 namespace {
31 31
32 void UploadResultCallback(DriveApiErrorCode* error_out, 32 void UploadResultCallback(DriveApiErrorCode* error_out,
33 scoped_ptr<FileResource>* entry_out, 33 std::unique_ptr<FileResource>* entry_out,
34 DriveApiErrorCode error, 34 DriveApiErrorCode error,
35 const GURL& upload_location, 35 const GURL& upload_location,
36 scoped_ptr<FileResource> entry) { 36 std::unique_ptr<FileResource> entry) {
37 ASSERT_TRUE(error_out); 37 ASSERT_TRUE(error_out);
38 ASSERT_TRUE(entry_out); 38 ASSERT_TRUE(entry_out);
39 *error_out = error; 39 *error_out = error;
40 *entry_out = std::move(entry); 40 *entry_out = std::move(entry);
41 } 41 }
42 42
43 void DownloadResultCallback(DriveApiErrorCode* error_out, 43 void DownloadResultCallback(DriveApiErrorCode* error_out,
44 DriveApiErrorCode error, 44 DriveApiErrorCode error,
45 const base::FilePath& local_file) { 45 const base::FilePath& local_file) {
46 ASSERT_TRUE(error_out); 46 ASSERT_TRUE(error_out);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (error != google_apis::HTTP_NO_CONTENT && folder_id) 79 if (error != google_apis::HTTP_NO_CONTENT && folder_id)
80 return error; 80 return error;
81 return google_apis::HTTP_CREATED; 81 return google_apis::HTTP_CREATED;
82 } 82 }
83 83
84 DriveApiErrorCode FakeDriveServiceHelper::AddFolder( 84 DriveApiErrorCode FakeDriveServiceHelper::AddFolder(
85 const std::string& parent_folder_id, 85 const std::string& parent_folder_id,
86 const std::string& title, 86 const std::string& title,
87 std::string* folder_id) { 87 std::string* folder_id) {
88 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 88 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
89 scoped_ptr<FileResource> folder; 89 std::unique_ptr<FileResource> folder;
90 drive::AddNewDirectoryOptions options; 90 drive::AddNewDirectoryOptions options;
91 options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE; 91 options.visibility = google_apis::drive::FILE_VISIBILITY_PRIVATE;
92 fake_drive_service_->AddNewDirectory(parent_folder_id, title, options, 92 fake_drive_service_->AddNewDirectory(parent_folder_id, title, options,
93 CreateResultReceiver(&error, &folder)); 93 CreateResultReceiver(&error, &folder));
94 base::RunLoop().RunUntilIdle(); 94 base::RunLoop().RunUntilIdle();
95 95
96 if (error == google_apis::HTTP_CREATED && folder_id) 96 if (error == google_apis::HTTP_CREATED && folder_id)
97 *folder_id = folder->file_id(); 97 *folder_id = folder->file_id();
98 return error; 98 return error;
99 } 99 }
100 100
101 DriveApiErrorCode FakeDriveServiceHelper::AddFile( 101 DriveApiErrorCode FakeDriveServiceHelper::AddFile(
102 const std::string& parent_folder_id, 102 const std::string& parent_folder_id,
103 const std::string& title, 103 const std::string& title,
104 const std::string& content, 104 const std::string& content,
105 std::string* file_id) { 105 std::string* file_id) {
106 base::FilePath temp_file = WriteToTempFile(content); 106 base::FilePath temp_file = WriteToTempFile(content);
107 107
108 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 108 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
109 scoped_ptr<FileResource> file; 109 std::unique_ptr<FileResource> file;
110 drive_uploader_->UploadNewFile( 110 drive_uploader_->UploadNewFile(
111 parent_folder_id, temp_file, title, "application/octet-stream", 111 parent_folder_id, temp_file, title, "application/octet-stream",
112 drive::UploadNewFileOptions(), 112 drive::UploadNewFileOptions(),
113 base::Bind(&UploadResultCallback, &error, &file), 113 base::Bind(&UploadResultCallback, &error, &file),
114 google_apis::ProgressCallback()); 114 google_apis::ProgressCallback());
115 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
116 116
117 if (error == google_apis::HTTP_SUCCESS && file_id) 117 if (error == google_apis::HTTP_SUCCESS && file_id)
118 *file_id = file->file_id(); 118 *file_id = file->file_id();
119 return error; 119 return error;
120 } 120 }
121 121
122 DriveApiErrorCode FakeDriveServiceHelper::UpdateFile( 122 DriveApiErrorCode FakeDriveServiceHelper::UpdateFile(
123 const std::string& file_id, 123 const std::string& file_id,
124 const std::string& content) { 124 const std::string& content) {
125 base::FilePath temp_file = WriteToTempFile(content); 125 base::FilePath temp_file = WriteToTempFile(content);
126 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 126 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
127 scoped_ptr<FileResource> file; 127 std::unique_ptr<FileResource> file;
128 drive_uploader_->UploadExistingFile( 128 drive_uploader_->UploadExistingFile(
129 file_id, temp_file, "application/octet-stream", 129 file_id, temp_file, "application/octet-stream",
130 drive::UploadExistingFileOptions(), 130 drive::UploadExistingFileOptions(),
131 base::Bind(&UploadResultCallback, &error, &file), 131 base::Bind(&UploadResultCallback, &error, &file),
132 google_apis::ProgressCallback()); 132 google_apis::ProgressCallback());
133 base::RunLoop().RunUntilIdle(); 133 base::RunLoop().RunUntilIdle();
134 return error; 134 return error;
135 } 135 }
136 136
137 DriveApiErrorCode FakeDriveServiceHelper::DeleteResource( 137 DriveApiErrorCode FakeDriveServiceHelper::DeleteResource(
(...skipping 14 matching lines...) Expand all
152 file_id, 152 file_id,
153 CreateResultReceiver(&error)); 153 CreateResultReceiver(&error));
154 base::RunLoop().RunUntilIdle(); 154 base::RunLoop().RunUntilIdle();
155 return error; 155 return error;
156 } 156 }
157 157
158 DriveApiErrorCode FakeDriveServiceHelper::UpdateModificationTime( 158 DriveApiErrorCode FakeDriveServiceHelper::UpdateModificationTime(
159 const std::string& file_id, 159 const std::string& file_id,
160 const base::Time& modification_time) { 160 const base::Time& modification_time) {
161 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 161 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
162 scoped_ptr<FileResource> entry; 162 std::unique_ptr<FileResource> entry;
163 error = GetFileResource(file_id, &entry); 163 error = GetFileResource(file_id, &entry);
164 if (error != google_apis::HTTP_SUCCESS) 164 if (error != google_apis::HTTP_SUCCESS)
165 return error; 165 return error;
166 166
167 fake_drive_service_->UpdateResource( 167 fake_drive_service_->UpdateResource(
168 file_id, std::string(), entry->title(), modification_time, 168 file_id, std::string(), entry->title(), modification_time,
169 entry->last_viewed_by_me_date(), google_apis::drive::Properties(), 169 entry->last_viewed_by_me_date(), google_apis::drive::Properties(),
170 CreateResultReceiver(&error, &entry)); 170 CreateResultReceiver(&error, &entry));
171 base::RunLoop().RunUntilIdle(); 171 base::RunLoop().RunUntilIdle();
172 return error; 172 return error;
173 } 173 }
174 174
175 DriveApiErrorCode FakeDriveServiceHelper::RenameResource( 175 DriveApiErrorCode FakeDriveServiceHelper::RenameResource(
176 const std::string& file_id, 176 const std::string& file_id,
177 const std::string& new_title) { 177 const std::string& new_title) {
178 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 178 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
179 scoped_ptr<FileResource> entry; 179 std::unique_ptr<FileResource> entry;
180 fake_drive_service_->UpdateResource( 180 fake_drive_service_->UpdateResource(
181 file_id, std::string(), new_title, base::Time(), base::Time(), 181 file_id, std::string(), new_title, base::Time(), base::Time(),
182 google_apis::drive::Properties(), CreateResultReceiver(&error, &entry)); 182 google_apis::drive::Properties(), CreateResultReceiver(&error, &entry));
183 base::RunLoop().RunUntilIdle(); 183 base::RunLoop().RunUntilIdle();
184 return error; 184 return error;
185 } 185 }
186 186
187 DriveApiErrorCode FakeDriveServiceHelper::AddResourceToDirectory( 187 DriveApiErrorCode FakeDriveServiceHelper::AddResourceToDirectory(
188 const std::string& parent_folder_id, 188 const std::string& parent_folder_id,
189 const std::string& file_id) { 189 const std::string& file_id) {
(...skipping 12 matching lines...) Expand all
202 fake_drive_service_->RemoveResourceFromDirectory( 202 fake_drive_service_->RemoveResourceFromDirectory(
203 parent_folder_id, file_id, 203 parent_folder_id, file_id,
204 CreateResultReceiver(&error)); 204 CreateResultReceiver(&error));
205 base::RunLoop().RunUntilIdle(); 205 base::RunLoop().RunUntilIdle();
206 return error; 206 return error;
207 } 207 }
208 208
209 DriveApiErrorCode FakeDriveServiceHelper::GetSyncRootFolderID( 209 DriveApiErrorCode FakeDriveServiceHelper::GetSyncRootFolderID(
210 std::string* sync_root_folder_id) { 210 std::string* sync_root_folder_id) {
211 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 211 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
212 scoped_ptr<FileList> resource_list; 212 std::unique_ptr<FileList> resource_list;
213 fake_drive_service_->SearchByTitle( 213 fake_drive_service_->SearchByTitle(
214 sync_root_folder_title_, std::string(), 214 sync_root_folder_title_, std::string(),
215 CreateResultReceiver(&error, &resource_list)); 215 CreateResultReceiver(&error, &resource_list));
216 base::RunLoop().RunUntilIdle(); 216 base::RunLoop().RunUntilIdle();
217 if (error != google_apis::HTTP_SUCCESS) 217 if (error != google_apis::HTTP_SUCCESS)
218 return error; 218 return error;
219 219
220 const ScopedVector<FileResource>& items = resource_list->items(); 220 const ScopedVector<FileResource>& items = resource_list->items();
221 for (ScopedVector<FileResource>::const_iterator itr = items.begin(); 221 for (ScopedVector<FileResource>::const_iterator itr = items.begin();
222 itr != items.end(); ++itr) { 222 itr != items.end(); ++itr) {
223 const FileResource& item = **itr; 223 const FileResource& item = **itr;
224 if (item.parents().empty()) { 224 if (item.parents().empty()) {
225 *sync_root_folder_id = item.file_id(); 225 *sync_root_folder_id = item.file_id();
226 return google_apis::HTTP_SUCCESS; 226 return google_apis::HTTP_SUCCESS;
227 } 227 }
228 } 228 }
229 return google_apis::HTTP_NOT_FOUND; 229 return google_apis::HTTP_NOT_FOUND;
230 } 230 }
231 231
232 DriveApiErrorCode FakeDriveServiceHelper::ListFilesInFolder( 232 DriveApiErrorCode FakeDriveServiceHelper::ListFilesInFolder(
233 const std::string& folder_id, 233 const std::string& folder_id,
234 ScopedVector<FileResource>* entries) { 234 ScopedVector<FileResource>* entries) {
235 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 235 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
236 scoped_ptr<FileList> list; 236 std::unique_ptr<FileList> list;
237 fake_drive_service_->GetFileListInDirectory( 237 fake_drive_service_->GetFileListInDirectory(
238 folder_id, 238 folder_id,
239 CreateResultReceiver(&error, &list)); 239 CreateResultReceiver(&error, &list));
240 base::RunLoop().RunUntilIdle(); 240 base::RunLoop().RunUntilIdle();
241 if (error != google_apis::HTTP_SUCCESS) 241 if (error != google_apis::HTTP_SUCCESS)
242 return error; 242 return error;
243 243
244 return CompleteListing(std::move(list), entries); 244 return CompleteListing(std::move(list), entries);
245 } 245 }
246 246
247 DriveApiErrorCode FakeDriveServiceHelper::SearchByTitle( 247 DriveApiErrorCode FakeDriveServiceHelper::SearchByTitle(
248 const std::string& folder_id, 248 const std::string& folder_id,
249 const std::string& title, 249 const std::string& title,
250 ScopedVector<FileResource>* entries) { 250 ScopedVector<FileResource>* entries) {
251 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 251 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
252 scoped_ptr<FileList> list; 252 std::unique_ptr<FileList> list;
253 fake_drive_service_->SearchByTitle( 253 fake_drive_service_->SearchByTitle(
254 title, folder_id, 254 title, folder_id,
255 CreateResultReceiver(&error, &list)); 255 CreateResultReceiver(&error, &list));
256 base::RunLoop().RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
257 if (error != google_apis::HTTP_SUCCESS) 257 if (error != google_apis::HTTP_SUCCESS)
258 return error; 258 return error;
259 259
260 return CompleteListing(std::move(list), entries); 260 return CompleteListing(std::move(list), entries);
261 } 261 }
262 262
263 DriveApiErrorCode FakeDriveServiceHelper::GetFileResource( 263 DriveApiErrorCode FakeDriveServiceHelper::GetFileResource(
264 const std::string& file_id, 264 const std::string& file_id,
265 scoped_ptr<FileResource>* entry) { 265 std::unique_ptr<FileResource>* entry) {
266 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 266 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
267 fake_drive_service_->GetFileResource( 267 fake_drive_service_->GetFileResource(
268 file_id, 268 file_id,
269 CreateResultReceiver(&error, entry)); 269 CreateResultReceiver(&error, entry));
270 base::RunLoop().RunUntilIdle(); 270 base::RunLoop().RunUntilIdle();
271 return error; 271 return error;
272 } 272 }
273 273
274 DriveApiErrorCode FakeDriveServiceHelper::GetFileVisibility( 274 DriveApiErrorCode FakeDriveServiceHelper::GetFileVisibility(
275 const std::string& file_id, 275 const std::string& file_id,
276 google_apis::drive::FileVisibility* visibility) { 276 google_apis::drive::FileVisibility* visibility) {
277 return fake_drive_service_->GetFileVisibility( 277 return fake_drive_service_->GetFileVisibility(
278 file_id, 278 file_id,
279 visibility); 279 visibility);
280 } 280 }
281 281
282 DriveApiErrorCode FakeDriveServiceHelper::ReadFile( 282 DriveApiErrorCode FakeDriveServiceHelper::ReadFile(
283 const std::string& file_id, 283 const std::string& file_id,
284 std::string* file_content) { 284 std::string* file_content) {
285 scoped_ptr<google_apis::FileResource> file; 285 std::unique_ptr<google_apis::FileResource> file;
286 DriveApiErrorCode error = GetFileResource(file_id, &file); 286 DriveApiErrorCode error = GetFileResource(file_id, &file);
287 if (error != google_apis::HTTP_SUCCESS) 287 if (error != google_apis::HTTP_SUCCESS)
288 return error; 288 return error;
289 if (!file) 289 if (!file)
290 return google_apis::DRIVE_PARSE_ERROR; 290 return google_apis::DRIVE_PARSE_ERROR;
291 291
292 error = google_apis::DRIVE_OTHER_ERROR; 292 error = google_apis::DRIVE_OTHER_ERROR;
293 base::FilePath temp_file; 293 base::FilePath temp_file;
294 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); 294 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file));
295 fake_drive_service_->DownloadFile( 295 fake_drive_service_->DownloadFile(
296 temp_file, file->file_id(), 296 temp_file, file->file_id(),
297 base::Bind(&DownloadResultCallback, &error), 297 base::Bind(&DownloadResultCallback, &error),
298 google_apis::GetContentCallback(), 298 google_apis::GetContentCallback(),
299 google_apis::ProgressCallback()); 299 google_apis::ProgressCallback());
300 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
301 if (error != google_apis::HTTP_SUCCESS) 301 if (error != google_apis::HTTP_SUCCESS)
302 return error; 302 return error;
303 303
304 return base::ReadFileToString(temp_file, file_content) 304 return base::ReadFileToString(temp_file, file_content)
305 ? google_apis::HTTP_SUCCESS : google_apis::DRIVE_FILE_ERROR; 305 ? google_apis::HTTP_SUCCESS : google_apis::DRIVE_FILE_ERROR;
306 } 306 }
307 307
308 DriveApiErrorCode FakeDriveServiceHelper::GetAboutResource( 308 DriveApiErrorCode FakeDriveServiceHelper::GetAboutResource(
309 scoped_ptr<AboutResource>* about_resource) { 309 std::unique_ptr<AboutResource>* about_resource) {
310 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 310 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
311 fake_drive_service_->GetAboutResource( 311 fake_drive_service_->GetAboutResource(
312 CreateResultReceiver(&error, about_resource)); 312 CreateResultReceiver(&error, about_resource));
313 base::RunLoop().RunUntilIdle(); 313 base::RunLoop().RunUntilIdle();
314 return error; 314 return error;
315 } 315 }
316 316
317 DriveApiErrorCode FakeDriveServiceHelper::CompleteListing( 317 DriveApiErrorCode FakeDriveServiceHelper::CompleteListing(
318 scoped_ptr<FileList> list, 318 std::unique_ptr<FileList> list,
319 ScopedVector<FileResource>* entries) { 319 ScopedVector<FileResource>* entries) {
320 while (true) { 320 while (true) {
321 entries->reserve(entries->size() + list->items().size()); 321 entries->reserve(entries->size() + list->items().size());
322 std::vector<FileResource*> tmp; 322 std::vector<FileResource*> tmp;
323 list->mutable_items()->release(&tmp); 323 list->mutable_items()->release(&tmp);
324 for (std::vector<FileResource*>::const_iterator itr = 324 for (std::vector<FileResource*>::const_iterator itr =
325 tmp.begin(); itr != tmp.end(); ++itr) { 325 tmp.begin(); itr != tmp.end(); ++itr) {
326 entries->push_back(*itr); 326 entries->push_back(*itr);
327 } 327 }
328 328
(...skipping 22 matching lines...) Expand all
351 const std::string& content) { 351 const std::string& content) {
352 base::FilePath temp_file; 352 base::FilePath temp_file;
353 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); 353 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file));
354 EXPECT_EQ(static_cast<int>(content.size()), 354 EXPECT_EQ(static_cast<int>(content.size()),
355 base::WriteFile(temp_file, content.data(), content.size())); 355 base::WriteFile(temp_file, content.data(), content.size()));
356 return temp_file; 356 return temp_file;
357 } 357 }
358 358
359 } // namespace drive_backend 359 } // namespace drive_backend
360 } // namespace sync_file_system 360 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698