Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / extensions / shell / browser / shell_oauth2_token_service.h
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 EXTENSIONS_SHELL_BROWSER_SHELL_OAUTH2_TOKEN_SERVICE_H_
6 #define EXTENSIONS_SHELL_BROWSER_SHELL_OAUTH2_TOKEN_SERVICE_H_
7
8 #include <string>
9
10 #include "base/macros.h"
11 #include "google_apis/gaia/oauth2_token_service.h"
12
13 namespace content {
14 class BrowserContext;
15 }
16
17 namespace extensions {
18
19 // Requests OAuth2 access tokens for app_shell. Requires the OAuth2 refresh
20 // token to be set explicitly. Only stores a single refresh token for a single
21 // user account. Created and accessed on the UI thread. Only one instance is
22 // allowed.
23 class ShellOAuth2TokenService : public OAuth2TokenService {
24  public:
25   ShellOAuth2TokenService(content::BrowserContext* browser_context,
26                           std::string account_id,
27                           std::string refresh_token);
28   ~ShellOAuth2TokenService() override;
29
30   // Returns the single instance for app_shell.
31   static ShellOAuth2TokenService* GetInstance();
32
33   std::string account_id() const { return account_id_; }
34
35   // Sets the current user account and refresh token.
36   void SetRefreshToken(const std::string& account_id,
37                        const std::string& refresh_token);
38
39   // OAuth2TokenService:
40   bool RefreshTokenIsAvailable(const std::string& account_id) const override;
41   OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
42       const std::string& account_id,
43       net::URLRequestContextGetter* getter,
44       OAuth2AccessTokenConsumer* consumer) override;
45   net::URLRequestContextGetter* GetRequestContext() override;
46
47  private:
48   // Not owned.
49   content::BrowserContext* browser_context_;
50
51   // User account id, such as "foo@gmail.com".
52   std::string account_id_;
53
54   // Cached copy of an OAuth2 refresh token. Not stored on disk.
55   std::string refresh_token_;
56
57   DISALLOW_COPY_AND_ASSIGN(ShellOAuth2TokenService);
58 };
59
60 }  // namespace extensions
61
62 #endif  // EXTENSIONS_SHELL_BROWSER_SHELL_OAUTH2_TOKEN_SERVICE_H_