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

Side by Side Diff: google_apis/drive/drive_api_requests.cc

Issue 1873663002: Convert //google_apis 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 (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 "google_apis/drive/drive_api_requests.h" 5 #include "google_apis/drive/drive_api_requests.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const char kUMADriveBatchUploadResponseCode[] = "Drive.BatchUploadResponseCode"; 53 const char kUMADriveBatchUploadResponseCode[] = "Drive.BatchUploadResponseCode";
54 const char kUMADriveTotalFileCountInBatchUpload[] = 54 const char kUMADriveTotalFileCountInBatchUpload[] =
55 "Drive.TotalFileCountInBatchUpload"; 55 "Drive.TotalFileCountInBatchUpload";
56 const char kUMADriveTotalFileSizeInBatchUpload[] = 56 const char kUMADriveTotalFileSizeInBatchUpload[] =
57 "Drive.TotalFileSizeInBatchUpload"; 57 "Drive.TotalFileSizeInBatchUpload";
58 58
59 // Parses the JSON value to FileResource instance and runs |callback| on the 59 // Parses the JSON value to FileResource instance and runs |callback| on the
60 // UI thread once parsing is done. 60 // UI thread once parsing is done.
61 // This is customized version of ParseJsonAndRun defined above to adapt the 61 // This is customized version of ParseJsonAndRun defined above to adapt the
62 // remaining response type. 62 // remaining response type.
63 void ParseFileResourceWithUploadRangeAndRun(const UploadRangeCallback& callback, 63 void ParseFileResourceWithUploadRangeAndRun(
64 const UploadRangeResponse& response, 64 const UploadRangeCallback& callback,
65 scoped_ptr<base::Value> value) { 65 const UploadRangeResponse& response,
66 std::unique_ptr<base::Value> value) {
66 DCHECK(!callback.is_null()); 67 DCHECK(!callback.is_null());
67 68
68 scoped_ptr<FileResource> file_resource; 69 std::unique_ptr<FileResource> file_resource;
69 if (value) { 70 if (value) {
70 file_resource = FileResource::CreateFrom(*value); 71 file_resource = FileResource::CreateFrom(*value);
71 if (!file_resource) { 72 if (!file_resource) {
72 callback.Run( 73 callback.Run(UploadRangeResponse(DRIVE_PARSE_ERROR,
73 UploadRangeResponse(DRIVE_PARSE_ERROR, 74 response.start_position_received,
74 response.start_position_received, 75 response.end_position_received),
75 response.end_position_received), 76 std::unique_ptr<FileResource>());
76 scoped_ptr<FileResource>());
77 return; 77 return;
78 } 78 }
79 } 79 }
80 80
81 callback.Run(response, std::move(file_resource)); 81 callback.Run(response, std::move(file_resource));
82 } 82 }
83 83
84 // Attaches |properties| to the |request_body| if |properties| is not empty. 84 // Attaches |properties| to the |request_body| if |properties| is not empty.
85 // |request_body| must not be NULL. 85 // |request_body| must not be NULL.
86 void AttachProperties(const Properties& properties, 86 void AttachProperties(const Properties& properties,
(...skipping 30 matching lines...) Expand all
117 const std::string& parent_resource_id, 117 const std::string& parent_resource_id,
118 const base::Time& modified_date, 118 const base::Time& modified_date,
119 const base::Time& last_viewed_by_me_date, 119 const base::Time& last_viewed_by_me_date,
120 const Properties& properties) { 120 const Properties& properties) {
121 base::DictionaryValue root; 121 base::DictionaryValue root;
122 if (!title.empty()) 122 if (!title.empty())
123 root.SetString("title", title); 123 root.SetString("title", title);
124 124
125 // Fill parent link. 125 // Fill parent link.
126 if (!parent_resource_id.empty()) { 126 if (!parent_resource_id.empty()) {
127 scoped_ptr<base::ListValue> parents(new base::ListValue); 127 std::unique_ptr<base::ListValue> parents(new base::ListValue);
128 parents->Append( 128 parents->Append(
129 google_apis::util::CreateParentValue(parent_resource_id).release()); 129 google_apis::util::CreateParentValue(parent_resource_id).release());
130 root.Set("parents", parents.release()); 130 root.Set("parents", parents.release());
131 } 131 }
132 132
133 if (!modified_date.is_null()) { 133 if (!modified_date.is_null()) {
134 root.SetString("modifiedDate", 134 root.SetString("modifiedDate",
135 google_apis::util::FormatTimeAsString(modified_date)); 135 google_apis::util::FormatTimeAsString(modified_date));
136 } 136 }
137 137
(...skipping 30 matching lines...) Expand all
168 base::StringPiece TrimTransportPadding(const base::StringPiece& piece) { 168 base::StringPiece TrimTransportPadding(const base::StringPiece& piece) {
169 size_t trim_size = 0; 169 size_t trim_size = 0;
170 while (trim_size < piece.size() && 170 while (trim_size < piece.size() &&
171 (piece[piece.size() - 1 - trim_size] == ' ' || 171 (piece[piece.size() - 1 - trim_size] == ' ' ||
172 piece[piece.size() - 1 - trim_size] == '\t')) { 172 piece[piece.size() - 1 - trim_size] == '\t')) {
173 ++trim_size; 173 ++trim_size;
174 } 174 }
175 return piece.substr(0, piece.size() - trim_size); 175 return piece.substr(0, piece.size() - trim_size);
176 } 176 }
177 177
178 void EmptyClosure(scoped_ptr<BatchableDelegate>) { 178 void EmptyClosure(std::unique_ptr<BatchableDelegate>) {}
179 }
180 179
181 } // namespace 180 } // namespace
182 181
183 MultipartHttpResponse::MultipartHttpResponse() : code(HTTP_SUCCESS) { 182 MultipartHttpResponse::MultipartHttpResponse() : code(HTTP_SUCCESS) {
184 } 183 }
185 184
186 MultipartHttpResponse::~MultipartHttpResponse() { 185 MultipartHttpResponse::~MultipartHttpResponse() {
187 } 186 }
188 187
189 // The |response| must be multipart/mixed format that contains child HTTP 188 // The |response| must be multipart/mixed format that contains child HTTP
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 825
827 bool InitiateUploadNewFileRequest::GetContentData( 826 bool InitiateUploadNewFileRequest::GetContentData(
828 std::string* upload_content_type, 827 std::string* upload_content_type,
829 std::string* upload_content) { 828 std::string* upload_content) {
830 *upload_content_type = util::kContentTypeApplicationJson; 829 *upload_content_type = util::kContentTypeApplicationJson;
831 830
832 base::DictionaryValue root; 831 base::DictionaryValue root;
833 root.SetString("title", title_); 832 root.SetString("title", title_);
834 833
835 // Fill parent link. 834 // Fill parent link.
836 scoped_ptr<base::ListValue> parents(new base::ListValue); 835 std::unique_ptr<base::ListValue> parents(new base::ListValue);
837 parents->Append(util::CreateParentValue(parent_resource_id_).release()); 836 parents->Append(util::CreateParentValue(parent_resource_id_).release());
838 root.Set("parents", parents.release()); 837 root.Set("parents", parents.release());
839 838
840 if (!modified_date_.is_null()) 839 if (!modified_date_.is_null())
841 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); 840 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_));
842 841
843 if (!last_viewed_by_me_date_.is_null()) { 842 if (!last_viewed_by_me_date_.is_null()) {
844 root.SetString("lastViewedByMeDate", 843 root.SetString("lastViewedByMeDate",
845 util::FormatTimeAsString(last_viewed_by_me_date_)); 844 util::FormatTimeAsString(last_viewed_by_me_date_));
846 } 845 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 InitiateUploadRequestBase::GetExtraRequestHeaders()); 885 InitiateUploadRequestBase::GetExtraRequestHeaders());
887 headers.push_back(util::GenerateIfMatchHeader(etag_)); 886 headers.push_back(util::GenerateIfMatchHeader(etag_));
888 return headers; 887 return headers;
889 } 888 }
890 889
891 bool InitiateUploadExistingFileRequest::GetContentData( 890 bool InitiateUploadExistingFileRequest::GetContentData(
892 std::string* upload_content_type, 891 std::string* upload_content_type,
893 std::string* upload_content) { 892 std::string* upload_content) {
894 base::DictionaryValue root; 893 base::DictionaryValue root;
895 if (!parent_resource_id_.empty()) { 894 if (!parent_resource_id_.empty()) {
896 scoped_ptr<base::ListValue> parents(new base::ListValue); 895 std::unique_ptr<base::ListValue> parents(new base::ListValue);
897 parents->Append(util::CreateParentValue(parent_resource_id_).release()); 896 parents->Append(util::CreateParentValue(parent_resource_id_).release());
898 root.Set("parents", parents.release()); 897 root.Set("parents", parents.release());
899 } 898 }
900 899
901 if (!title_.empty()) 900 if (!title_.empty())
902 root.SetString("title", title_); 901 root.SetString("title", title_);
903 902
904 if (!modified_date_.is_null()) 903 if (!modified_date_.is_null())
905 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_)); 904 root.SetString("modifiedDate", util::FormatTimeAsString(modified_date_));
906 905
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 local_file_path), 940 local_file_path),
942 callback_(callback), 941 callback_(callback),
943 progress_callback_(progress_callback) { 942 progress_callback_(progress_callback) {
944 DCHECK(!callback_.is_null()); 943 DCHECK(!callback_.is_null());
945 } 944 }
946 945
947 ResumeUploadRequest::~ResumeUploadRequest() {} 946 ResumeUploadRequest::~ResumeUploadRequest() {}
948 947
949 void ResumeUploadRequest::OnRangeRequestComplete( 948 void ResumeUploadRequest::OnRangeRequestComplete(
950 const UploadRangeResponse& response, 949 const UploadRangeResponse& response,
951 scoped_ptr<base::Value> value) { 950 std::unique_ptr<base::Value> value) {
952 DCHECK(CalledOnValidThread()); 951 DCHECK(CalledOnValidThread());
953 ParseFileResourceWithUploadRangeAndRun(callback_, response, std::move(value)); 952 ParseFileResourceWithUploadRangeAndRun(callback_, response, std::move(value));
954 } 953 }
955 954
956 void ResumeUploadRequest::OnURLFetchUploadProgress( 955 void ResumeUploadRequest::OnURLFetchUploadProgress(
957 const net::URLFetcher* source, 956 const net::URLFetcher* source,
958 int64_t current, 957 int64_t current,
959 int64_t total) { 958 int64_t total) {
960 if (!progress_callback_.is_null()) 959 if (!progress_callback_.is_null())
961 progress_callback_.Run(current, total); 960 progress_callback_.Run(current, total);
962 } 961 }
963 962
964 //========================== GetUploadStatusRequest ========================== 963 //========================== GetUploadStatusRequest ==========================
965 964
966 GetUploadStatusRequest::GetUploadStatusRequest( 965 GetUploadStatusRequest::GetUploadStatusRequest(
967 RequestSender* sender, 966 RequestSender* sender,
968 const GURL& upload_url, 967 const GURL& upload_url,
969 int64_t content_length, 968 int64_t content_length,
970 const UploadRangeCallback& callback) 969 const UploadRangeCallback& callback)
971 : GetUploadStatusRequestBase(sender, upload_url, content_length), 970 : GetUploadStatusRequestBase(sender, upload_url, content_length),
972 callback_(callback) { 971 callback_(callback) {
973 DCHECK(!callback.is_null()); 972 DCHECK(!callback.is_null());
974 } 973 }
975 974
976 GetUploadStatusRequest::~GetUploadStatusRequest() {} 975 GetUploadStatusRequest::~GetUploadStatusRequest() {}
977 976
978 void GetUploadStatusRequest::OnRangeRequestComplete( 977 void GetUploadStatusRequest::OnRangeRequestComplete(
979 const UploadRangeResponse& response, 978 const UploadRangeResponse& response,
980 scoped_ptr<base::Value> value) { 979 std::unique_ptr<base::Value> value) {
981 DCHECK(CalledOnValidThread()); 980 DCHECK(CalledOnValidThread());
982 ParseFileResourceWithUploadRangeAndRun(callback_, response, std::move(value)); 981 ParseFileResourceWithUploadRangeAndRun(callback_, response, std::move(value));
983 } 982 }
984 983
985 //======================= MultipartUploadNewFileDelegate ======================= 984 //======================= MultipartUploadNewFileDelegate =======================
986 985
987 MultipartUploadNewFileDelegate::MultipartUploadNewFileDelegate( 986 MultipartUploadNewFileDelegate::MultipartUploadNewFileDelegate(
988 base::SequencedTaskRunner* task_runner, 987 base::SequencedTaskRunner* task_runner,
989 const std::string& title, 988 const std::string& title,
990 const std::string& parent_resource_id, 989 const std::string& parent_resource_id,
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 } else if (last_progress_value_ < child->data_offset + child->data_size && 1453 } else if (last_progress_value_ < child->data_offset + child->data_size &&
1455 child->data_offset + child->data_size < current) { 1454 child->data_offset + child->data_size < current) {
1456 child->request->NotifyUploadProgress(source, child->data_size, 1455 child->request->NotifyUploadProgress(source, child->data_size,
1457 child->data_size); 1456 child->data_size);
1458 } 1457 }
1459 } 1458 }
1460 last_progress_value_ = current; 1459 last_progress_value_ = current;
1461 } 1460 }
1462 } // namespace drive 1461 } // namespace drive
1463 } // namespace google_apis 1462 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698