Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "obfuscated_gaia_id_fetcher.h" | |
|
Munjal (Google)
2012/08/09 21:44:29
You need to specify the path relative to src here.
Pete Williamson
2012/08/13 21:21:14
Done
| |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/json/json_reader.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/common/net/gaia/google_service_auth_error.h" | |
| 13 #include "net/url_request/url_fetcher.h" | |
| 14 #include "net/url_request/url_request_status.h" | |
| 15 | |
| 16 using net::URLFetcher; | |
| 17 using net::URLRequestContextGetter; | |
| 18 using net::URLRequestStatus; | |
| 19 | |
| 20 const char kID[] = "id"; | |
|
Munjal (Google)
2012/08/09 21:44:29
Put this inside anonymous namespace.
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 21 | |
| 22 namespace { | |
|
Munjal (Google)
2012/08/09 21:44:29
Nit: add an empty line here?
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 23 // This is the URL of the service where we get the obfuscated GAIA ID | |
| 24 // (here misnamed channel ID). | |
|
Munjal (Google)
2012/08/09 21:44:29
Nit: Drop "This is the". Also, may be make it a bi
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 25 static const char kCWSChannelServiceURL[] = | |
| 26 "https://www.googleapis.com/chromewebstore/v1.1/channels/id"; | |
| 27 | |
| 28 // TODO: How should we handle an error while calling the API? We can just | |
| 29 // leave the GAIA ID as a null string, and allow the client to try again later. | |
| 30 // We should probably log an error. Is it useful to return an error to the | |
| 31 // client, or should we just leave the GAIA ID null, and let the client check | |
| 32 // it for validity when they try to use it? | |
| 33 static GoogleServiceAuthError CreateAuthError(URLRequestStatus status) { | |
| 34 if (status.status() == URLRequestStatus::CANCELED) { | |
| 35 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | |
| 36 } else { | |
| 37 // TODO(munjal): Improve error handling. Currently we return connection | |
| 38 // error for even application level errors. We need to either expand the | |
| 39 // GoogleServiceAuthError enum or create a new one to report better | |
| 40 // errors. | |
| 41 DLOG(WARNING) << "Server returned error: errno " << status.error(); | |
| 42 return GoogleServiceAuthError::FromConnectionError(status.error()); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 | |
| 49 namespace extensions { | |
| 50 | |
| 51 ObfuscatedGaiaIdFetcher::Parameters::Parameters() {} | |
| 52 | |
| 53 ObfuscatedGaiaIdFetcher::Parameters::Parameters( | |
| 54 const std::string& rt, | |
| 55 const std::string& eid) | |
| 56 : login_refresh_token(rt), | |
| 57 extension_id(eid) { | |
| 58 } | |
| 59 | |
| 60 ObfuscatedGaiaIdFetcher::Parameters::~Parameters() {} | |
| 61 | |
| 62 // TODO: Do we need to cache scopes here? | |
| 63 // It doesn't seem to get referenced anywhere - what would I need it for? | |
|
Munjal (Google)
2012/08/09 21:44:29
Remove this comment.
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 64 ObfuscatedGaiaIdFetcher::ObfuscatedGaiaIdFetcher( | |
| 65 URLRequestContextGetter* context, | |
| 66 Delegate* delegate, | |
| 67 const Parameters& parameters) | |
| 68 : OAuth2ApiCallFlow( | |
| 69 context, parameters.login_refresh_token, | |
| 70 "", std::vector<std::string>()), | |
| 71 context_(context), | |
| 72 delegate_(delegate), | |
| 73 parameters_(parameters) { | |
| 74 } | |
| 75 | |
| 76 ObfuscatedGaiaIdFetcher::~ObfuscatedGaiaIdFetcher() { } | |
| 77 | |
| 78 void ObfuscatedGaiaIdFetcher::ReportSuccess(const std::string& access_token) { | |
| 79 if (delegate_) | |
| 80 delegate_->OnObfuscatedGaiaIdFetchSuccess(access_token); | |
| 81 } | |
|
Munjal (Google)
2012/08/09 21:44:29
access_token -> obfuscated_id in this method.
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 82 | |
| 83 void ObfuscatedGaiaIdFetcher::ReportFailure( | |
| 84 const GoogleServiceAuthError& error) { | |
| 85 if (delegate_) | |
| 86 delegate_->OnObfuscatedGaiaIdFetchFailure(error); | |
| 87 } | |
| 88 | |
| 89 GURL ObfuscatedGaiaIdFetcher::CreateApiCallUrl() { | |
| 90 LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::CreateApiCallUrl called ***"; | |
|
Munjal (Google)
2012/08/09 21:44:29
Remove LOG statements here and elsewhere in the fi
Pete Williamson
2012/08/13 21:21:14
All marked for removal, I'll actually remove them
| |
| 91 return GURL(kCWSChannelServiceURL); | |
| 92 } | |
| 93 | |
| 94 // Nothing to do here, we don't need a body for this request, the URL | |
| 95 // encodes all the proper arguments. | |
|
Munjal (Google)
2012/08/09 21:44:29
Take this comment inside the method. Also remove e
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 96 std::string ObfuscatedGaiaIdFetcher::CreateApiCallBody() { | |
| 97 LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::CreateApiCallBody called ***"; | |
| 98 return std::string(); | |
| 99 } | |
| 100 | |
| 101 // On the first call, we want to process the token issue-ing response. | |
| 102 // On subsequent calls, we want to process the ChannelID. | |
|
Munjal (Google)
2012/08/09 21:44:29
I don't understand this comment. Remove it?
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 103 void ObfuscatedGaiaIdFetcher::ProcessApiCallSuccess( | |
| 104 const net::URLFetcher* source) { | |
| 105 // TODO(munjal): Change error code paths in this method to report an | |
| 106 // internal error. | |
| 107 LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::ProcessApiCallSuccess called ***"; | |
| 108 std::string response_body; | |
| 109 source->GetResponseAsString(&response_body); | |
| 110 | |
| 111 std::string channel_id; | |
| 112 if (ParseResponse(response_body, &channel_id)) | |
| 113 ReportSuccess(channel_id); | |
| 114 else | |
| 115 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); | |
| 116 } | |
| 117 | |
| 118 void ObfuscatedGaiaIdFetcher::ProcessApiCallFailure( | |
| 119 const net::URLFetcher* source) { | |
| 120 LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::ProcessApiCallFailure called ***"; | |
| 121 ReportFailure(CreateAuthError(source->GetStatus())); | |
| 122 } | |
| 123 | |
| 124 void ObfuscatedGaiaIdFetcher::ProcessNewAccessToken( | |
| 125 const std::string& access_token) { | |
| 126 // TODO: what do I need to do here, if anything? | |
|
Munjal (Google)
2012/08/09 21:44:29
Do nothing here right now. Just add a comment that
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 127 LOG(INFO) << "*** ObfuscatedGaiaIDFetcher::ProcessNewAccessToken - " | |
| 128 << "got new access token ***"; | |
| 129 } | |
| 130 | |
| 131 void ObfuscatedGaiaIdFetcher::ProcessMintAccessTokenFailure( | |
| 132 const GoogleServiceAuthError& error) { | |
| 133 // TODO: what do I need to do here, if anything? | |
|
Munjal (Google)
2012/08/09 21:44:29
ReportFailure here. This means we failed to genera
Pete Williamson
2012/08/13 21:21:14
Done.
| |
| 134 LOG(INFO) << "*** ObfuscatedGaiaIDFetcher::ProcessMintAccessTokenFailure - " | |
| 135 << "error ***"; | |
| 136 } | |
| 137 | |
| 138 // static | |
| 139 bool ObfuscatedGaiaIdFetcher::ParseResponse( | |
| 140 const std::string& data, std::string* result) { | |
| 141 LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::ParseResponse called ***"; | |
| 142 | |
| 143 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | |
| 144 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | |
| 145 return false; | |
| 146 | |
| 147 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | |
| 148 return dict->GetString(kID, result); | |
| 149 } | |
| 150 | |
| 151 } // namespace extensions | |
| OLD | NEW |