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

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

Issue 1218773003: Implement a DRIVE_REQUEST_TOO_LARGE backoff. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 5 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/base_requests.h" 5 #include "google_apis/drive/base_requests.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return code; 145 return code;
146 146
147 DVLOG(1) << error_body; 147 DVLOG(1) << error_body;
148 const char kErrorKey[] = "error"; 148 const char kErrorKey[] = "error";
149 const char kErrorErrorsKey[] = "errors"; 149 const char kErrorErrorsKey[] = "errors";
150 const char kErrorReasonKey[] = "reason"; 150 const char kErrorReasonKey[] = "reason";
151 const char kErrorMessageKey[] = "message"; 151 const char kErrorMessageKey[] = "message";
152 const char kErrorReasonRateLimitExceeded[] = "rateLimitExceeded"; 152 const char kErrorReasonRateLimitExceeded[] = "rateLimitExceeded";
153 const char kErrorReasonUserRateLimitExceeded[] = "userRateLimitExceeded"; 153 const char kErrorReasonUserRateLimitExceeded[] = "userRateLimitExceeded";
154 const char kErrorReasonQuotaExceeded[] = "quotaExceeded"; 154 const char kErrorReasonQuotaExceeded[] = "quotaExceeded";
155 const char kErrorReasonResponseTooLarge[] = "responseTooLarge";
155 156
156 scoped_ptr<const base::Value> value(google_apis::ParseJson(error_body)); 157 scoped_ptr<const base::Value> value(google_apis::ParseJson(error_body));
157 const base::DictionaryValue* dictionary = NULL; 158 const base::DictionaryValue* dictionary = NULL;
158 const base::DictionaryValue* error = NULL; 159 const base::DictionaryValue* error = NULL;
159 if (value && 160 if (value &&
160 value->GetAsDictionary(&dictionary) && 161 value->GetAsDictionary(&dictionary) &&
161 dictionary->GetDictionaryWithoutPathExpansion(kErrorKey, &error)) { 162 dictionary->GetDictionaryWithoutPathExpansion(kErrorKey, &error)) {
162 // Get error message. 163 // Get error message.
163 std::string message; 164 std::string message;
164 error->GetStringWithoutPathExpansion(kErrorMessageKey, &message); 165 error->GetStringWithoutPathExpansion(kErrorMessageKey, &message);
165 DLOG(ERROR) << "code: " << code << ", message: " << message; 166 DLOG(ERROR) << "code: " << code << ", message: " << message;
166 167
167 // Override the error code based on the reason of the first error. 168 // Override the error code based on the reason of the first error.
168 const base::ListValue* errors = NULL; 169 const base::ListValue* errors = NULL;
169 const base::DictionaryValue* first_error = NULL; 170 const base::DictionaryValue* first_error = NULL;
170 if (error->GetListWithoutPathExpansion(kErrorErrorsKey, &errors) && 171 if (error->GetListWithoutPathExpansion(kErrorErrorsKey, &errors) &&
171 errors->GetDictionary(0, &first_error)) { 172 errors->GetDictionary(0, &first_error)) {
172 std::string reason; 173 std::string reason;
173 first_error->GetStringWithoutPathExpansion(kErrorReasonKey, &reason); 174 first_error->GetStringWithoutPathExpansion(kErrorReasonKey, &reason);
174 if (reason == kErrorReasonRateLimitExceeded || 175 if (reason == kErrorReasonRateLimitExceeded ||
175 reason == kErrorReasonUserRateLimitExceeded) { 176 reason == kErrorReasonUserRateLimitExceeded) {
176 return google_apis::HTTP_SERVICE_UNAVAILABLE; 177 return google_apis::HTTP_SERVICE_UNAVAILABLE;
177 } 178 }
178 if (reason == kErrorReasonQuotaExceeded) 179 if (reason == kErrorReasonQuotaExceeded)
179 return google_apis::DRIVE_NO_SPACE; 180 return google_apis::DRIVE_NO_SPACE;
181 if (reason == kErrorReasonResponseTooLarge)
182 return google_apis::DRIVE_RESPONSE_TOO_LARGE;
180 } 183 }
181 } 184 }
182 185
183 return code; 186 return code;
184 } 187 }
185 188
186 } // namespace 189 } // namespace
187 190
188 namespace google_apis { 191 namespace google_apis {
189 192
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 download_action_callback_.Run(code, temp_file); 1013 download_action_callback_.Run(code, temp_file);
1011 OnProcessURLFetchResultsComplete(); 1014 OnProcessURLFetchResultsComplete();
1012 } 1015 }
1013 1016
1014 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( 1017 void DownloadFileRequestBase::RunCallbackOnPrematureFailure(
1015 DriveApiErrorCode code) { 1018 DriveApiErrorCode code) {
1016 download_action_callback_.Run(code, base::FilePath()); 1019 download_action_callback_.Run(code, base::FilePath());
1017 } 1020 }
1018 1021
1019 } // namespace google_apis 1022 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698