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

Unified Diff: chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.cc

Issue 10836182: Obfuscated Gaia ID fetcher (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.cc
diff --git a/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.cc b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0409480e060092ba8e6e8ee942d147cc1c4a8807
--- /dev/null
+++ b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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
+
+#include <string>
+#include <vector>
+
+#include "base/json/json_reader.h"
+#include "base/values.h"
+#include "chrome/common/net/gaia/google_service_auth_error.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_request_status.h"
+
+using net::URLFetcher;
+using net::URLRequestContextGetter;
+using net::URLRequestStatus;
+
+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.
+
+namespace {
Munjal (Google) 2012/08/09 21:44:29 Nit: add an empty line here?
Pete Williamson 2012/08/13 21:21:14 Done.
+// This is the URL of the service where we get the obfuscated GAIA ID
+// (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.
+static const char kCWSChannelServiceURL[] =
+ "https://www.googleapis.com/chromewebstore/v1.1/channels/id";
+
+// TODO: How should we handle an error while calling the API? We can just
+// leave the GAIA ID as a null string, and allow the client to try again later.
+// We should probably log an error. Is it useful to return an error to the
+// client, or should we just leave the GAIA ID null, and let the client check
+// it for validity when they try to use it?
+static GoogleServiceAuthError CreateAuthError(URLRequestStatus status) {
+ if (status.status() == URLRequestStatus::CANCELED) {
+ return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED);
+ } else {
+ // TODO(munjal): Improve error handling. Currently we return connection
+ // error for even application level errors. We need to either expand the
+ // GoogleServiceAuthError enum or create a new one to report better
+ // errors.
+ DLOG(WARNING) << "Server returned error: errno " << status.error();
+ return GoogleServiceAuthError::FromConnectionError(status.error());
+ }
+}
+
+} // namespace
+
+
+namespace extensions {
+
+ObfuscatedGaiaIdFetcher::Parameters::Parameters() {}
+
+ObfuscatedGaiaIdFetcher::Parameters::Parameters(
+ const std::string& rt,
+ const std::string& eid)
+ : login_refresh_token(rt),
+ extension_id(eid) {
+}
+
+ObfuscatedGaiaIdFetcher::Parameters::~Parameters() {}
+
+// TODO: Do we need to cache scopes here?
+// 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.
+ObfuscatedGaiaIdFetcher::ObfuscatedGaiaIdFetcher(
+ URLRequestContextGetter* context,
+ Delegate* delegate,
+ const Parameters& parameters)
+ : OAuth2ApiCallFlow(
+ context, parameters.login_refresh_token,
+ "", std::vector<std::string>()),
+ context_(context),
+ delegate_(delegate),
+ parameters_(parameters) {
+}
+
+ObfuscatedGaiaIdFetcher::~ObfuscatedGaiaIdFetcher() { }
+
+void ObfuscatedGaiaIdFetcher::ReportSuccess(const std::string& access_token) {
+ if (delegate_)
+ delegate_->OnObfuscatedGaiaIdFetchSuccess(access_token);
+}
Munjal (Google) 2012/08/09 21:44:29 access_token -> obfuscated_id in this method.
Pete Williamson 2012/08/13 21:21:14 Done.
+
+void ObfuscatedGaiaIdFetcher::ReportFailure(
+ const GoogleServiceAuthError& error) {
+ if (delegate_)
+ delegate_->OnObfuscatedGaiaIdFetchFailure(error);
+}
+
+GURL ObfuscatedGaiaIdFetcher::CreateApiCallUrl() {
+ 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
+ return GURL(kCWSChannelServiceURL);
+}
+
+// Nothing to do here, we don't need a body for this request, the URL
+// 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.
+std::string ObfuscatedGaiaIdFetcher::CreateApiCallBody() {
+ LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::CreateApiCallBody called ***";
+ return std::string();
+}
+
+// On the first call, we want to process the token issue-ing response.
+// 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.
+void ObfuscatedGaiaIdFetcher::ProcessApiCallSuccess(
+ const net::URLFetcher* source) {
+ // TODO(munjal): Change error code paths in this method to report an
+ // internal error.
+ LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::ProcessApiCallSuccess called ***";
+ std::string response_body;
+ source->GetResponseAsString(&response_body);
+
+ std::string channel_id;
+ if (ParseResponse(response_body, &channel_id))
+ ReportSuccess(channel_id);
+ else
+ ReportFailure(GoogleServiceAuthError::FromConnectionError(101));
+}
+
+void ObfuscatedGaiaIdFetcher::ProcessApiCallFailure(
+ const net::URLFetcher* source) {
+ LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::ProcessApiCallFailure called ***";
+ ReportFailure(CreateAuthError(source->GetStatus()));
+}
+
+void ObfuscatedGaiaIdFetcher::ProcessNewAccessToken(
+ const std::string& access_token) {
+ // 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.
+ LOG(INFO) << "*** ObfuscatedGaiaIDFetcher::ProcessNewAccessToken - "
+ << "got new access token ***";
+}
+
+void ObfuscatedGaiaIdFetcher::ProcessMintAccessTokenFailure(
+ const GoogleServiceAuthError& error) {
+ // 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.
+ LOG(INFO) << "*** ObfuscatedGaiaIDFetcher::ProcessMintAccessTokenFailure - "
+ << "error ***";
+}
+
+// static
+bool ObfuscatedGaiaIdFetcher::ParseResponse(
+ const std::string& data, std::string* result) {
+ LOG(INFO) << "*** ObfuscatedGaiaIdFetcher::ParseResponse called ***";
+
+ scoped_ptr<base::Value> value(base::JSONReader::Read(data));
+ if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY)
+ return false;
+
+ DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
+ return dict->GetString(kID, result);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698