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

Side by Side Diff: chrome/browser/chromeos/gdata/operations_base.cc

Issue 10877006: Rename GDataErrorCode to DriveErrorCode, GDataFileError to DriveFileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 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/chromeos/gdata/operations_base.h" 5 #include "chrome/browser/chromeos/gdata/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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 oauth2_access_token_fetcher_->Start( 112 oauth2_access_token_fetcher_->Start(
113 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), 113 GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
114 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), 114 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
115 refresh_token_, 115 refresh_token_,
116 scopes); 116 scopes);
117 } 117 }
118 118
119 void AuthOperation::DoCancel() { 119 void AuthOperation::DoCancel() {
120 oauth2_access_token_fetcher_->CancelRequest(); 120 oauth2_access_token_fetcher_->CancelRequest();
121 if (!callback_.is_null()) 121 if (!callback_.is_null())
122 callback_.Run(GDATA_CANCELLED, std::string()); 122 callback_.Run(DRIVE_CANCELLED, std::string());
123 } 123 }
124 124
125 // Callback for OAuth2AccessTokenFetcher on success. |access_token| is the token 125 // Callback for OAuth2AccessTokenFetcher on success. |access_token| is the token
126 // used to start fetching user data. 126 // used to start fetching user data.
127 void AuthOperation::OnGetTokenSuccess(const std::string& access_token, 127 void AuthOperation::OnGetTokenSuccess(const std::string& access_token,
128 const base::Time& expiration_time) { 128 const base::Time& expiration_time) {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
130 130
131 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", 131 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
132 kSuccessRatioHistogramSuccess, 132 kSuccessRatioHistogramSuccess,
(...skipping 10 matching lines...) Expand all
143 LOG(WARNING) << "AuthOperation: token request using refresh token failed" 143 LOG(WARNING) << "AuthOperation: token request using refresh token failed"
144 << error.ToString(); 144 << error.ToString();
145 145
146 // There are many ways to fail, but if the failure is due to connection, 146 // There are many ways to fail, but if the failure is due to connection,
147 // it's likely that the device is off-line. We treat the error differently 147 // it's likely that the device is off-line. We treat the error differently
148 // so that the file manager works while off-line. 148 // so that the file manager works while off-line.
149 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { 149 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
150 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", 150 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
151 kSuccessRatioHistogramNoConnection, 151 kSuccessRatioHistogramNoConnection,
152 kSuccessRatioHistogramMaxValue); 152 kSuccessRatioHistogramMaxValue);
153 callback_.Run(GDATA_NO_CONNECTION, std::string()); 153 callback_.Run(DRIVE_NO_CONNECTION, std::string());
154 } else { 154 } else {
155 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", 155 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
156 kSuccessRatioHistogramFailure, 156 kSuccessRatioHistogramFailure,
157 kSuccessRatioHistogramMaxValue); 157 kSuccessRatioHistogramMaxValue);
158 callback_.Run(HTTP_UNAUTHORIZED, std::string()); 158 callback_.Run(HTTP_UNAUTHORIZED, std::string());
159 } 159 }
160 NotifyFinish(OperationRegistry::OPERATION_FAILED); 160 NotifyFinish(OperationRegistry::OPERATION_FAILED);
161 } 161 }
162 162
163 //============================ UrlFetchOperationBase =========================== 163 //============================ UrlFetchOperationBase ===========================
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return std::vector<std::string>(); 244 return std::vector<std::string>();
245 } 245 }
246 246
247 bool UrlFetchOperationBase::GetContentData(std::string* upload_content_type, 247 bool UrlFetchOperationBase::GetContentData(std::string* upload_content_type,
248 std::string* upload_content) { 248 std::string* upload_content) {
249 return false; 249 return false;
250 } 250 }
251 251
252 void UrlFetchOperationBase::DoCancel() { 252 void UrlFetchOperationBase::DoCancel() {
253 url_fetcher_.reset(NULL); 253 url_fetcher_.reset(NULL);
254 RunCallbackOnPrematureFailure(GDATA_CANCELLED); 254 RunCallbackOnPrematureFailure(DRIVE_CANCELLED);
255 } 255 }
256 256
257 GDataErrorCode UrlFetchOperationBase::GetErrorCode( 257 DriveErrorCode UrlFetchOperationBase::GetErrorCode(
258 const URLFetcher* source) const { 258 const URLFetcher* source) const {
259 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode()); 259 DriveErrorCode code = static_cast<DriveErrorCode>(source->GetResponseCode());
260 if (code == HTTP_SUCCESS && !source->GetStatus().is_success()) { 260 if (code == HTTP_SUCCESS && !source->GetStatus().is_success()) {
261 // If the HTTP response code is SUCCESS yet the URL request failed, it is 261 // If the HTTP response code is SUCCESS yet the URL request failed, it is
262 // likely that the failure is due to loss of connection. 262 // likely that the failure is due to loss of connection.
263 code = GDATA_NO_CONNECTION; 263 code = DRIVE_NO_CONNECTION;
264 } 264 }
265 return code; 265 return code;
266 } 266 }
267 267
268 void UrlFetchOperationBase::OnProcessURLFetchResultsComplete(bool result) { 268 void UrlFetchOperationBase::OnProcessURLFetchResultsComplete(bool result) {
269 if (result) 269 if (result)
270 NotifySuccessToOperationRegistry(); 270 NotifySuccessToOperationRegistry();
271 else 271 else
272 NotifyFinish(OperationRegistry::OPERATION_FAILED); 272 NotifyFinish(OperationRegistry::OPERATION_FAILED);
273 } 273 }
274 274
275 void UrlFetchOperationBase::OnURLFetchComplete(const URLFetcher* source) { 275 void UrlFetchOperationBase::OnURLFetchComplete(const URLFetcher* source) {
276 GDataErrorCode code = GetErrorCode(source); 276 DriveErrorCode code = GetErrorCode(source);
277 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source); 277 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source);
278 278
279 if (code == HTTP_UNAUTHORIZED) { 279 if (code == HTTP_UNAUTHORIZED) {
280 if (!re_authenticate_callback_.is_null() && 280 if (!re_authenticate_callback_.is_null() &&
281 ++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerOperation) { 281 ++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerOperation) {
282 re_authenticate_callback_.Run(this); 282 re_authenticate_callback_.Run(this);
283 return; 283 return;
284 } 284 }
285 285
286 OnAuthFailed(code); 286 OnAuthFailed(code);
287 return; 287 return;
288 } 288 }
289 289
290 // Overridden by each specialization 290 // Overridden by each specialization
291 ProcessURLFetchResults(source); 291 ProcessURLFetchResults(source);
292 } 292 }
293 293
294 void UrlFetchOperationBase::NotifySuccessToOperationRegistry() { 294 void UrlFetchOperationBase::NotifySuccessToOperationRegistry() {
295 NotifyFinish(OperationRegistry::OPERATION_COMPLETED); 295 NotifyFinish(OperationRegistry::OPERATION_COMPLETED);
296 } 296 }
297 297
298 void UrlFetchOperationBase::NotifyStartToOperationRegistry() { 298 void UrlFetchOperationBase::NotifyStartToOperationRegistry() {
299 NotifyStart(); 299 NotifyStart();
300 } 300 }
301 301
302 void UrlFetchOperationBase::OnAuthFailed(GDataErrorCode code) { 302 void UrlFetchOperationBase::OnAuthFailed(DriveErrorCode code) {
303 RunCallbackOnPrematureFailure(code); 303 RunCallbackOnPrematureFailure(code);
304 304
305 // Notify authentication failed. 305 // Notify authentication failed.
306 NotifyAuthFailed(); 306 NotifyAuthFailed();
307 307
308 // Check if this failed before we even started fetching. If so, register 308 // Check if this failed before we even started fetching. If so, register
309 // for start so we can properly unregister with finish. 309 // for start so we can properly unregister with finish.
310 if (!started_) 310 if (!started_)
311 NotifyStart(); 311 NotifyStart();
312 312
(...skipping 29 matching lines...) Expand all
342 const GURL& document_url) 342 const GURL& document_url)
343 : UrlFetchOperationBase(registry), 343 : UrlFetchOperationBase(registry),
344 callback_(callback), 344 callback_(callback),
345 document_url_(document_url) { 345 document_url_(document_url) {
346 } 346 }
347 347
348 EntryActionOperation::~EntryActionOperation() {} 348 EntryActionOperation::~EntryActionOperation() {}
349 349
350 void EntryActionOperation::ProcessURLFetchResults(const URLFetcher* source) { 350 void EntryActionOperation::ProcessURLFetchResults(const URLFetcher* source) {
351 if (!callback_.is_null()) { 351 if (!callback_.is_null()) {
352 GDataErrorCode code = GetErrorCode(source); 352 DriveErrorCode code = GetErrorCode(source);
353 callback_.Run(code, document_url_); 353 callback_.Run(code, document_url_);
354 } 354 }
355 const bool success = true; 355 const bool success = true;
356 OnProcessURLFetchResultsComplete(success); 356 OnProcessURLFetchResultsComplete(success);
357 } 357 }
358 358
359 void EntryActionOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { 359 void EntryActionOperation::RunCallbackOnPrematureFailure(DriveErrorCode code) {
360 if (!callback_.is_null()) 360 if (!callback_.is_null())
361 callback_.Run(code, document_url_); 361 callback_.Run(code, document_url_);
362 } 362 }
363 363
364 //============================== GetDataOperation ============================== 364 //============================== GetDataOperation ==============================
365 365
366 GetDataOperation::GetDataOperation(OperationRegistry* registry, 366 GetDataOperation::GetDataOperation(OperationRegistry* registry,
367 const GetDataCallback& callback) 367 const GetDataCallback& callback)
368 : UrlFetchOperationBase(registry), 368 : UrlFetchOperationBase(registry),
369 callback_(callback), 369 callback_(callback),
370 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 370 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
371 } 371 }
372 372
373 GetDataOperation::~GetDataOperation() {} 373 GetDataOperation::~GetDataOperation() {}
374 374
375 void GetDataOperation::ProcessURLFetchResults(const URLFetcher* source) { 375 void GetDataOperation::ProcessURLFetchResults(const URLFetcher* source) {
376 std::string data; 376 std::string data;
377 source->GetResponseAsString(&data); 377 source->GetResponseAsString(&data);
378 scoped_ptr<base::Value> root_value; 378 scoped_ptr<base::Value> root_value;
379 GDataErrorCode fetch_error_code = GetErrorCode(source); 379 DriveErrorCode fetch_error_code = GetErrorCode(source);
380 380
381 switch (fetch_error_code) { 381 switch (fetch_error_code) {
382 case HTTP_SUCCESS: 382 case HTTP_SUCCESS:
383 case HTTP_CREATED: 383 case HTTP_CREATED:
384 ParseResponse(fetch_error_code, data); 384 ParseResponse(fetch_error_code, data);
385 break; 385 break;
386 default: 386 default:
387 RunCallback(fetch_error_code, scoped_ptr<base::Value>()); 387 RunCallback(fetch_error_code, scoped_ptr<base::Value>());
388 const bool success = false; 388 const bool success = false;
389 OnProcessURLFetchResultsComplete(success); 389 OnProcessURLFetchResultsComplete(success);
390 break; 390 break;
391 } 391 }
392 } 392 }
393 393
394 void GetDataOperation::RunCallbackOnPrematureFailure( 394 void GetDataOperation::RunCallbackOnPrematureFailure(
395 GDataErrorCode fetch_error_code) { 395 DriveErrorCode fetch_error_code) {
396 if (!callback_.is_null()) { 396 if (!callback_.is_null()) {
397 scoped_ptr<base::Value> root_value; 397 scoped_ptr<base::Value> root_value;
398 callback_.Run(fetch_error_code, root_value.Pass()); 398 callback_.Run(fetch_error_code, root_value.Pass());
399 } 399 }
400 } 400 }
401 401
402 void GetDataOperation::ParseResponse(GDataErrorCode fetch_error_code, 402 void GetDataOperation::ParseResponse(DriveErrorCode fetch_error_code,
403 const std::string& data) { 403 const std::string& data) {
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
405 405
406 // Uses this hack to avoid deep-copy of json object because json might be so 406 // Uses this hack to avoid deep-copy of json object because json might be so
407 // big. This pointer of scped_ptr is to ensure a deletion of the parsed json 407 // big. This pointer of scped_ptr is to ensure a deletion of the parsed json
408 // value object. 408 // value object.
409 scoped_ptr<base::Value>* parsed_value = new scoped_ptr<base::Value>(); 409 scoped_ptr<base::Value>* parsed_value = new scoped_ptr<base::Value>();
410 410
411 BrowserThread::PostBlockingPoolTaskAndReply( 411 BrowserThread::PostBlockingPoolTaskAndReply(
412 FROM_HERE, 412 FROM_HERE,
413 base::Bind(&ParseJsonOnBlockingPool, 413 base::Bind(&ParseJsonOnBlockingPool,
414 data, 414 data,
415 parsed_value), 415 parsed_value),
416 base::Bind(&GetDataOperation::OnDataParsed, 416 base::Bind(&GetDataOperation::OnDataParsed,
417 weak_ptr_factory_.GetWeakPtr(), 417 weak_ptr_factory_.GetWeakPtr(),
418 fetch_error_code, 418 fetch_error_code,
419 base::Owned(parsed_value))); 419 base::Owned(parsed_value)));
420 } 420 }
421 421
422 void GetDataOperation::OnDataParsed( 422 void GetDataOperation::OnDataParsed(
423 gdata::GDataErrorCode fetch_error_code, 423 gdata::DriveErrorCode fetch_error_code,
424 scoped_ptr<base::Value>* value) { 424 scoped_ptr<base::Value>* value) {
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
426 426
427 bool success = true; 427 bool success = true;
428 if (!value->get()) { 428 if (!value->get()) {
429 fetch_error_code = gdata::GDATA_PARSE_ERROR; 429 fetch_error_code = gdata::DRIVE_PARSE_ERROR;
430 success = false; 430 success = false;
431 } 431 }
432 432
433 // The ownership of the parsed json object is transfered to RunCallBack(), 433 // The ownership of the parsed json object is transfered to RunCallBack(),
434 // keeping the ownership of the |value| here. 434 // keeping the ownership of the |value| here.
435 RunCallback(fetch_error_code, value->Pass()); 435 RunCallback(fetch_error_code, value->Pass());
436 436
437 DCHECK(!value->get()); 437 DCHECK(!value->get());
438 438
439 OnProcessURLFetchResultsComplete(success); 439 OnProcessURLFetchResultsComplete(success);
440 // |value| will be deleted after return because it is base::Owned()'d. 440 // |value| will be deleted after return because it is base::Owned()'d.
441 } 441 }
442 442
443 void GetDataOperation::RunCallback(GDataErrorCode fetch_error_code, 443 void GetDataOperation::RunCallback(DriveErrorCode fetch_error_code,
444 scoped_ptr<base::Value> value) { 444 scoped_ptr<base::Value> value) {
445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
446 if (!callback_.is_null()) 446 if (!callback_.is_null())
447 callback_.Run(fetch_error_code, value.Pass()); 447 callback_.Run(fetch_error_code, value.Pass());
448 } 448 }
449 449
450 } // namespace gdata 450 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698