summaryrefslogtreecommitdiffstats
path: root/extensions/shell/browser/shell_oauth2_token_service_delegate.cc
blob: 89eb2120447028e417e22256bded7dcdc1020ad4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 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.

#include "extensions/shell/browser/shell_oauth2_token_service_delegate.h"

#include <vector>

namespace extensions {

ShellOAuth2TokenServiceDelegate::ShellOAuth2TokenServiceDelegate(
    content::BrowserContext* browser_context,
    std::string account_id,
    std::string refresh_token)
    : browser_context_(browser_context),
      account_id_(account_id),
      refresh_token_(refresh_token) {
}

ShellOAuth2TokenServiceDelegate::~ShellOAuth2TokenServiceDelegate() {
}

bool ShellOAuth2TokenServiceDelegate::RefreshTokenIsAvailable(
    const std::string& account_id) const {
  if (account_id != account_id_)
    return false;

  return !refresh_token_.empty();
}

OAuth2AccessTokenFetcher*
ShellOAuth2TokenServiceDelegate::CreateAccessTokenFetcher(
    const std::string& account_id,
    net::URLRequestContextGetter* getter,
    OAuth2AccessTokenConsumer* consumer) {
  DCHECK_EQ(account_id, account_id_);
  DCHECK(!refresh_token_.empty());
  return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token_);
}

net::URLRequestContextGetter*
ShellOAuth2TokenServiceDelegate::GetRequestContext() const {
  return browser_context_->GetRequestContext();
}

std::vector<std::string> ShellOAuth2TokenServiceDelegate::GetAccounts() {
  std::vector<std::string> accounts;
  accounts.push_back(account_id_);
  return accounts;
}

void ShellOAuth2TokenServiceDelegate::UpdateCredentials(
    const std::string& account_id,
    const std::string& refresh_token) {
  account_id_ = account_id;
  refresh_token_ = refresh_token;
}

}  // namespace extensions