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

Side by Side Diff: chrome/browser/google_apis/operations_base.cc

Issue 10939011: Reland "Revert 156830 - drive: Stop exposing operation_registry() from DriveServiceInterface" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 "chrome/browser/google_apis/operations_base.h" 5 #include "chrome/browser/google_apis/operations_base.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // used to start fetching user data. 102 // used to start fetching user data.
103 void AuthOperation::OnGetTokenSuccess(const std::string& access_token, 103 void AuthOperation::OnGetTokenSuccess(const std::string& access_token,
104 const base::Time& expiration_time) { 104 const base::Time& expiration_time) {
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
106 106
107 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", 107 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
108 kSuccessRatioHistogramSuccess, 108 kSuccessRatioHistogramSuccess,
109 kSuccessRatioHistogramMaxValue); 109 kSuccessRatioHistogramMaxValue);
110 110
111 callback_.Run(HTTP_SUCCESS, access_token); 111 callback_.Run(HTTP_SUCCESS, access_token);
112 NotifyFinish(OperationRegistry::OPERATION_COMPLETED); 112 NotifyFinish(OPERATION_COMPLETED);
113 } 113 }
114 114
115 // Callback for OAuth2AccessTokenFetcher on failure. 115 // Callback for OAuth2AccessTokenFetcher on failure.
116 void AuthOperation::OnGetTokenFailure(const GoogleServiceAuthError& error) { 116 void AuthOperation::OnGetTokenFailure(const GoogleServiceAuthError& error) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
118 118
119 LOG(WARNING) << "AuthOperation: token request using refresh token failed" 119 LOG(WARNING) << "AuthOperation: token request using refresh token failed"
120 << error.ToString(); 120 << error.ToString();
121 121
122 // There are many ways to fail, but if the failure is due to connection, 122 // There are many ways to fail, but if the failure is due to connection,
123 // it's likely that the device is off-line. We treat the error differently 123 // it's likely that the device is off-line. We treat the error differently
124 // so that the file manager works while off-line. 124 // so that the file manager works while off-line.
125 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { 125 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
126 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", 126 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
127 kSuccessRatioHistogramNoConnection, 127 kSuccessRatioHistogramNoConnection,
128 kSuccessRatioHistogramMaxValue); 128 kSuccessRatioHistogramMaxValue);
129 callback_.Run(GDATA_NO_CONNECTION, std::string()); 129 callback_.Run(GDATA_NO_CONNECTION, std::string());
130 } else { 130 } else {
131 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", 131 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
132 kSuccessRatioHistogramFailure, 132 kSuccessRatioHistogramFailure,
133 kSuccessRatioHistogramMaxValue); 133 kSuccessRatioHistogramMaxValue);
134 callback_.Run(HTTP_UNAUTHORIZED, std::string()); 134 callback_.Run(HTTP_UNAUTHORIZED, std::string());
135 } 135 }
136 NotifyFinish(OperationRegistry::OPERATION_FAILED); 136 NotifyFinish(OPERATION_FAILED);
137 } 137 }
138 138
139 //============================ UrlFetchOperationBase =========================== 139 //============================ UrlFetchOperationBase ===========================
140 140
141 UrlFetchOperationBase::UrlFetchOperationBase(OperationRegistry* registry) 141 UrlFetchOperationBase::UrlFetchOperationBase(OperationRegistry* registry)
142 : OperationRegistry::Operation(registry), 142 : OperationRegistry::Operation(registry),
143 re_authenticate_count_(0), 143 re_authenticate_count_(0),
144 save_temp_file_(false), 144 save_temp_file_(false),
145 started_(false) { 145 started_(false) {
146 } 146 }
147 147
148 UrlFetchOperationBase::UrlFetchOperationBase( 148 UrlFetchOperationBase::UrlFetchOperationBase(OperationRegistry* registry,
149 OperationRegistry* registry, 149 OperationType type,
150 OperationRegistry::OperationType type, 150 const FilePath& path)
151 const FilePath& path)
152 : OperationRegistry::Operation(registry, type, path), 151 : OperationRegistry::Operation(registry, type, path),
153 re_authenticate_count_(0), 152 re_authenticate_count_(0),
154 save_temp_file_(false) { 153 save_temp_file_(false) {
155 } 154 }
156 155
157 UrlFetchOperationBase::~UrlFetchOperationBase() {} 156 UrlFetchOperationBase::~UrlFetchOperationBase() {}
158 157
159 void UrlFetchOperationBase::Start(const std::string& auth_token) { 158 void UrlFetchOperationBase::Start(const std::string& auth_token) {
160 DCHECK(!auth_token.empty()); 159 DCHECK(!auth_token.empty());
161 160
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // likely that the failure is due to loss of connection. 237 // likely that the failure is due to loss of connection.
239 code = GDATA_NO_CONNECTION; 238 code = GDATA_NO_CONNECTION;
240 } 239 }
241 return code; 240 return code;
242 } 241 }
243 242
244 void UrlFetchOperationBase::OnProcessURLFetchResultsComplete(bool result) { 243 void UrlFetchOperationBase::OnProcessURLFetchResultsComplete(bool result) {
245 if (result) 244 if (result)
246 NotifySuccessToOperationRegistry(); 245 NotifySuccessToOperationRegistry();
247 else 246 else
248 NotifyFinish(OperationRegistry::OPERATION_FAILED); 247 NotifyFinish(OPERATION_FAILED);
249 } 248 }
250 249
251 void UrlFetchOperationBase::OnURLFetchComplete(const URLFetcher* source) { 250 void UrlFetchOperationBase::OnURLFetchComplete(const URLFetcher* source) {
252 GDataErrorCode code = GetErrorCode(source); 251 GDataErrorCode code = GetErrorCode(source);
253 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source); 252 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source);
254 253
255 if (code == HTTP_UNAUTHORIZED) { 254 if (code == HTTP_UNAUTHORIZED) {
256 if (!re_authenticate_callback_.is_null() && 255 if (!re_authenticate_callback_.is_null() &&
257 ++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerOperation) { 256 ++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerOperation) {
258 re_authenticate_callback_.Run(this); 257 re_authenticate_callback_.Run(this);
259 return; 258 return;
260 } 259 }
261 260
262 OnAuthFailed(code); 261 OnAuthFailed(code);
263 return; 262 return;
264 } 263 }
265 264
266 // Overridden by each specialization 265 // Overridden by each specialization
267 ProcessURLFetchResults(source); 266 ProcessURLFetchResults(source);
268 } 267 }
269 268
270 void UrlFetchOperationBase::NotifySuccessToOperationRegistry() { 269 void UrlFetchOperationBase::NotifySuccessToOperationRegistry() {
271 NotifyFinish(OperationRegistry::OPERATION_COMPLETED); 270 NotifyFinish(OPERATION_COMPLETED);
272 } 271 }
273 272
274 void UrlFetchOperationBase::NotifyStartToOperationRegistry() { 273 void UrlFetchOperationBase::NotifyStartToOperationRegistry() {
275 NotifyStart(); 274 NotifyStart();
276 } 275 }
277 276
278 void UrlFetchOperationBase::OnAuthFailed(GDataErrorCode code) { 277 void UrlFetchOperationBase::OnAuthFailed(GDataErrorCode code) {
279 RunCallbackOnPrematureFailure(code); 278 RunCallbackOnPrematureFailure(code);
280 279
281 // Notify authentication failed. 280 // Notify authentication failed.
282 NotifyAuthFailed(); 281 NotifyAuthFailed();
283 282
284 // Check if this failed before we even started fetching. If so, register 283 // Check if this failed before we even started fetching. If so, register
285 // for start so we can properly unregister with finish. 284 // for start so we can properly unregister with finish.
286 if (!started_) 285 if (!started_)
287 NotifyStart(); 286 NotifyStart();
288 287
289 // Note: NotifyFinish() must be invoked at the end, after all other callbacks 288 // Note: NotifyFinish() must be invoked at the end, after all other callbacks
290 // and notifications. Once NotifyFinish() is called, the current instance of 289 // and notifications. Once NotifyFinish() is called, the current instance of
291 // gdata operation will be deleted from the OperationRegistry and become 290 // gdata operation will be deleted from the OperationRegistry and become
292 // invalid. 291 // invalid.
293 NotifyFinish(OperationRegistry::OPERATION_FAILED); 292 NotifyFinish(OPERATION_FAILED);
294 } 293 }
295 294
296 std::string UrlFetchOperationBase::GetResponseHeadersAsString( 295 std::string UrlFetchOperationBase::GetResponseHeadersAsString(
297 const URLFetcher* url_fetcher) { 296 const URLFetcher* url_fetcher) {
298 // net::HttpResponseHeaders::raw_headers(), as the name implies, stores 297 // net::HttpResponseHeaders::raw_headers(), as the name implies, stores
299 // all headers in their raw format, i.e each header is null-terminated. 298 // all headers in their raw format, i.e each header is null-terminated.
300 // So logging raw_headers() only shows the first header, which is probably 299 // So logging raw_headers() only shows the first header, which is probably
301 // the status line. GetNormalizedHeaders, on the other hand, will show all 300 // the status line. GetNormalizedHeaders, on the other hand, will show all
302 // the headers, one per line, which is probably what we want. 301 // the headers, one per line, which is probably what we want.
303 std::string headers; 302 std::string headers;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 416 }
418 417
419 void GetDataOperation::RunCallback(GDataErrorCode fetch_error_code, 418 void GetDataOperation::RunCallback(GDataErrorCode fetch_error_code,
420 scoped_ptr<base::Value> value) { 419 scoped_ptr<base::Value> value) {
421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
422 if (!callback_.is_null()) 421 if (!callback_.is_null())
423 callback_.Run(fetch_error_code, value.Pass()); 422 callback_.Run(fetch_error_code, value.Pass());
424 } 423 }
425 424
426 } // namespace gdata 425 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/operations_base.h ('k') | chrome/browser/ui/webui/chromeos/drive_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698