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

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

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 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ 5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ 6 #define GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9
10 #include <memory>
9 #include <string> 11 #include <string>
10 #include <utility> 12 #include <utility>
11 #include <vector> 13 #include <vector>
12 14
13 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
14 #include "base/location.h" 16 #include "base/location.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
18 #include "base/task_runner_util.h" 19 #include "base/task_runner_util.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "base/values.h" 21 #include "base/values.h"
21 #include "google_apis/drive/base_requests.h" 22 #include "google_apis/drive/base_requests.h"
22 #include "google_apis/drive/drive_api_parser.h" 23 #include "google_apis/drive/drive_api_parser.h"
23 #include "google_apis/drive/drive_api_url_generator.h" 24 #include "google_apis/drive/drive_api_url_generator.h"
24 #include "google_apis/drive/drive_common_callbacks.h" 25 #include "google_apis/drive/drive_common_callbacks.h"
25 26
26 namespace google_apis { 27 namespace google_apis {
27 28
28 // Callback used for requests that the server returns FileList data 29 // Callback used for requests that the server returns FileList data
29 // formatted into JSON value. 30 // formatted into JSON value.
30 typedef base::Callback<void(DriveApiErrorCode error, 31 typedef base::Callback<void(DriveApiErrorCode error,
31 scoped_ptr<FileList> entry)> FileListCallback; 32 std::unique_ptr<FileList> entry)>
33 FileListCallback;
32 34
33 // Callback used for requests that the server returns ChangeList data 35 // Callback used for requests that the server returns ChangeList data
34 // formatted into JSON value. 36 // formatted into JSON value.
35 typedef base::Callback<void(DriveApiErrorCode error, 37 typedef base::Callback<void(DriveApiErrorCode error,
36 scoped_ptr<ChangeList> entry)> ChangeListCallback; 38 std::unique_ptr<ChangeList> entry)>
39 ChangeListCallback;
37 40
38 namespace drive { 41 namespace drive {
39 42
40 // Represents a property for a file or a directory. 43 // Represents a property for a file or a directory.
41 // https://developers.google.com/drive/v2/reference/properties 44 // https://developers.google.com/drive/v2/reference/properties
42 class Property { 45 class Property {
43 public: 46 public:
44 Property(); 47 Property();
45 ~Property(); 48 ~Property();
46 49
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 }; 117 };
115 118
116 //============================ DriveApiDataRequest =========================== 119 //============================ DriveApiDataRequest ===========================
117 120
118 // The base class of Drive API related requests that receive a JSON response 121 // The base class of Drive API related requests that receive a JSON response
119 // representing |DataType|. 122 // representing |DataType|.
120 template<class DataType> 123 template<class DataType>
121 class DriveApiDataRequest : public DriveApiPartialFieldRequest { 124 class DriveApiDataRequest : public DriveApiPartialFieldRequest {
122 public: 125 public:
123 typedef base::Callback<void(DriveApiErrorCode error, 126 typedef base::Callback<void(DriveApiErrorCode error,
124 scoped_ptr<DataType> data)> Callback; 127 std::unique_ptr<DataType> data)>
128 Callback;
125 129
126 // |callback| is called when the request finishes either by success or by 130 // |callback| is called when the request finishes either by success or by
127 // failure. On success, a JSON Value object is passed. It must not be null. 131 // failure. On success, a JSON Value object is passed. It must not be null.
128 DriveApiDataRequest(RequestSender* sender, const Callback& callback) 132 DriveApiDataRequest(RequestSender* sender, const Callback& callback)
129 : DriveApiPartialFieldRequest(sender), 133 : DriveApiPartialFieldRequest(sender),
130 callback_(callback), 134 callback_(callback),
131 weak_ptr_factory_(this) { 135 weak_ptr_factory_(this) {
132 DCHECK(!callback_.is_null()); 136 DCHECK(!callback_.is_null());
133 } 137 }
134 ~DriveApiDataRequest() override {} 138 ~DriveApiDataRequest() override {}
(...skipping 13 matching lines...) Expand all
148 weak_ptr_factory_.GetWeakPtr(), error)); 152 weak_ptr_factory_.GetWeakPtr(), error));
149 break; 153 break;
150 default: 154 default:
151 RunCallbackOnPrematureFailure(error); 155 RunCallbackOnPrematureFailure(error);
152 OnProcessURLFetchResultsComplete(); 156 OnProcessURLFetchResultsComplete();
153 break; 157 break;
154 } 158 }
155 } 159 }
156 160
157 void RunCallbackOnPrematureFailure(DriveApiErrorCode error) override { 161 void RunCallbackOnPrematureFailure(DriveApiErrorCode error) override {
158 callback_.Run(error, scoped_ptr<DataType>()); 162 callback_.Run(error, std::unique_ptr<DataType>());
159 } 163 }
160 164
161 private: 165 private:
162 // Parses the |json| string by using DataType::CreateFrom. 166 // Parses the |json| string by using DataType::CreateFrom.
163 static scoped_ptr<DataType> Parse(const std::string& json) { 167 static std::unique_ptr<DataType> Parse(const std::string& json) {
164 scoped_ptr<base::Value> value = ParseJson(json); 168 std::unique_ptr<base::Value> value = ParseJson(json);
165 return value ? DataType::CreateFrom(*value) : scoped_ptr<DataType>(); 169 return value ? DataType::CreateFrom(*value) : std::unique_ptr<DataType>();
166 } 170 }
167 171
168 // Receives the parsed result and invokes the callback. 172 // Receives the parsed result and invokes the callback.
169 void OnDataParsed(DriveApiErrorCode error, scoped_ptr<DataType> value) { 173 void OnDataParsed(DriveApiErrorCode error, std::unique_ptr<DataType> value) {
170 if (!value) 174 if (!value)
171 error = DRIVE_PARSE_ERROR; 175 error = DRIVE_PARSE_ERROR;
172 callback_.Run(error, std::move(value)); 176 callback_.Run(error, std::move(value));
173 OnProcessURLFetchResultsComplete(); 177 OnProcessURLFetchResultsComplete();
174 } 178 }
175 179
176 const Callback callback_; 180 const Callback callback_;
177 181
178 // Note: This should remain the last member so it'll be destroyed and 182 // Note: This should remain the last member so it'll be destroyed and
179 // invalidate its weak pointers before any other members are destroyed. 183 // invalidate its weak pointers before any other members are destroyed.
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 std::string parent_resource_id_; 924 std::string parent_resource_id_;
921 std::string title_; 925 std::string title_;
922 base::Time modified_date_; 926 base::Time modified_date_;
923 base::Time last_viewed_by_me_date_; 927 base::Time last_viewed_by_me_date_;
924 Properties properties_; 928 Properties properties_;
925 929
926 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest); 930 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileRequest);
927 }; 931 };
928 932
929 // Callback used for ResumeUpload() and GetUploadStatus(). 933 // Callback used for ResumeUpload() and GetUploadStatus().
930 typedef base::Callback<void( 934 typedef base::Callback<void(const UploadRangeResponse& response,
931 const UploadRangeResponse& response, 935 std::unique_ptr<FileResource> new_resource)>
932 scoped_ptr<FileResource> new_resource)> UploadRangeCallback; 936 UploadRangeCallback;
933 937
934 //============================ ResumeUploadRequest =========================== 938 //============================ ResumeUploadRequest ===========================
935 939
936 // Performs the request for resuming the upload of a file. 940 // Performs the request for resuming the upload of a file.
937 class ResumeUploadRequest : public ResumeUploadRequestBase { 941 class ResumeUploadRequest : public ResumeUploadRequestBase {
938 public: 942 public:
939 // See also ResumeUploadRequestBase's comment for parameters meaning. 943 // See also ResumeUploadRequestBase's comment for parameters meaning.
940 // |callback| must not be null. |progress_callback| may be null. 944 // |callback| must not be null. |progress_callback| may be null.
941 ResumeUploadRequest(RequestSender* sender, 945 ResumeUploadRequest(RequestSender* sender,
942 const GURL& upload_location, 946 const GURL& upload_location,
943 int64_t start_position, 947 int64_t start_position,
944 int64_t end_position, 948 int64_t end_position,
945 int64_t content_length, 949 int64_t content_length,
946 const std::string& content_type, 950 const std::string& content_type,
947 const base::FilePath& local_file_path, 951 const base::FilePath& local_file_path,
948 const UploadRangeCallback& callback, 952 const UploadRangeCallback& callback,
949 const ProgressCallback& progress_callback); 953 const ProgressCallback& progress_callback);
950 ~ResumeUploadRequest() override; 954 ~ResumeUploadRequest() override;
951 955
952 protected: 956 protected:
953 // UploadRangeRequestBase overrides. 957 // UploadRangeRequestBase overrides.
954 void OnRangeRequestComplete(const UploadRangeResponse& response, 958 void OnRangeRequestComplete(const UploadRangeResponse& response,
955 scoped_ptr<base::Value> value) override; 959 std::unique_ptr<base::Value> value) override;
956 // content::UrlFetcherDelegate overrides. 960 // content::UrlFetcherDelegate overrides.
957 void OnURLFetchUploadProgress(const net::URLFetcher* source, 961 void OnURLFetchUploadProgress(const net::URLFetcher* source,
958 int64_t current, 962 int64_t current,
959 int64_t total) override; 963 int64_t total) override;
960 964
961 private: 965 private:
962 const UploadRangeCallback callback_; 966 const UploadRangeCallback callback_;
963 const ProgressCallback progress_callback_; 967 const ProgressCallback progress_callback_;
964 968
965 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest); 969 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequest);
966 }; 970 };
967 971
968 //========================== GetUploadStatusRequest ========================== 972 //========================== GetUploadStatusRequest ==========================
969 973
970 // Performs the request to fetch the current upload status of a file. 974 // Performs the request to fetch the current upload status of a file.
971 class GetUploadStatusRequest : public GetUploadStatusRequestBase { 975 class GetUploadStatusRequest : public GetUploadStatusRequestBase {
972 public: 976 public:
973 // See also GetUploadStatusRequestBase's comment for parameters meaning. 977 // See also GetUploadStatusRequestBase's comment for parameters meaning.
974 // |callback| must not be null. 978 // |callback| must not be null.
975 GetUploadStatusRequest(RequestSender* sender, 979 GetUploadStatusRequest(RequestSender* sender,
976 const GURL& upload_url, 980 const GURL& upload_url,
977 int64_t content_length, 981 int64_t content_length,
978 const UploadRangeCallback& callback); 982 const UploadRangeCallback& callback);
979 ~GetUploadStatusRequest() override; 983 ~GetUploadStatusRequest() override;
980 984
981 protected: 985 protected:
982 // UploadRangeRequestBase overrides. 986 // UploadRangeRequestBase overrides.
983 void OnRangeRequestComplete(const UploadRangeResponse& response, 987 void OnRangeRequestComplete(const UploadRangeResponse& response,
984 scoped_ptr<base::Value> value) override; 988 std::unique_ptr<base::Value> value) override;
985 989
986 private: 990 private:
987 const UploadRangeCallback callback_; 991 const UploadRangeCallback callback_;
988 992
989 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest); 993 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest);
990 }; 994 };
991 995
992 //======================= MultipartUploadNewFileDelegate ======================= 996 //======================= MultipartUploadNewFileDelegate =======================
993 997
994 // This class performs the request for initiating the upload of a new file. 998 // This class performs the request for initiating the upload of a new file.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 net::URLFetcher::RequestType GetRequestType() const override; 1150 net::URLFetcher::RequestType GetRequestType() const override;
1147 std::vector<std::string> GetExtraRequestHeaders() const override; 1151 std::vector<std::string> GetExtraRequestHeaders() const override;
1148 void Prepare(const PrepareCallback& callback) override; 1152 void Prepare(const PrepareCallback& callback) override;
1149 bool GetContentData(std::string* upload_content_type, 1153 bool GetContentData(std::string* upload_content_type,
1150 std::string* upload_content) override; 1154 std::string* upload_content) override;
1151 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override; 1155 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override;
1152 void ProcessURLFetchResults(const net::URLFetcher* source) override; 1156 void ProcessURLFetchResults(const net::URLFetcher* source) override;
1153 void OnURLFetchUploadProgress(const net::URLFetcher* source, 1157 void OnURLFetchUploadProgress(const net::URLFetcher* source,
1154 int64_t current, 1158 int64_t current,
1155 int64_t total) override; 1159 int64_t total) override;
1156 scoped_ptr<BatchableDelegate> delegate_; 1160 std::unique_ptr<BatchableDelegate> delegate_;
1157 1161
1158 // Note: This should remain the last member so it'll be destroyed and 1162 // Note: This should remain the last member so it'll be destroyed and
1159 // invalidate its weak pointers before any other members are destroyed. 1163 // invalidate its weak pointers before any other members are destroyed.
1160 base::WeakPtrFactory<SingleBatchableDelegateRequest> weak_ptr_factory_; 1164 base::WeakPtrFactory<SingleBatchableDelegateRequest> weak_ptr_factory_;
1161 1165
1162 DISALLOW_COPY_AND_ASSIGN(SingleBatchableDelegateRequest); 1166 DISALLOW_COPY_AND_ASSIGN(SingleBatchableDelegateRequest);
1163 }; 1167 };
1164 1168
1165 //========================== BatchUploadRequest ========================== 1169 //========================== BatchUploadRequest ==========================
1166 1170
1167 class BatchUploadChildEntry { 1171 class BatchUploadChildEntry {
1168 public: 1172 public:
1169 explicit BatchUploadChildEntry(BatchableDelegate* request); 1173 explicit BatchUploadChildEntry(BatchableDelegate* request);
1170 ~BatchUploadChildEntry(); 1174 ~BatchUploadChildEntry();
1171 scoped_ptr<BatchableDelegate> request; 1175 std::unique_ptr<BatchableDelegate> request;
1172 bool prepared; 1176 bool prepared;
1173 int64_t data_offset; 1177 int64_t data_offset;
1174 int64_t data_size; 1178 int64_t data_size;
1175 1179
1176 private: 1180 private:
1177 DISALLOW_COPY_AND_ASSIGN(BatchUploadChildEntry); 1181 DISALLOW_COPY_AND_ASSIGN(BatchUploadChildEntry);
1178 }; 1182 };
1179 1183
1180 class BatchUploadRequest : public UrlFetchRequestBase { 1184 class BatchUploadRequest : public UrlFetchRequestBase {
1181 public: 1185 public:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 // invalidate its weak pointers before any other members are destroyed. 1259 // invalidate its weak pointers before any other members are destroyed.
1256 base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_; 1260 base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_;
1257 1261
1258 DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest); 1262 DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest);
1259 }; 1263 };
1260 1264
1261 } // namespace drive 1265 } // namespace drive
1262 } // namespace google_apis 1266 } // namespace google_apis
1263 1267
1264 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ 1268 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698