Chromium Code Reviews| Index: chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| diff --git a/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..baf6f3da86a278208e09beaf411e23c85957aaa6 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| @@ -0,0 +1,91 @@ |
| +// 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. |
| + |
| +// This file has code to fetch the Obfuscated GAIA ID from the server |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/string16.h" |
| +#include "chrome/common/net/gaia/oauth2_api_call_flow.h" |
| + |
| +class GoogleServiceAuthError; |
| + |
| +namespace base { |
| +class DictionaryValue; |
|
dcheng
2012/08/20 19:10:01
This is unused.
dcheng
2012/08/20 19:10:01
Unused.
Pete Williamson
2012/08/20 20:53:05
Done.
|
| +} |
| + |
| +namespace content { |
| +class URLFetcher; |
| +} |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace extensions { |
| + |
| +// Fetches obfuscated gaia id of the Google Account that is logged in to Chrome. |
| +// This starts an asynchronous operation which reports success to the delegate. |
| +// Call "Start()" to start the async fetch. |
| +class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow { |
| + public: |
| + // Delegate interface that is called when obfuscated gaia id fetch |
| + // succeeds or fails. |
| + class Delegate { |
| + public: |
| + virtual void OnObfuscatedGaiaIdFetchSuccess( |
| + const std::string& obfuscated_id) {} |
| + virtual void OnObfuscatedGaiaIdFetchFailure( |
| + const GoogleServiceAuthError& error) {} |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + // TODO: Someday let's make a profile keyed service to cache the GAIA ID. |
|
dcheng
2012/08/20 19:10:01
Should be TODO(petewil)
Pete Williamson
2012/08/20 20:53:05
Done.
|
| + |
| + ObfuscatedGaiaIdFetcher(net::URLRequestContextGetter* context, |
| + Delegate* delegate, |
| + const std::string& refresh_token); |
| + virtual ~ObfuscatedGaiaIdFetcher(); |
| + |
| + protected: |
| + // OAuth2ApiCallFlow implementation |
| + 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_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, SetUp); |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ParseResponse); |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallSuccess); |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallFailure); |
| + |
| + void ReportSuccess(const std::string& obfuscated_id); |
| + void ReportFailure(const GoogleServiceAuthError& error); |
| + |
| + // Get the obfuscated GAIA ID out of the response body. |
| + static bool ParseResponse( |
| + const std::string& data, std::string* obfuscated_id); |
| + |
| + // Unowned, weak pointer to the delegate. Normally the delegate owns |
|
dcheng
2012/08/20 19:10:01
Don't use "weak" since we have WeakPtr<T> as well.
Munjal (Google)
2012/08/20 20:01:25
Agree with Daniel.
Pete Williamson
2012/08/20 20:53:05
Done.
|
| + // this fetcher class. |
| + Delegate* delegate_; |
| + std::string obfuscated_gaia_id_; |
|
dcheng
2012/08/20 19:10:01
It seems like this is unused.
Pete Williamson
2012/08/20 20:53:05
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |