| 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/service/fake_drive_service.h" | 5 #include "components/drive/service/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include <string> | 9 #include <string> |
| 8 | 10 |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/md5.h" | 14 #include "base/md5.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_tokenizer.h" | 17 #include "base/strings/string_tokenizer.h" |
| 16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return false; | 96 return false; |
| 95 // Search query in the title. | 97 // Search query in the title. |
| 96 if (!entry.file() || | 98 if (!entry.file() || |
| 97 entry.file()->title().find(value) == std::string::npos) | 99 entry.file()->title().find(value) == std::string::npos) |
| 98 return false; | 100 return false; |
| 99 } | 101 } |
| 100 return true; | 102 return true; |
| 101 } | 103 } |
| 102 | 104 |
| 103 void ScheduleUploadRangeCallback(const UploadRangeCallback& callback, | 105 void ScheduleUploadRangeCallback(const UploadRangeCallback& callback, |
| 104 int64 start_position, | 106 int64_t start_position, |
| 105 int64 end_position, | 107 int64_t end_position, |
| 106 DriveApiErrorCode error, | 108 DriveApiErrorCode error, |
| 107 scoped_ptr<FileResource> entry) { | 109 scoped_ptr<FileResource> entry) { |
| 108 base::ThreadTaskRunnerHandle::Get()->PostTask( | 110 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 109 FROM_HERE, | 111 FROM_HERE, |
| 110 base::Bind(callback, | 112 base::Bind(callback, |
| 111 UploadRangeResponse(error, | 113 UploadRangeResponse(error, |
| 112 start_position, | 114 start_position, |
| 113 end_position), | 115 end_position), |
| 114 base::Passed(&entry))); | 116 base::Passed(&entry))); |
| 115 } | 117 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 /* end position */ content_length, | 165 /* end position */ content_length, |
| 164 content_length, | 166 content_length, |
| 165 content_type, | 167 content_type, |
| 166 local_file_path, | 168 local_file_path, |
| 167 base::Bind(&CallFileResouceCallback, callback), | 169 base::Bind(&CallFileResouceCallback, callback), |
| 168 progress_callback); | 170 progress_callback); |
| 169 } | 171 } |
| 170 } | 172 } |
| 171 | 173 |
| 172 base::WeakPtr<FakeDriveService> service; | 174 base::WeakPtr<FakeDriveService> service; |
| 173 int64 content_length; | 175 int64_t content_length; |
| 174 std::string content_type; | 176 std::string content_type; |
| 175 base::FilePath local_file_path; | 177 base::FilePath local_file_path; |
| 176 FileResourceCallback callback; | 178 FileResourceCallback callback; |
| 177 ProgressCallback progress_callback; | 179 ProgressCallback progress_callback; |
| 178 }; | 180 }; |
| 179 | 181 |
| 180 } // namespace | 182 } // namespace |
| 181 | 183 |
| 182 struct FakeDriveService::EntryInfo { | 184 struct FakeDriveService::EntryInfo { |
| 183 EntryInfo() | 185 EntryInfo() |
| 184 : user_permission(google_apis::drive::PERMISSION_ROLE_OWNER), | 186 : user_permission(google_apis::drive::PERMISSION_ROLE_OWNER), |
| 185 visibility(google_apis::drive::FILE_VISIBILITY_DEFAULT) {} | 187 visibility(google_apis::drive::FILE_VISIBILITY_DEFAULT) {} |
| 186 | 188 |
| 187 google_apis::ChangeResource change_resource; | 189 google_apis::ChangeResource change_resource; |
| 188 GURL share_url; | 190 GURL share_url; |
| 189 std::string content_data; | 191 std::string content_data; |
| 190 | 192 |
| 191 // Behaves in the same way as "userPermission" described in | 193 // Behaves in the same way as "userPermission" described in |
| 192 // https://developers.google.com/drive/v2/reference/files | 194 // https://developers.google.com/drive/v2/reference/files |
| 193 google_apis::drive::PermissionRole user_permission; | 195 google_apis::drive::PermissionRole user_permission; |
| 194 | 196 |
| 195 google_apis::drive::FileVisibility visibility; | 197 google_apis::drive::FileVisibility visibility; |
| 196 }; | 198 }; |
| 197 | 199 |
| 198 struct FakeDriveService::UploadSession { | 200 struct FakeDriveService::UploadSession { |
| 199 std::string content_type; | 201 std::string content_type; |
| 200 int64 content_length; | 202 int64_t content_length; |
| 201 std::string parent_resource_id; | 203 std::string parent_resource_id; |
| 202 std::string resource_id; | 204 std::string resource_id; |
| 203 std::string etag; | 205 std::string etag; |
| 204 std::string title; | 206 std::string title; |
| 205 | 207 |
| 206 int64 uploaded_size; | 208 int64_t uploaded_size; |
| 207 | 209 |
| 208 UploadSession() | 210 UploadSession() |
| 209 : content_length(0), | 211 : content_length(0), |
| 210 uploaded_size(0) {} | 212 uploaded_size(0) {} |
| 211 | 213 |
| 212 UploadSession( | 214 UploadSession(std::string content_type, |
| 213 std::string content_type, | 215 int64_t content_length, |
| 214 int64 content_length, | 216 std::string parent_resource_id, |
| 215 std::string parent_resource_id, | 217 std::string resource_id, |
| 216 std::string resource_id, | 218 std::string etag, |
| 217 std::string etag, | 219 std::string title) |
| 218 std::string title) | 220 : content_type(content_type), |
| 219 : content_type(content_type), | 221 content_length(content_length), |
| 220 content_length(content_length), | 222 parent_resource_id(parent_resource_id), |
| 221 parent_resource_id(parent_resource_id), | 223 resource_id(resource_id), |
| 222 resource_id(resource_id), | 224 etag(etag), |
| 223 etag(etag), | 225 title(title), |
| 224 title(title), | 226 uploaded_size(0) {} |
| 225 uploaded_size(0) { | |
| 226 } | |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 FakeDriveService::FakeDriveService() | 229 FakeDriveService::FakeDriveService() |
| 230 : about_resource_(new AboutResource), | 230 : about_resource_(new AboutResource), |
| 231 published_date_seq_(0), | 231 published_date_seq_(0), |
| 232 next_upload_sequence_number_(0), | 232 next_upload_sequence_number_(0), |
| 233 default_max_results_(0), | 233 default_max_results_(0), |
| 234 resource_id_count_(0), | 234 resource_id_count_(0), |
| 235 file_list_load_count_(0), | 235 file_list_load_count_(0), |
| 236 change_list_load_count_(0), | 236 change_list_load_count_(0), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 std::string item_id; | 320 std::string item_id; |
| 321 if (item->GetStringWithoutPathExpansion(kKeyId, &item_id) && | 321 if (item->GetStringWithoutPathExpansion(kKeyId, &item_id) && |
| 322 item_id == app_id) { | 322 item_id == app_id) { |
| 323 return true; | 323 return true; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 return false; | 327 return false; |
| 328 } | 328 } |
| 329 | 329 |
| 330 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { | 330 void FakeDriveService::SetQuotaValue(int64_t used, int64_t total) { |
| 331 DCHECK(thread_checker_.CalledOnValidThread()); | 331 DCHECK(thread_checker_.CalledOnValidThread()); |
| 332 | 332 |
| 333 about_resource_->set_quota_bytes_used_aggregate(used); | 333 about_resource_->set_quota_bytes_used_aggregate(used); |
| 334 about_resource_->set_quota_bytes_total(total); | 334 about_resource_->set_quota_bytes_total(total); |
| 335 } | 335 } |
| 336 | 336 |
| 337 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { | 337 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { |
| 338 return GURL("https://fake_server/" + net::EscapePath(resource_id)); | 338 return GURL("https://fake_server/" + net::EscapePath(resource_id)); |
| 339 } | 339 } |
| 340 | 340 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 base::StringPrintf("title:'%s'", title.c_str()), | 451 base::StringPrintf("title:'%s'", title.c_str()), |
| 452 directory_resource_id, | 452 directory_resource_id, |
| 453 0, // start offset | 453 0, // start offset |
| 454 default_max_results_, | 454 default_max_results_, |
| 455 NULL, | 455 NULL, |
| 456 base::Bind(&FileListCallbackAdapter, callback)); | 456 base::Bind(&FileListCallbackAdapter, callback)); |
| 457 return CancelCallback(); | 457 return CancelCallback(); |
| 458 } | 458 } |
| 459 | 459 |
| 460 CancelCallback FakeDriveService::GetChangeList( | 460 CancelCallback FakeDriveService::GetChangeList( |
| 461 int64 start_changestamp, | 461 int64_t start_changestamp, |
| 462 const ChangeListCallback& callback) { | 462 const ChangeListCallback& callback) { |
| 463 DCHECK(thread_checker_.CalledOnValidThread()); | 463 DCHECK(thread_checker_.CalledOnValidThread()); |
| 464 DCHECK(!callback.is_null()); | 464 DCHECK(!callback.is_null()); |
| 465 | 465 |
| 466 GetChangeListInternal(start_changestamp, | 466 GetChangeListInternal(start_changestamp, |
| 467 std::string(), // empty search query | 467 std::string(), // empty search query |
| 468 std::string(), // no directory resource id, | 468 std::string(), // no directory resource id, |
| 469 0, // start offset | 469 0, // start offset |
| 470 default_max_results_, | 470 default_max_results_, |
| 471 &change_list_load_count_, | 471 &change_list_load_count_, |
| 472 callback); | 472 callback); |
| 473 return CancelCallback(); | 473 return CancelCallback(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 CancelCallback FakeDriveService::GetRemainingChangeList( | 476 CancelCallback FakeDriveService::GetRemainingChangeList( |
| 477 const GURL& next_link, | 477 const GURL& next_link, |
| 478 const ChangeListCallback& callback) { | 478 const ChangeListCallback& callback) { |
| 479 DCHECK(thread_checker_.CalledOnValidThread()); | 479 DCHECK(thread_checker_.CalledOnValidThread()); |
| 480 DCHECK(!next_link.is_empty()); | 480 DCHECK(!next_link.is_empty()); |
| 481 DCHECK(!callback.is_null()); | 481 DCHECK(!callback.is_null()); |
| 482 | 482 |
| 483 // "changestamp", "q", "parent" and "start-offset" are parameters to | 483 // "changestamp", "q", "parent" and "start-offset" are parameters to |
| 484 // implement "paging" of the result on FakeDriveService. | 484 // implement "paging" of the result on FakeDriveService. |
| 485 // The URL should be the one filled in GetChangeListInternal of the | 485 // The URL should be the one filled in GetChangeListInternal of the |
| 486 // previous method invocation, so it should start with "http://localhost/?". | 486 // previous method invocation, so it should start with "http://localhost/?". |
| 487 // See also GetChangeListInternal. | 487 // See also GetChangeListInternal. |
| 488 DCHECK_EQ(next_link.host(), "localhost"); | 488 DCHECK_EQ(next_link.host(), "localhost"); |
| 489 DCHECK_EQ(next_link.path(), "/"); | 489 DCHECK_EQ(next_link.path(), "/"); |
| 490 | 490 |
| 491 int64 start_changestamp = 0; | 491 int64_t start_changestamp = 0; |
| 492 std::string search_query; | 492 std::string search_query; |
| 493 std::string directory_resource_id; | 493 std::string directory_resource_id; |
| 494 int start_offset = 0; | 494 int start_offset = 0; |
| 495 int max_results = default_max_results_; | 495 int max_results = default_max_results_; |
| 496 base::StringPairs parameters; | 496 base::StringPairs parameters; |
| 497 if (base::SplitStringIntoKeyValuePairs( | 497 if (base::SplitStringIntoKeyValuePairs( |
| 498 next_link.query(), '=', '&', ¶meters)) { | 498 next_link.query(), '=', '&', ¶meters)) { |
| 499 for (size_t i = 0; i < parameters.size(); ++i) { | 499 for (size_t i = 0; i < parameters.size(); ++i) { |
| 500 if (parameters[i].first == "changestamp") { | 500 if (parameters[i].first == "changestamp") { |
| 501 base::StringToInt64(parameters[i].second, &start_changestamp); | 501 base::StringToInt64(parameters[i].second, &start_changestamp); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 EntryInfo* entry = FindEntryByResourceId(resource_id); | 755 EntryInfo* entry = FindEntryByResourceId(resource_id); |
| 756 if (!entry || entry->change_resource.file()->IsHostedDocument()) { | 756 if (!entry || entry->change_resource.file()->IsHostedDocument()) { |
| 757 base::ThreadTaskRunnerHandle::Get()->PostTask( | 757 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 758 FROM_HERE, | 758 FROM_HERE, |
| 759 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); | 759 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); |
| 760 return CancelCallback(); | 760 return CancelCallback(); |
| 761 } | 761 } |
| 762 | 762 |
| 763 const FileResource* file = entry->change_resource.file(); | 763 const FileResource* file = entry->change_resource.file(); |
| 764 const std::string& content_data = entry->content_data; | 764 const std::string& content_data = entry->content_data; |
| 765 int64 file_size = file->file_size(); | 765 int64_t file_size = file->file_size(); |
| 766 DCHECK_EQ(static_cast<size_t>(file_size), content_data.size()); | 766 DCHECK_EQ(static_cast<size_t>(file_size), content_data.size()); |
| 767 | 767 |
| 768 if (!get_content_callback.is_null()) { | 768 if (!get_content_callback.is_null()) { |
| 769 const int64 kBlockSize = 5; | 769 const int64_t kBlockSize = 5; |
| 770 for (int64 i = 0; i < file_size; i += kBlockSize) { | 770 for (int64_t i = 0; i < file_size; i += kBlockSize) { |
| 771 const int64 size = std::min(kBlockSize, file_size - i); | 771 const int64_t size = std::min(kBlockSize, file_size - i); |
| 772 scoped_ptr<std::string> content_for_callback( | 772 scoped_ptr<std::string> content_for_callback( |
| 773 new std::string(content_data.substr(i, size))); | 773 new std::string(content_data.substr(i, size))); |
| 774 base::ThreadTaskRunnerHandle::Get()->PostTask( | 774 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 775 FROM_HERE, | 775 FROM_HERE, |
| 776 base::Bind(get_content_callback, HTTP_SUCCESS, | 776 base::Bind(get_content_callback, HTTP_SUCCESS, |
| 777 base::Passed(&content_for_callback))); | 777 base::Passed(&content_for_callback))); |
| 778 } | 778 } |
| 779 } | 779 } |
| 780 | 780 |
| 781 if (!test_util::WriteStringToFile(local_cache_path, content_data)) { | 781 if (!test_util::WriteStringToFile(local_cache_path, content_data)) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 return AddNewDirectoryWithResourceId( | 1040 return AddNewDirectoryWithResourceId( |
| 1041 "", | 1041 "", |
| 1042 parent_resource_id.empty() ? GetRootResourceId() : parent_resource_id, | 1042 parent_resource_id.empty() ? GetRootResourceId() : parent_resource_id, |
| 1043 directory_title, | 1043 directory_title, |
| 1044 options, | 1044 options, |
| 1045 callback); | 1045 callback); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 CancelCallback FakeDriveService::InitiateUploadNewFile( | 1048 CancelCallback FakeDriveService::InitiateUploadNewFile( |
| 1049 const std::string& content_type, | 1049 const std::string& content_type, |
| 1050 int64 content_length, | 1050 int64_t content_length, |
| 1051 const std::string& parent_resource_id, | 1051 const std::string& parent_resource_id, |
| 1052 const std::string& title, | 1052 const std::string& title, |
| 1053 const UploadNewFileOptions& options, | 1053 const UploadNewFileOptions& options, |
| 1054 const InitiateUploadCallback& callback) { | 1054 const InitiateUploadCallback& callback) { |
| 1055 DCHECK(thread_checker_.CalledOnValidThread()); | 1055 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1056 DCHECK(!callback.is_null()); | 1056 DCHECK(!callback.is_null()); |
| 1057 | 1057 |
| 1058 if (offline_) { | 1058 if (offline_) { |
| 1059 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1059 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1060 FROM_HERE, | 1060 FROM_HERE, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1079 title); | 1079 title); |
| 1080 | 1080 |
| 1081 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1081 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1082 FROM_HERE, | 1082 FROM_HERE, |
| 1083 base::Bind(callback, HTTP_SUCCESS, session_url)); | 1083 base::Bind(callback, HTTP_SUCCESS, session_url)); |
| 1084 return CancelCallback(); | 1084 return CancelCallback(); |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 CancelCallback FakeDriveService::InitiateUploadExistingFile( | 1087 CancelCallback FakeDriveService::InitiateUploadExistingFile( |
| 1088 const std::string& content_type, | 1088 const std::string& content_type, |
| 1089 int64 content_length, | 1089 int64_t content_length, |
| 1090 const std::string& resource_id, | 1090 const std::string& resource_id, |
| 1091 const UploadExistingFileOptions& options, | 1091 const UploadExistingFileOptions& options, |
| 1092 const InitiateUploadCallback& callback) { | 1092 const InitiateUploadCallback& callback) { |
| 1093 DCHECK(thread_checker_.CalledOnValidThread()); | 1093 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1094 DCHECK(!callback.is_null()); | 1094 DCHECK(!callback.is_null()); |
| 1095 | 1095 |
| 1096 if (offline_) { | 1096 if (offline_) { |
| 1097 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1097 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1098 FROM_HERE, | 1098 FROM_HERE, |
| 1099 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); | 1099 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 "" /* title */); | 1133 "" /* title */); |
| 1134 | 1134 |
| 1135 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1135 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1136 FROM_HERE, | 1136 FROM_HERE, |
| 1137 base::Bind(callback, HTTP_SUCCESS, session_url)); | 1137 base::Bind(callback, HTTP_SUCCESS, session_url)); |
| 1138 return CancelCallback(); | 1138 return CancelCallback(); |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 CancelCallback FakeDriveService::GetUploadStatus( | 1141 CancelCallback FakeDriveService::GetUploadStatus( |
| 1142 const GURL& upload_url, | 1142 const GURL& upload_url, |
| 1143 int64 content_length, | 1143 int64_t content_length, |
| 1144 const UploadRangeCallback& callback) { | 1144 const UploadRangeCallback& callback) { |
| 1145 DCHECK(thread_checker_.CalledOnValidThread()); | 1145 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1146 DCHECK(!callback.is_null()); | 1146 DCHECK(!callback.is_null()); |
| 1147 return CancelCallback(); | 1147 return CancelCallback(); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 CancelCallback FakeDriveService::ResumeUpload( | 1150 CancelCallback FakeDriveService::ResumeUpload( |
| 1151 const GURL& upload_url, | 1151 const GURL& upload_url, |
| 1152 int64 start_position, | 1152 int64_t start_position, |
| 1153 int64 end_position, | 1153 int64_t end_position, |
| 1154 int64 content_length, | 1154 int64_t content_length, |
| 1155 const std::string& content_type, | 1155 const std::string& content_type, |
| 1156 const base::FilePath& local_file_path, | 1156 const base::FilePath& local_file_path, |
| 1157 const UploadRangeCallback& callback, | 1157 const UploadRangeCallback& callback, |
| 1158 const ProgressCallback& progress_callback) { | 1158 const ProgressCallback& progress_callback) { |
| 1159 DCHECK(thread_checker_.CalledOnValidThread()); | 1159 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1160 DCHECK(!callback.is_null()); | 1160 DCHECK(!callback.is_null()); |
| 1161 | 1161 |
| 1162 FileResourceCallback completion_callback | 1162 FileResourceCallback completion_callback |
| 1163 = base::Bind(&ScheduleUploadRangeCallback, | 1163 = base::Bind(&ScheduleUploadRangeCallback, |
| 1164 callback, start_position, end_position); | 1164 callback, start_position, end_position); |
| 1165 | 1165 |
| 1166 if (offline_) { | 1166 if (offline_) { |
| 1167 completion_callback.Run(DRIVE_NO_CONNECTION, scoped_ptr<FileResource>()); | 1167 completion_callback.Run(DRIVE_NO_CONNECTION, scoped_ptr<FileResource>()); |
| 1168 return CancelCallback(); | 1168 return CancelCallback(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1182 return CancelCallback(); | 1182 return CancelCallback(); |
| 1183 } | 1183 } |
| 1184 | 1184 |
| 1185 if (!progress_callback.is_null()) { | 1185 if (!progress_callback.is_null()) { |
| 1186 // In the real GDataWapi/Drive DriveService, progress is reported in | 1186 // In the real GDataWapi/Drive DriveService, progress is reported in |
| 1187 // nondeterministic timing. In this fake implementation, we choose to call | 1187 // nondeterministic timing. In this fake implementation, we choose to call |
| 1188 // it twice per one ResumeUpload. This is for making sure that client code | 1188 // it twice per one ResumeUpload. This is for making sure that client code |
| 1189 // works fine even if the callback is invoked more than once; it is the | 1189 // works fine even if the callback is invoked more than once; it is the |
| 1190 // crucial difference of the progress callback from others. | 1190 // crucial difference of the progress callback from others. |
| 1191 // Note that progress is notified in the relative offset in each chunk. | 1191 // Note that progress is notified in the relative offset in each chunk. |
| 1192 const int64 chunk_size = end_position - start_position; | 1192 const int64_t chunk_size = end_position - start_position; |
| 1193 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1193 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1194 FROM_HERE, base::Bind(progress_callback, chunk_size / 2, chunk_size)); | 1194 FROM_HERE, base::Bind(progress_callback, chunk_size / 2, chunk_size)); |
| 1195 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1195 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1196 FROM_HERE, base::Bind(progress_callback, chunk_size, chunk_size)); | 1196 FROM_HERE, base::Bind(progress_callback, chunk_size, chunk_size)); |
| 1197 } | 1197 } |
| 1198 | 1198 |
| 1199 if (content_length != end_position) { | 1199 if (content_length != end_position) { |
| 1200 session->uploaded_size = end_position; | 1200 session->uploaded_size = end_position; |
| 1201 completion_callback.Run(HTTP_RESUME_INCOMPLETE, scoped_ptr<FileResource>()); | 1201 completion_callback.Run(HTTP_RESUME_INCOMPLETE, scoped_ptr<FileResource>()); |
| 1202 return CancelCallback(); | 1202 return CancelCallback(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 new FileResource(*file))); | 1258 new FileResource(*file))); |
| 1259 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1259 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1260 FROM_HERE, | 1260 FROM_HERE, |
| 1261 base::Bind(&FakeDriveService::NotifyObservers, | 1261 base::Bind(&FakeDriveService::NotifyObservers, |
| 1262 weak_ptr_factory_.GetWeakPtr())); | 1262 weak_ptr_factory_.GetWeakPtr())); |
| 1263 return CancelCallback(); | 1263 return CancelCallback(); |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 CancelCallback FakeDriveService::MultipartUploadNewFile( | 1266 CancelCallback FakeDriveService::MultipartUploadNewFile( |
| 1267 const std::string& content_type, | 1267 const std::string& content_type, |
| 1268 int64 content_length, | 1268 int64_t content_length, |
| 1269 const std::string& parent_resource_id, | 1269 const std::string& parent_resource_id, |
| 1270 const std::string& title, | 1270 const std::string& title, |
| 1271 const base::FilePath& local_file_path, | 1271 const base::FilePath& local_file_path, |
| 1272 const UploadNewFileOptions& options, | 1272 const UploadNewFileOptions& options, |
| 1273 const FileResourceCallback& callback, | 1273 const FileResourceCallback& callback, |
| 1274 const ProgressCallback& progress_callback) { | 1274 const ProgressCallback& progress_callback) { |
| 1275 CallResumeUpload* const call_resume_upload = new CallResumeUpload(); | 1275 CallResumeUpload* const call_resume_upload = new CallResumeUpload(); |
| 1276 call_resume_upload->service = weak_ptr_factory_.GetWeakPtr(); | 1276 call_resume_upload->service = weak_ptr_factory_.GetWeakPtr(); |
| 1277 call_resume_upload->content_type = content_type; | 1277 call_resume_upload->content_type = content_type; |
| 1278 call_resume_upload->content_length = content_length; | 1278 call_resume_upload->content_length = content_length; |
| 1279 call_resume_upload->local_file_path = local_file_path; | 1279 call_resume_upload->local_file_path = local_file_path; |
| 1280 call_resume_upload->callback = callback; | 1280 call_resume_upload->callback = callback; |
| 1281 call_resume_upload->progress_callback = progress_callback; | 1281 call_resume_upload->progress_callback = progress_callback; |
| 1282 InitiateUploadNewFile( | 1282 InitiateUploadNewFile( |
| 1283 content_type, | 1283 content_type, |
| 1284 content_length, | 1284 content_length, |
| 1285 parent_resource_id, | 1285 parent_resource_id, |
| 1286 title, | 1286 title, |
| 1287 options, | 1287 options, |
| 1288 base::Bind(&CallResumeUpload::Run, base::Owned(call_resume_upload))); | 1288 base::Bind(&CallResumeUpload::Run, base::Owned(call_resume_upload))); |
| 1289 return CancelCallback(); | 1289 return CancelCallback(); |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 CancelCallback FakeDriveService::MultipartUploadExistingFile( | 1292 CancelCallback FakeDriveService::MultipartUploadExistingFile( |
| 1293 const std::string& content_type, | 1293 const std::string& content_type, |
| 1294 int64 content_length, | 1294 int64_t content_length, |
| 1295 const std::string& resource_id, | 1295 const std::string& resource_id, |
| 1296 const base::FilePath& local_file_path, | 1296 const base::FilePath& local_file_path, |
| 1297 const UploadExistingFileOptions& options, | 1297 const UploadExistingFileOptions& options, |
| 1298 const FileResourceCallback& callback, | 1298 const FileResourceCallback& callback, |
| 1299 const ProgressCallback& progress_callback) { | 1299 const ProgressCallback& progress_callback) { |
| 1300 CallResumeUpload* const call_resume_upload = new CallResumeUpload(); | 1300 CallResumeUpload* const call_resume_upload = new CallResumeUpload(); |
| 1301 call_resume_upload->service = weak_ptr_factory_.GetWeakPtr(); | 1301 call_resume_upload->service = weak_ptr_factory_.GetWeakPtr(); |
| 1302 call_resume_upload->content_type = content_type; | 1302 call_resume_upload->content_type = content_type; |
| 1303 call_resume_upload->content_length = content_length; | 1303 call_resume_upload->content_length = content_length; |
| 1304 call_resume_upload->local_file_path = local_file_path; | 1304 call_resume_upload->local_file_path = local_file_path; |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 base::Time published_date = | 1660 base::Time published_date = |
| 1661 base::Time() + base::TimeDelta::FromMilliseconds(++published_date_seq_); | 1661 base::Time() + base::TimeDelta::FromMilliseconds(++published_date_seq_); |
| 1662 new_file->set_created_date(published_date); | 1662 new_file->set_created_date(published_date); |
| 1663 | 1663 |
| 1664 EntryInfo* raw_new_entry = new_entry.release(); | 1664 EntryInfo* raw_new_entry = new_entry.release(); |
| 1665 entries_[resource_id] = raw_new_entry; | 1665 entries_[resource_id] = raw_new_entry; |
| 1666 return raw_new_entry; | 1666 return raw_new_entry; |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 void FakeDriveService::GetChangeListInternal( | 1669 void FakeDriveService::GetChangeListInternal( |
| 1670 int64 start_changestamp, | 1670 int64_t start_changestamp, |
| 1671 const std::string& search_query, | 1671 const std::string& search_query, |
| 1672 const std::string& directory_resource_id, | 1672 const std::string& directory_resource_id, |
| 1673 int start_offset, | 1673 int start_offset, |
| 1674 int max_results, | 1674 int max_results, |
| 1675 int* load_counter, | 1675 int* load_counter, |
| 1676 const ChangeListCallback& callback) { | 1676 const ChangeListCallback& callback) { |
| 1677 if (offline_) { | 1677 if (offline_) { |
| 1678 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1678 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1679 FROM_HERE, | 1679 FROM_HERE, |
| 1680 base::Bind(callback, | 1680 base::Bind(callback, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 | 1814 |
| 1815 NOTREACHED(); | 1815 NOTREACHED(); |
| 1816 return scoped_ptr<BatchRequestConfiguratorInterface>(); | 1816 return scoped_ptr<BatchRequestConfiguratorInterface>(); |
| 1817 } | 1817 } |
| 1818 | 1818 |
| 1819 void FakeDriveService::NotifyObservers() { | 1819 void FakeDriveService::NotifyObservers() { |
| 1820 FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable()); | 1820 FOR_EACH_OBSERVER(ChangeObserver, change_observers_, OnNewChangeAvailable()); |
| 1821 } | 1821 } |
| 1822 | 1822 |
| 1823 } // namespace drive | 1823 } // namespace drive |
| OLD | NEW |