Commit 7bfff22f authored by bauerb's avatar bauerb Committed by Commit bot

Improve logging for PermissionRequestCreatorApiary errors.

BUG=535125

Review URL: https://codereview.chromium.org/1360153003

Cr-Commit-Position: refs/heads/master@{#351123}
parent e4631495
...@@ -199,7 +199,6 @@ void PermissionRequestCreatorApiary::OnGetTokenSuccess( ...@@ -199,7 +199,6 @@ void PermissionRequestCreatorApiary::OnGetTokenSuccess(
void PermissionRequestCreatorApiary::OnGetTokenFailure( void PermissionRequestCreatorApiary::OnGetTokenFailure(
const OAuth2TokenService::Request* request, const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
VLOG(1) << "Couldn't get token";
RequestIterator it = requests_.begin(); RequestIterator it = requests_.begin();
while (it != requests_.end()) { while (it != requests_.end()) {
if (request == (*it)->access_token_request.get()) if (request == (*it)->access_token_request.get())
...@@ -207,8 +206,8 @@ void PermissionRequestCreatorApiary::OnGetTokenFailure( ...@@ -207,8 +206,8 @@ void PermissionRequestCreatorApiary::OnGetTokenFailure(
++it; ++it;
} }
DCHECK(it != requests_.end()); DCHECK(it != requests_.end());
(*it)->callback.Run(false); LOG(WARNING) << "Token error: " << error.ToString();
requests_.erase(it); DispatchResult(it, false);
} }
void PermissionRequestCreatorApiary::OnURLFetchComplete( void PermissionRequestCreatorApiary::OnURLFetchComplete(
...@@ -223,7 +222,8 @@ void PermissionRequestCreatorApiary::OnURLFetchComplete( ...@@ -223,7 +222,8 @@ void PermissionRequestCreatorApiary::OnURLFetchComplete(
const net::URLRequestStatus& status = source->GetStatus(); const net::URLRequestStatus& status = source->GetStatus();
if (!status.is_success()) { if (!status.is_success()) {
DispatchNetworkError(it, status.error()); LOG(WARNING) << "Network error " << status.error();
DispatchResult(it, false);
return; return;
} }
...@@ -240,8 +240,7 @@ void PermissionRequestCreatorApiary::OnURLFetchComplete( ...@@ -240,8 +240,7 @@ void PermissionRequestCreatorApiary::OnURLFetchComplete(
if (response_code != net::HTTP_OK) { if (response_code != net::HTTP_OK) {
LOG(WARNING) << "HTTP error " << response_code; LOG(WARNING) << "HTTP error " << response_code;
DispatchGoogleServiceAuthError( DispatchResult(it, false);
it, GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED));
return; return;
} }
...@@ -250,33 +249,27 @@ void PermissionRequestCreatorApiary::OnURLFetchComplete( ...@@ -250,33 +249,27 @@ void PermissionRequestCreatorApiary::OnURLFetchComplete(
scoped_ptr<base::Value> value = base::JSONReader::Read(response_body); scoped_ptr<base::Value> value = base::JSONReader::Read(response_body);
base::DictionaryValue* dict = NULL; base::DictionaryValue* dict = NULL;
if (!value || !value->GetAsDictionary(&dict)) { if (!value || !value->GetAsDictionary(&dict)) {
DispatchNetworkError(it, net::ERR_INVALID_RESPONSE); LOG(WARNING) << "Invalid top-level dictionary";
DispatchResult(it, false);
return; return;
} }
base::DictionaryValue* permission_dict = NULL; base::DictionaryValue* permission_dict = NULL;
if (!dict->GetDictionary(kPermissionRequestKey, &permission_dict)) { if (!dict->GetDictionary(kPermissionRequestKey, &permission_dict)) {
DispatchNetworkError(it, net::ERR_INVALID_RESPONSE); LOG(WARNING) << "Permission request not found";
DispatchResult(it, false);
return; return;
} }
std::string id; std::string id;
if (!permission_dict->GetString(kIdKey, &id)) { if (!permission_dict->GetString(kIdKey, &id)) {
DispatchNetworkError(it, net::ERR_INVALID_RESPONSE); LOG(WARNING) << "ID not found";
DispatchResult(it, false);
return; return;
} }
(*it)->callback.Run(true); DispatchResult(it, true);
requests_.erase(it);
} }
void PermissionRequestCreatorApiary::DispatchNetworkError(RequestIterator it, void PermissionRequestCreatorApiary::DispatchResult(RequestIterator it,
int error_code) { bool success) {
DispatchGoogleServiceAuthError( (*it)->callback.Run(success);
it, GoogleServiceAuthError::FromConnectionError(error_code));
}
void PermissionRequestCreatorApiary::DispatchGoogleServiceAuthError(
RequestIterator it,
const GoogleServiceAuthError& error) {
VLOG(1) << "GoogleServiceAuthError: " << error.ToString();
(*it)->callback.Run(false);
requests_.erase(it); requests_.erase(it);
} }
...@@ -49,7 +49,7 @@ class PermissionRequestCreatorApiary : public PermissionRequestCreator, ...@@ -49,7 +49,7 @@ class PermissionRequestCreatorApiary : public PermissionRequestCreator,
private: private:
struct Request; struct Request;
typedef ScopedVector<Request>::iterator RequestIterator; using RequestIterator = ScopedVector<Request>::iterator;
// OAuth2TokenService::Consumer implementation: // OAuth2TokenService::Consumer implementation:
void OnGetTokenSuccess(const OAuth2TokenService::Request* request, void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
...@@ -72,9 +72,7 @@ class PermissionRequestCreatorApiary : public PermissionRequestCreator, ...@@ -72,9 +72,7 @@ class PermissionRequestCreatorApiary : public PermissionRequestCreator,
// we restart when the returned access token has expired. // we restart when the returned access token has expired.
void StartFetching(Request* request); void StartFetching(Request* request);
void DispatchNetworkError(RequestIterator it, int error_code); void DispatchResult(RequestIterator it, bool success);
void DispatchGoogleServiceAuthError(RequestIterator it,
const GoogleServiceAuthError& error);
OAuth2TokenService* oauth2_token_service_; OAuth2TokenService* oauth2_token_service_;
std::string account_id_; std::string account_id_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment