| Index: chrome/browser/extensions/api/identity/identity_get_auth_token_function.cc
|
| diff --git a/chrome/browser/extensions/api/identity/identity_api.cc b/chrome/browser/extensions/api/identity/identity_get_auth_token_function.cc
|
| similarity index 74%
|
| copy from chrome/browser/extensions/api/identity/identity_api.cc
|
| copy to chrome/browser/extensions/api/identity/identity_get_auth_token_function.cc
|
| index 4b74c3fe3091562a2cdfa3c8fab47451caee05a5..6f52b003546879494c59cbb3e3ce0336aded4e85 100644
|
| --- a/chrome/browser/extensions/api/identity/identity_api.cc
|
| +++ b/chrome/browser/extensions/api/identity/identity_get_auth_token_function.cc
|
| @@ -1,53 +1,26 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 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 "chrome/browser/extensions/api/identity/identity_api.h"
|
| -
|
| -#include <stddef.h>
|
| -
|
| -#include <memory>
|
| -#include <set>
|
| -#include <string>
|
| -#include <utility>
|
| -#include <vector>
|
| +#include "chrome/browser/extensions/api/identity/identity_get_auth_token_function.h"
|
|
|
| -#include "base/lazy_instance.h"
|
| -#include "base/macros.h"
|
| -#include "base/memory/ptr_util.h"
|
| #include "base/strings/string_number_conversions.h"
|
| -#include "base/strings/stringprintf.h"
|
| -#include "base/trace_event/trace_event.h"
|
| -#include "base/values.h"
|
| -#include "build/build_config.h"
|
| -#include "chrome/browser/app_mode/app_mode_utils.h"
|
| -#include "chrome/browser/browser_process.h"
|
| -#include "chrome/browser/chrome_notification_types.h"
|
| +#include "chrome/browser/extensions/api/identity/identity_api.h"
|
| #include "chrome/browser/extensions/api/identity/identity_constants.h"
|
| -#include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/signin/account_tracker_service_factory.h"
|
| #include "chrome/browser/signin/chrome_signin_client_factory.h"
|
| #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
|
| #include "chrome/browser/signin/signin_manager_factory.h"
|
| -#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
|
| #include "chrome/common/extensions/api/identity.h"
|
| -#include "chrome/common/url_constants.h"
|
| -#include "components/signin/core/browser/account_tracker_service.h"
|
| #include "components/signin/core/browser/profile_oauth2_token_service.h"
|
| #include "components/signin/core/browser/signin_manager.h"
|
| #include "components/signin/core/common/profile_management_switches.h"
|
| -#include "extensions/browser/event_router.h"
|
| -#include "extensions/browser/extension_function_dispatcher.h"
|
| -#include "extensions/common/extension.h"
|
| #include "extensions/common/extension_l10n_util.h"
|
| -#include "extensions/common/manifest_handlers/oauth2_manifest_handler.h"
|
| -#include "extensions/common/permissions/permission_set.h"
|
| -#include "extensions/common/permissions/permissions_data.h"
|
| #include "google_apis/gaia/gaia_urls.h"
|
| -#include "url/gurl.h"
|
|
|
| #if defined(OS_CHROMEOS)
|
| +#include "chrome/browser/app_mode/app_mode_utils.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chromeos/login/session/user_session_manager.h"
|
| #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
|
| #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
|
| @@ -80,208 +53,6 @@ std::string GetPrimaryAccountId(content::BrowserContext* context) {
|
|
|
| namespace identity = api::identity;
|
|
|
| -IdentityTokenCacheValue::IdentityTokenCacheValue()
|
| - : status_(CACHE_STATUS_NOTFOUND) {}
|
| -
|
| -IdentityTokenCacheValue::IdentityTokenCacheValue(
|
| - const IssueAdviceInfo& issue_advice)
|
| - : status_(CACHE_STATUS_ADVICE), issue_advice_(issue_advice) {
|
| - expiration_time_ =
|
| - base::Time::Now() + base::TimeDelta::FromSeconds(
|
| - identity_constants::kCachedIssueAdviceTTLSeconds);
|
| -}
|
| -
|
| -IdentityTokenCacheValue::IdentityTokenCacheValue(const std::string& token,
|
| - base::TimeDelta time_to_live)
|
| - : status_(CACHE_STATUS_TOKEN), token_(token) {
|
| - // Remove 20 minutes from the ttl so cached tokens will have some time
|
| - // to live any time they are returned.
|
| - time_to_live -= base::TimeDelta::FromMinutes(20);
|
| -
|
| - base::TimeDelta zero_delta;
|
| - if (time_to_live < zero_delta)
|
| - time_to_live = zero_delta;
|
| -
|
| - expiration_time_ = base::Time::Now() + time_to_live;
|
| -}
|
| -
|
| -IdentityTokenCacheValue::IdentityTokenCacheValue(
|
| - const IdentityTokenCacheValue& other) = default;
|
| -
|
| -IdentityTokenCacheValue::~IdentityTokenCacheValue() {}
|
| -
|
| -IdentityTokenCacheValue::CacheValueStatus IdentityTokenCacheValue::status()
|
| - const {
|
| - if (is_expired())
|
| - return IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND;
|
| - else
|
| - return status_;
|
| -}
|
| -
|
| -const IssueAdviceInfo& IdentityTokenCacheValue::issue_advice() const {
|
| - return issue_advice_;
|
| -}
|
| -
|
| -const std::string& IdentityTokenCacheValue::token() const { return token_; }
|
| -
|
| -bool IdentityTokenCacheValue::is_expired() const {
|
| - return status_ == CACHE_STATUS_NOTFOUND ||
|
| - expiration_time_ < base::Time::Now();
|
| -}
|
| -
|
| -const base::Time& IdentityTokenCacheValue::expiration_time() const {
|
| - return expiration_time_;
|
| -}
|
| -
|
| -IdentityAPI::IdentityAPI(content::BrowserContext* context)
|
| - : browser_context_(context),
|
| - profile_identity_provider_(
|
| - SigninManagerFactory::GetForProfile(
|
| - Profile::FromBrowserContext(context)),
|
| - ProfileOAuth2TokenServiceFactory::GetForProfile(
|
| - Profile::FromBrowserContext(context)),
|
| - LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(
|
| - Profile::FromBrowserContext(context))),
|
| - account_tracker_(&profile_identity_provider_,
|
| - g_browser_process->system_request_context()),
|
| - get_auth_token_function_(nullptr) {
|
| - account_tracker_.AddObserver(this);
|
| -}
|
| -
|
| -IdentityAPI::~IdentityAPI() {}
|
| -
|
| -IdentityMintRequestQueue* IdentityAPI::mint_queue() { return &mint_queue_; }
|
| -
|
| -void IdentityAPI::SetCachedToken(const ExtensionTokenKey& key,
|
| - const IdentityTokenCacheValue& token_data) {
|
| - CachedTokens::iterator it = token_cache_.find(key);
|
| - if (it != token_cache_.end() && it->second.status() <= token_data.status())
|
| - token_cache_.erase(it);
|
| -
|
| - token_cache_.insert(std::make_pair(key, token_data));
|
| -}
|
| -
|
| -void IdentityAPI::EraseCachedToken(const std::string& extension_id,
|
| - const std::string& token) {
|
| - CachedTokens::iterator it;
|
| - for (it = token_cache_.begin(); it != token_cache_.end(); ++it) {
|
| - if (it->first.extension_id == extension_id &&
|
| - it->second.status() == IdentityTokenCacheValue::CACHE_STATUS_TOKEN &&
|
| - it->second.token() == token) {
|
| - token_cache_.erase(it);
|
| - break;
|
| - }
|
| - }
|
| -}
|
| -
|
| -void IdentityAPI::EraseAllCachedTokens() { token_cache_.clear(); }
|
| -
|
| -const IdentityTokenCacheValue& IdentityAPI::GetCachedToken(
|
| - const ExtensionTokenKey& key) {
|
| - return token_cache_[key];
|
| -}
|
| -
|
| -const IdentityAPI::CachedTokens& IdentityAPI::GetAllCachedTokens() {
|
| - return token_cache_;
|
| -}
|
| -
|
| -std::vector<std::string> IdentityAPI::GetAccounts() const {
|
| - const std::string primary_account_id = GetPrimaryAccountId(browser_context_);
|
| - const std::vector<gaia::AccountIds> ids = account_tracker_.GetAccounts();
|
| - std::vector<std::string> gaia_ids;
|
| -
|
| - if (switches::IsExtensionsMultiAccount()) {
|
| - for (std::vector<gaia::AccountIds>::const_iterator it = ids.begin();
|
| - it != ids.end();
|
| - ++it) {
|
| - gaia_ids.push_back(it->gaia);
|
| - }
|
| - } else if (ids.size() >= 1) {
|
| - gaia_ids.push_back(ids[0].gaia);
|
| - }
|
| -
|
| - return gaia_ids;
|
| -}
|
| -
|
| -std::string IdentityAPI::FindAccountKeyByGaiaId(const std::string& gaia_id) {
|
| - return account_tracker_.FindAccountIdsByGaiaId(gaia_id).account_key;
|
| -}
|
| -
|
| -void IdentityAPI::Shutdown() {
|
| - if (get_auth_token_function_)
|
| - get_auth_token_function_->Shutdown();
|
| - account_tracker_.RemoveObserver(this);
|
| - account_tracker_.Shutdown();
|
| -}
|
| -
|
| -static base::LazyInstance<BrowserContextKeyedAPIFactory<IdentityAPI> >
|
| - g_factory = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| -// static
|
| -BrowserContextKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() {
|
| - return g_factory.Pointer();
|
| -}
|
| -
|
| -void IdentityAPI::OnAccountAdded(const gaia::AccountIds& ids) {
|
| -}
|
| -
|
| -void IdentityAPI::OnAccountRemoved(const gaia::AccountIds& ids) {
|
| -}
|
| -
|
| -void IdentityAPI::OnAccountSignInChanged(const gaia::AccountIds& ids,
|
| - bool is_signed_in) {
|
| - api::identity::AccountInfo account_info;
|
| - account_info.id = ids.gaia;
|
| -
|
| - std::unique_ptr<base::ListValue> args =
|
| - api::identity::OnSignInChanged::Create(account_info, is_signed_in);
|
| - std::unique_ptr<Event> event(
|
| - new Event(events::IDENTITY_ON_SIGN_IN_CHANGED,
|
| - api::identity::OnSignInChanged::kEventName, std::move(args),
|
| - browser_context_));
|
| -
|
| - EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event));
|
| -}
|
| -
|
| -void IdentityAPI::SetAccountStateForTest(gaia::AccountIds ids,
|
| - bool is_signed_in) {
|
| - account_tracker_.SetAccountStateForTest(ids, is_signed_in);
|
| -}
|
| -
|
| -template <>
|
| -void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies() {
|
| - DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
|
| - DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
|
| -}
|
| -
|
| -IdentityGetAccountsFunction::IdentityGetAccountsFunction() {
|
| -}
|
| -
|
| -IdentityGetAccountsFunction::~IdentityGetAccountsFunction() {
|
| -}
|
| -
|
| -ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() {
|
| - if (GetProfile()->IsOffTheRecord()) {
|
| - return RespondNow(Error(identity_constants::kOffTheRecord));
|
| - }
|
| -
|
| - std::vector<std::string> gaia_ids =
|
| - IdentityAPI::GetFactoryInstance()->Get(GetProfile())->GetAccounts();
|
| - DCHECK(gaia_ids.size() < 2 || switches::IsExtensionsMultiAccount());
|
| -
|
| - std::unique_ptr<base::ListValue> infos(new base::ListValue());
|
| -
|
| - for (std::vector<std::string>::const_iterator it = gaia_ids.begin();
|
| - it != gaia_ids.end();
|
| - ++it) {
|
| - api::identity::AccountInfo account_info;
|
| - account_info.id = *it;
|
| - infos->Append(account_info.ToValue());
|
| - }
|
| -
|
| - return RespondNow(OneArgument(std::move(infos)));
|
| -}
|
| -
|
| IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction()
|
| : OAuth2TokenService::Consumer("extensions_identity_api"),
|
| interactive_(false),
|
|
|