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 #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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 scoped_ptr<DataType> data)> Callback; | 106 scoped_ptr<DataType> data)> Callback; |
107 | 107 |
108 // |callback| is called when the request finishes either by success or by | 108 // |callback| is called when the request finishes either by success or by |
109 // failure. On success, a JSON Value object is passed. It must not be null. | 109 // failure. On success, a JSON Value object is passed. It must not be null. |
110 DriveApiDataRequest(RequestSender* sender, const Callback& callback) | 110 DriveApiDataRequest(RequestSender* sender, const Callback& callback) |
111 : DriveApiPartialFieldRequest(sender), | 111 : DriveApiPartialFieldRequest(sender), |
112 callback_(callback), | 112 callback_(callback), |
113 weak_ptr_factory_(this) { | 113 weak_ptr_factory_(this) { |
114 DCHECK(!callback_.is_null()); | 114 DCHECK(!callback_.is_null()); |
115 } | 115 } |
116 virtual ~DriveApiDataRequest() {} | 116 ~DriveApiDataRequest() override {} |
117 | 117 |
118 protected: | 118 protected: |
119 // UrlFetchRequestBase overrides. | 119 // UrlFetchRequestBase overrides. |
120 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override { | 120 void ProcessURLFetchResults(const net::URLFetcher* source) override { |
121 DriveApiErrorCode error = GetErrorCode(); | 121 DriveApiErrorCode error = GetErrorCode(); |
122 switch (error) { | 122 switch (error) { |
123 case HTTP_SUCCESS: | 123 case HTTP_SUCCESS: |
124 case HTTP_CREATED: | 124 case HTTP_CREATED: |
125 base::PostTaskAndReplyWithResult( | 125 base::PostTaskAndReplyWithResult( |
126 blocking_task_runner(), | 126 blocking_task_runner(), |
127 FROM_HERE, | 127 FROM_HERE, |
128 base::Bind(&DriveApiDataRequest::Parse, response_writer()->data()), | 128 base::Bind(&DriveApiDataRequest::Parse, response_writer()->data()), |
129 base::Bind(&DriveApiDataRequest::OnDataParsed, | 129 base::Bind(&DriveApiDataRequest::OnDataParsed, |
130 weak_ptr_factory_.GetWeakPtr(), error)); | 130 weak_ptr_factory_.GetWeakPtr(), error)); |
131 break; | 131 break; |
132 default: | 132 default: |
133 RunCallbackOnPrematureFailure(error); | 133 RunCallbackOnPrematureFailure(error); |
134 OnProcessURLFetchResultsComplete(); | 134 OnProcessURLFetchResultsComplete(); |
135 break; | 135 break; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 virtual void RunCallbackOnPrematureFailure(DriveApiErrorCode error) override { | 139 void RunCallbackOnPrematureFailure(DriveApiErrorCode error) override { |
140 callback_.Run(error, scoped_ptr<DataType>()); | 140 callback_.Run(error, scoped_ptr<DataType>()); |
141 } | 141 } |
142 | 142 |
143 private: | 143 private: |
144 // Parses the |json| string by using DataType::CreateFrom. | 144 // Parses the |json| string by using DataType::CreateFrom. |
145 static scoped_ptr<DataType> Parse(const std::string& json) { | 145 static scoped_ptr<DataType> Parse(const std::string& json) { |
146 scoped_ptr<base::Value> value = ParseJson(json); | 146 scoped_ptr<base::Value> value = ParseJson(json); |
147 return value ? DataType::CreateFrom(*value) : scoped_ptr<DataType>(); | 147 return value ? DataType::CreateFrom(*value) : scoped_ptr<DataType>(); |
148 } | 148 } |
149 | 149 |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 // invalidate its weak pointers before any other members are destroyed. | 1174 // invalidate its weak pointers before any other members are destroyed. |
1175 base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_; | 1175 base::WeakPtrFactory<BatchUploadRequest> weak_ptr_factory_; |
1176 | 1176 |
1177 DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest); | 1177 DISALLOW_COPY_AND_ASSIGN(BatchUploadRequest); |
1178 }; | 1178 }; |
1179 | 1179 |
1180 } // namespace drive | 1180 } // namespace drive |
1181 } // namespace google_apis | 1181 } // namespace google_apis |
1182 | 1182 |
1183 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ | 1183 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_REQUESTS_H_ |
OLD | NEW |