signin_oauth_helper.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
1// Copyright 2014 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#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_
6#define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_
7
8#include <string>
9
10#include "base/memory/scoped_ptr.h"
11#include "google_apis/gaia/gaia_auth_consumer.h"
12#include "google_apis/gaia/gaia_auth_fetcher.h"
13
14// Retrieves the OAuth2 information from an already signed in cookie jar.
15// The information retrieved is: username, refresh token.
16class SigninOAuthHelper : public GaiaAuthConsumer {
17 public:
18  // Implemented by users of SigninOAuthHelper to know then helper is finished.
19  class Consumer {
20   public:
21    virtual ~Consumer() {}
22
23    // Called when all the information is retrieved successfully.  |email|
24    // and |display_email| correspond to the gaia properties called "email"
25    // and "displayEmail" associated with the signed in account. |refresh_token|
26    // is the account's login-scoped oauth2 refresh token.
27    virtual void OnSigninOAuthInformationAvailable(
28        const std::string& email,
29        const std::string& display_email,
30        const std::string& refresh_token) {}
31
32    // Called when an error occurs while getting the information.
33    virtual void OnSigninOAuthInformationFailure(
34        const GoogleServiceAuthError& error) {}
35  };
36
37  explicit SigninOAuthHelper(net::URLRequestContextGetter* getter,
38                             const std::string& session_index,
39                             Consumer* consumer);
40  virtual ~SigninOAuthHelper();
41
42 private:
43  // Overridden from GaiaAuthConsumer.
44  virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE;
45  virtual void OnClientOAuthFailure(const GoogleServiceAuthError& error)
46      OVERRIDE;
47  virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
48  virtual void OnClientLoginFailure(const GoogleServiceAuthError& error)
49      OVERRIDE;
50  virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE;
51  virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error)
52      OVERRIDE;
53
54  GaiaAuthFetcher gaia_auth_fetcher_;
55  std::string refresh_token_;
56  Consumer* consumer_;
57
58  DISALLOW_COPY_AND_ASSIGN(SigninOAuthHelper);
59};
60
61#endif  // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_
62