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

Unified Diff: components/signin/core/browser/account_service_flag_fetcher.h

Issue 284763004: Create AccountServiceFlagFetcher which downloads an account's Gaia service flags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 7 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: components/signin/core/browser/account_service_flag_fetcher.h
diff --git a/components/signin/core/browser/account_service_flag_fetcher.h b/components/signin/core/browser/account_service_flag_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..85f7947f024e34561b2254d7919041da1618bc83
--- /dev/null
+++ b/components/signin/core/browser/account_service_flag_fetcher.h
@@ -0,0 +1,78 @@
+// Copyright 2014 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 COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_
+#define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "google_apis/gaia/gaia_auth_consumer.h"
+#include "google_apis/gaia/gaia_auth_fetcher.h"
+#include "google_apis/gaia/oauth2_token_service.h"
+
+class ProfileOAuth2TokenService;
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+// Downloads an account's list of Gaia service flags.
+class AccountServiceFlagFetcher : public GaiaAuthConsumer,
+ public OAuth2TokenService::Observer,
+ public OAuth2TokenService::Consumer {
+ public:
+ enum ResultCode {
+ SUCCESS,
+ TOKEN_ERROR, // Failed to get OAuth2 token.
+ SERVICE_ERROR // Service returned an error or malformed reply.
Bernhard Bauer 2014/05/20 12:35:27 You can add a trailing comma here, to reduce edit
Marc Treib 2014/05/20 13:24:28 Done.
+ };
+ // If the flag download is successful, this will return the list of service
+ // flags that are set for the given account.
+ typedef base::Callback<void(ResultCode /* result */,
+ const std::vector<std::string>& /* flags */)>
+ Callback;
+
+ // Immediately starts fetching the flags.
+ AccountServiceFlagFetcher(const std::string& account_id,
+ ProfileOAuth2TokenService* token_service,
+ net::URLRequestContextGetter* request_context,
+ const Callback& callback);
+ // Destructing the object before the callback is called cancels the request.
+ virtual ~AccountServiceFlagFetcher();
+
+ private:
+ void Start();
+ void StartFetchingOAuth2AccessToken();
+
+ // Overridden from OAuth2TokenService::Observer:
+ virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
+
+ // Overridden from OAuth2TokenService::Consumer:
+ virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) OVERRIDE;
+ virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) OVERRIDE;
+
+ // Overridden from GaiaAuthConsumer:
+ virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
+ virtual void OnClientLoginFailure(const GoogleServiceAuthError& error)
+ OVERRIDE;
+ virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE;
+ virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error)
+ OVERRIDE;
+
+ const std::string account_id_;
+ ProfileOAuth2TokenService* token_service_;
+ GaiaAuthFetcher gaia_auth_fetcher_;
+
+ Callback callback_;
+
+ scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_;
+};
+
+#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698