| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/drive/drive_uploader.h" | 5 #include "components/drive/drive_uploader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // The upload range should start from the current first unreceived byte. | 163 // The upload range should start from the current first unreceived byte. |
| 164 EXPECT_EQ(received_bytes_, start_position); | 164 EXPECT_EQ(received_bytes_, start_position); |
| 165 EXPECT_EQ(expected_upload_file_, local_file_path); | 165 EXPECT_EQ(expected_upload_file_, local_file_path); |
| 166 | 166 |
| 167 // The upload data must be split into 512KB chunks. | 167 // The upload data must be split into 512KB chunks. |
| 168 const int64_t expected_chunk_end = | 168 const int64_t expected_chunk_end = |
| 169 std::min(received_bytes_ + kUploadChunkSize, expected_content_length_); | 169 std::min(received_bytes_ + kUploadChunkSize, expected_content_length_); |
| 170 EXPECT_EQ(expected_chunk_end, end_position); | 170 EXPECT_EQ(expected_chunk_end, end_position); |
| 171 | 171 |
| 172 // The upload URL returned by InitiateUpload() must be used. | 172 // The upload URL returned by InitiateUpload() must be used. |
| 173 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location || | 173 EXPECT_TRUE(upload_location == kTestUploadNewFileURL || |
| 174 GURL(kTestUploadExistingFileURL) == upload_location); | 174 upload_location == kTestUploadExistingFileURL); |
| 175 | 175 |
| 176 // Other parameters should be the exact values passed to DriveUploader. | 176 // Other parameters should be the exact values passed to DriveUploader. |
| 177 EXPECT_EQ(expected_content_length_, content_length); | 177 EXPECT_EQ(expected_content_length_, content_length); |
| 178 EXPECT_EQ(kTestMimeType, content_type); | 178 EXPECT_EQ(kTestMimeType, content_type); |
| 179 | 179 |
| 180 // Update the internal status of the current upload session. | 180 // Update the internal status of the current upload session. |
| 181 resume_upload_call_count_++; | 181 resume_upload_call_count_++; |
| 182 received_bytes_ = end_position; | 182 received_bytes_ = end_position; |
| 183 | 183 |
| 184 // Callback progress | 184 // Callback progress |
| 185 if (!progress_callback.is_null()) { | 185 if (!progress_callback.is_null()) { |
| 186 // For the testing purpose, it always notifies the progress at the end of | 186 // For the testing purpose, it always notifies the progress at the end of |
| 187 // each chunk uploading. | 187 // each chunk uploading. |
| 188 int64_t chunk_size = end_position - start_position; | 188 int64_t chunk_size = end_position - start_position; |
| 189 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 189 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 190 base::Bind(progress_callback, chunk_size, chunk_size)); | 190 base::Bind(progress_callback, chunk_size, chunk_size)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 SendUploadRangeResponse(upload_location, callback); | 193 SendUploadRangeResponse(upload_location, callback); |
| 194 return CancelCallback(); | 194 return CancelCallback(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Handles a request to fetch the current upload status. | 197 // Handles a request to fetch the current upload status. |
| 198 CancelCallback GetUploadStatus(const GURL& upload_location, | 198 CancelCallback GetUploadStatus(const GURL& upload_location, |
| 199 int64_t content_length, | 199 int64_t content_length, |
| 200 const UploadRangeCallback& callback) override { | 200 const UploadRangeCallback& callback) override { |
| 201 EXPECT_EQ(expected_content_length_, content_length); | 201 EXPECT_EQ(expected_content_length_, content_length); |
| 202 // The upload URL returned by InitiateUpload() must be used. | 202 // The upload URL returned by InitiateUpload() must be used. |
| 203 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location || | 203 EXPECT_TRUE(upload_location == kTestUploadNewFileURL || |
| 204 GURL(kTestUploadExistingFileURL) == upload_location); | 204 upload_location == kTestUploadExistingFileURL); |
| 205 | 205 |
| 206 SendUploadRangeResponse(upload_location, callback); | 206 SendUploadRangeResponse(upload_location, callback); |
| 207 return CancelCallback(); | 207 return CancelCallback(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Runs |callback| with the current upload status. | 210 // Runs |callback| with the current upload status. |
| 211 void SendUploadRangeResponse(const GURL& upload_location, | 211 void SendUploadRangeResponse(const GURL& upload_location, |
| 212 const UploadRangeCallback& callback) { | 212 const UploadRangeCallback& callback) { |
| 213 // Callback with response. | 213 // Callback with response. |
| 214 UploadRangeResponse response; | 214 UploadRangeResponse response; |
| 215 std::unique_ptr<FileResource> entry; | 215 std::unique_ptr<FileResource> entry; |
| 216 if (received_bytes_ == expected_content_length_) { | 216 if (received_bytes_ == expected_content_length_) { |
| 217 DriveApiErrorCode response_code = | 217 DriveApiErrorCode response_code = |
| 218 upload_location == GURL(kTestUploadNewFileURL) ? | 218 upload_location == kTestUploadNewFileURL ? |
| 219 HTTP_CREATED : HTTP_SUCCESS; | 219 HTTP_CREATED : HTTP_SUCCESS; |
| 220 response = UploadRangeResponse(response_code, -1, -1); | 220 response = UploadRangeResponse(response_code, -1, -1); |
| 221 | 221 |
| 222 entry.reset(new FileResource); | 222 entry.reset(new FileResource); |
| 223 entry->set_md5_checksum(kTestDummyMd5); | 223 entry->set_md5_checksum(kTestDummyMd5); |
| 224 } else { | 224 } else { |
| 225 response = UploadRangeResponse( | 225 response = UploadRangeResponse( |
| 226 HTTP_RESUME_INCOMPLETE, 0, received_bytes_); | 226 HTTP_RESUME_INCOMPLETE, 0, received_bytes_); |
| 227 } | 227 } |
| 228 // ResumeUpload is an asynchronous function, so don't callback directly. | 228 // ResumeUpload is an asynchronous function, so don't callback directly. |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 | 951 |
| 952 EXPECT_EQ(HTTP_NOT_FOUND, results[0].error); | 952 EXPECT_EQ(HTTP_NOT_FOUND, results[0].error); |
| 953 EXPECT_TRUE(results[0].resume_url.is_empty()); | 953 EXPECT_TRUE(results[0].resume_url.is_empty()); |
| 954 EXPECT_FALSE(results[0].file); | 954 EXPECT_FALSE(results[0].file); |
| 955 | 955 |
| 956 EXPECT_EQ(HTTP_NOT_FOUND, results[1].error); | 956 EXPECT_EQ(HTTP_NOT_FOUND, results[1].error); |
| 957 EXPECT_TRUE(results[1].resume_url.is_empty()); | 957 EXPECT_TRUE(results[1].resume_url.is_empty()); |
| 958 EXPECT_FALSE(results[1].file); | 958 EXPECT_FALSE(results[1].file); |
| 959 } | 959 } |
| 960 } // namespace drive | 960 } // namespace drive |
| OLD | NEW |