| OLD | NEW |
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return error; | 78 return error; |
| 79 return google_apis::HTTP_CREATED; | 79 return google_apis::HTTP_CREATED; |
| 80 } | 80 } |
| 81 | 81 |
| 82 DriveApiErrorCode FakeDriveServiceHelper::AddFolder( | 82 DriveApiErrorCode FakeDriveServiceHelper::AddFolder( |
| 83 const std::string& parent_folder_id, | 83 const std::string& parent_folder_id, |
| 84 const std::string& title, | 84 const std::string& title, |
| 85 std::string* folder_id) { | 85 std::string* folder_id) { |
| 86 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 86 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 87 scoped_ptr<FileResource> folder; | 87 scoped_ptr<FileResource> folder; |
| 88 fake_drive_service_->AddNewDirectory( | 88 fake_drive_service_->AddNewDirectory(parent_folder_id, title, |
| 89 parent_folder_id, title, | 89 drive::AddNewDirectoryOptions(), |
| 90 drive::DriveServiceInterface::AddNewDirectoryOptions(), | 90 CreateResultReceiver(&error, &folder)); |
| 91 CreateResultReceiver(&error, &folder)); | |
| 92 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 93 | 92 |
| 94 if (error == google_apis::HTTP_CREATED && folder_id) | 93 if (error == google_apis::HTTP_CREATED && folder_id) |
| 95 *folder_id = folder->file_id(); | 94 *folder_id = folder->file_id(); |
| 96 return error; | 95 return error; |
| 97 } | 96 } |
| 98 | 97 |
| 99 DriveApiErrorCode FakeDriveServiceHelper::AddFile( | 98 DriveApiErrorCode FakeDriveServiceHelper::AddFile( |
| 100 const std::string& parent_folder_id, | 99 const std::string& parent_folder_id, |
| 101 const std::string& title, | 100 const std::string& title, |
| 102 const std::string& content, | 101 const std::string& content, |
| 103 std::string* file_id) { | 102 std::string* file_id) { |
| 104 base::FilePath temp_file = WriteToTempFile(content); | 103 base::FilePath temp_file = WriteToTempFile(content); |
| 105 | 104 |
| 106 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 105 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 107 scoped_ptr<FileResource> file; | 106 scoped_ptr<FileResource> file; |
| 108 drive_uploader_->UploadNewFile( | 107 drive_uploader_->UploadNewFile( |
| 109 parent_folder_id, temp_file, title, | 108 parent_folder_id, temp_file, title, "application/octet-stream", |
| 110 "application/octet-stream", | 109 drive::UploadNewFileOptions(), |
| 111 drive::DriveUploader::UploadNewFileOptions(), | |
| 112 base::Bind(&UploadResultCallback, &error, &file), | 110 base::Bind(&UploadResultCallback, &error, &file), |
| 113 google_apis::ProgressCallback()); | 111 google_apis::ProgressCallback()); |
| 114 base::RunLoop().RunUntilIdle(); | 112 base::RunLoop().RunUntilIdle(); |
| 115 | 113 |
| 116 if (error == google_apis::HTTP_SUCCESS && file_id) | 114 if (error == google_apis::HTTP_SUCCESS && file_id) |
| 117 *file_id = file->file_id(); | 115 *file_id = file->file_id(); |
| 118 return error; | 116 return error; |
| 119 } | 117 } |
| 120 | 118 |
| 121 DriveApiErrorCode FakeDriveServiceHelper::UpdateFile( | 119 DriveApiErrorCode FakeDriveServiceHelper::UpdateFile( |
| 122 const std::string& file_id, | 120 const std::string& file_id, |
| 123 const std::string& content) { | 121 const std::string& content) { |
| 124 base::FilePath temp_file = WriteToTempFile(content); | 122 base::FilePath temp_file = WriteToTempFile(content); |
| 125 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 123 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 126 scoped_ptr<FileResource> file; | 124 scoped_ptr<FileResource> file; |
| 127 drive_uploader_->UploadExistingFile( | 125 drive_uploader_->UploadExistingFile( |
| 128 file_id, temp_file, | 126 file_id, temp_file, "application/octet-stream", |
| 129 "application/octet-stream", | 127 drive::UploadExistingFileOptions(), |
| 130 drive::DriveUploader::UploadExistingFileOptions(), | |
| 131 base::Bind(&UploadResultCallback, &error, &file), | 128 base::Bind(&UploadResultCallback, &error, &file), |
| 132 google_apis::ProgressCallback()); | 129 google_apis::ProgressCallback()); |
| 133 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
| 134 return error; | 131 return error; |
| 135 } | 132 } |
| 136 | 133 |
| 137 DriveApiErrorCode FakeDriveServiceHelper::DeleteResource( | 134 DriveApiErrorCode FakeDriveServiceHelper::DeleteResource( |
| 138 const std::string& file_id) { | 135 const std::string& file_id) { |
| 139 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 136 DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 140 fake_drive_service_->DeleteResource( | 137 fake_drive_service_->DeleteResource( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 const std::string& content) { | 340 const std::string& content) { |
| 344 base::FilePath temp_file; | 341 base::FilePath temp_file; |
| 345 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); | 342 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); |
| 346 EXPECT_EQ(static_cast<int>(content.size()), | 343 EXPECT_EQ(static_cast<int>(content.size()), |
| 347 base::WriteFile(temp_file, content.data(), content.size())); | 344 base::WriteFile(temp_file, content.data(), content.size())); |
| 348 return temp_file; | 345 return temp_file; |
| 349 } | 346 } |
| 350 | 347 |
| 351 } // namespace drive_backend | 348 } // namespace drive_backend |
| 352 } // namespace sync_file_system | 349 } // namespace sync_file_system |
| OLD | NEW |