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

Unified Diff: chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetch.h

Issue 10837013: Chrome Cloud Messaging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: InvalidationHandler + event Created 8 years, 5 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_fetch.h
diff --git a/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetch.h b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetch.h
new file mode 100644
index 0000000000000000000000000000000000000000..0872ab732e530d0c13dd386f686bd2d512bcded5
--- /dev/null
+++ b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetch.h
@@ -0,0 +1,131 @@
+// 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.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH_H_
+#define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH_H_
+
+#include <string>
+#include <vector>
+
+#include "base/memory/weak_ptr.h"
+#include "base/string16.h"
+#include "chrome/common/net/gaia/oauth2_api_call_flow.h"
+
+class GoogleServiceAuthError;
+class ObfuscatedGaiaIdFetchTest;
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace content {
+class URLFetcher;
+}
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+namespace extension {
+
+// This class implements the OAuth2 flow to Google to call the
+// chrome web store API to get an obfuscated channel ID
+//
+class ObfuscatedGaiaIdFetch : public OAuth2ApiCallFlow {
+ public:
+
+ // Parameters needed to get an Obfuscated Gaia ID
+ struct Parameters {
+ public:
+ Parameters();
+ Parameters(const std::string& rt,
+ const std::string& eid,
+ const std::vector<std::string>& scopes_arg);
+ ~Parameters();
+
+ std::string login_refresh_token;
+ std::string extension_id;
+ std::vector<std::string> scopes;
+ };
+
+ // interface for a delegate to be notified of changes when
+ // the operation succeeds or fails. Pass your delegate in to
+ // the class constructor when creating this class if you
+ // want to be notified when a result arrives.
+ class Delegate {
+ public:
+ virtual void OnObfuscatedGaiaIdFetchSuccess(
+ const std::string& access_token) {}
+ virtual void OnObfuscatedGaiaIdFetchFailure(
+ const GoogleServiceAuthError& error) {}
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ ObfuscatedGaiaIdFetch(net::URLRequestContextGetter* context,
+ Delegate* delegate,
+ const Parameters& parameters);
+ virtual ~ObfuscatedGaiaIdFetch();
+
+ // when the user logs out, clear the token so we get a fresh
+ // token for the next user
+ void ClearGaiaId()
+ { obfuscatedGaiaId_.clear(); }
+
+ // return whatever we have cached for a Gaia ID,
+ // or an empty string if we don't have anything
+ const std::string& GetCachedObfuscatedGaiaId()
+ { return obfuscatedGaiaId_; }
+
+ // begin a fetch operation. The Delegate will be called when
+ // the operation is complete (likely on a different thread)
+ void StartObfuscatedGaiaIdFetch()
+ { Start(); }
+
+ protected:
+ // Implementation of template methods in OAuth2ApiCallFlow.
+ virtual GURL CreateApiCallUrl() OVERRIDE;
+ virtual std::string CreateApiCallBody() OVERRIDE;
+
+ virtual void ProcessApiCallSuccess(
+ const net::URLFetcher* source) OVERRIDE;
+ virtual void ProcessApiCallFailure(
+ const net::URLFetcher* source) OVERRIDE;
+ virtual void ProcessNewAccessToken(
+ const std::string& access_token) OVERRIDE;
+ virtual void ProcessMintAccessTokenFailure(
+ const GoogleServiceAuthError& error) OVERRIDE;
+
+ private:
+ friend class ObfuscatedGaiaIdFetchTest;
+ FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
+ ParseGaiaTokenResponse);
+ FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
+ ProcessApiCallSuccess);
+ FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
+ ProcessApiCallFailure);
+ FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
+ ProcessObfuscatedGaiaIdFailure);
+
+ void ReportSuccess(const std::string& access_token);
+ void ReportFailure(const GoogleServiceAuthError& error);
+
+ // get the obfuscated GAIA ID out of the response body
+ static bool ParseObfuscatedGaiaIdFetchResponse(
+ const std::string& data, std::string* channel_id);
+
+ net::URLRequestContextGetter* context_;
+ Delegate* delegate_;
+ Parameters parameters_;
+ base::WeakPtrFactory<ObfuscatedGaiaIdFetch> weak_factory_;
+ std::string obfuscatedGaiaId_;
+
+ DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetch);
+};
+
+
+} // namespace extension
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH_H_

Powered by Google App Engine
This is Rietveld 408576698