Commit d96563a1 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Kaleidoscope: delegate identity management to dedicated service.

At the moment, this is only moving a call around.

Bug: b/170751292
Change-Id: I5a991a95afabd5e42df667a66c5984dbe6f24d3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2548697Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Auto-Submit: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830797}
parent c9f9a170
...@@ -3601,6 +3601,8 @@ static_library("browser") { ...@@ -3601,6 +3601,8 @@ static_library("browser") {
"media/kaleidoscope/constants.h", "media/kaleidoscope/constants.h",
"media/kaleidoscope/kaleidoscope_data_provider_impl.cc", "media/kaleidoscope/kaleidoscope_data_provider_impl.cc",
"media/kaleidoscope/kaleidoscope_data_provider_impl.h", "media/kaleidoscope/kaleidoscope_data_provider_impl.h",
"media/kaleidoscope/kaleidoscope_identity_manager_impl.cc",
"media/kaleidoscope/kaleidoscope_identity_manager_impl.h",
"media/kaleidoscope/kaleidoscope_metrics_recorder.cc", "media/kaleidoscope/kaleidoscope_metrics_recorder.cc",
"media/kaleidoscope/kaleidoscope_metrics_recorder.h", "media/kaleidoscope/kaleidoscope_metrics_recorder.h",
"media/kaleidoscope/kaleidoscope_prefs.cc", "media/kaleidoscope/kaleidoscope_prefs.cc",
......
...@@ -104,6 +104,7 @@ ...@@ -104,6 +104,7 @@
#include "chrome/browser/badging/badge_manager.h" #include "chrome/browser/badging/badge_manager.h"
#include "chrome/browser/media/feeds/media_feeds_store.mojom.h" #include "chrome/browser/media/feeds/media_feeds_store.mojom.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_data_provider_impl.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_data_provider_impl.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_identity_manager_impl.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_ui.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_ui.h"
#include "chrome/browser/media/kaleidoscope/mojom/kaleidoscope.mojom.h" #include "chrome/browser/media/kaleidoscope/mojom/kaleidoscope.mojom.h"
#include "chrome/browser/payments/payment_credential_factory.h" #include "chrome/browser/payments/payment_credential_factory.h"
...@@ -810,6 +811,9 @@ void PopulateChromeWebUIFrameBinders( ...@@ -810,6 +811,9 @@ void PopulateChromeWebUIFrameBinders(
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
RegisterWebUIControllerInterfaceBinder<media::mojom::KaleidoscopeDataProvider, RegisterWebUIControllerInterfaceBinder<media::mojom::KaleidoscopeDataProvider,
KaleidoscopeUI, NewTabPageUI>(map); KaleidoscopeUI, NewTabPageUI>(map);
RegisterWebUIControllerInterfaceBinder<
media::mojom::KaleidoscopeIdentityManager, KaleidoscopeUI, NewTabPageUI>(
map);
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -18,17 +18,12 @@ ...@@ -18,17 +18,12 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_access_token_fetcher.h"
#include "components/signin/public/identity_manager/scope_set.h" #include "components/signin/public/identity_manager/scope_set.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_constants.h"
#include "google_apis/google_api_keys.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
namespace { namespace {
...@@ -43,9 +38,6 @@ constexpr int kMediaFeedsFetchedItemsMin = 4; ...@@ -43,9 +38,6 @@ constexpr int kMediaFeedsFetchedItemsMin = 4;
// The maximum number of feed items to display. // The maximum number of feed items to display.
constexpr int kMediaFeedsItemsMaxCount = 20; constexpr int kMediaFeedsItemsMaxCount = 20;
constexpr char kChromeMediaRecommendationsOAuth2Scope[] =
"https://www.googleapis.com/auth/chrome-media-recommendations";
// The minimum watch time needed in media history for a provider to be // The minimum watch time needed in media history for a provider to be
// considered high watch time. // considered high watch time.
constexpr base::TimeDelta kProviderHighWatchTimeMin = constexpr base::TimeDelta kProviderHighWatchTimeMin =
...@@ -73,71 +65,16 @@ KaleidoscopeDataProviderImpl::KaleidoscopeDataProviderImpl( ...@@ -73,71 +65,16 @@ KaleidoscopeDataProviderImpl::KaleidoscopeDataProviderImpl(
mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> receiver, mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> receiver,
Profile* profile, Profile* profile,
KaleidoscopeMetricsRecorder* metrics_recorder) KaleidoscopeMetricsRecorder* metrics_recorder)
: credentials_(media::mojom::Credentials::New()), : profile_(profile),
profile_(profile),
metrics_recorder_(metrics_recorder), metrics_recorder_(metrics_recorder),
receiver_(this, std::move(receiver)) { receiver_(this, std::move(receiver)) {
DCHECK(profile); DCHECK(profile);
// If this is Google Chrome then we should use the official API key. identity_manager_ = IdentityManagerFactory::GetForProfile(profile_);
if (google_apis::IsGoogleChromeAPIKeyUsed()) {
bool is_stable_channel =
chrome::GetChannel() == version_info::Channel::STABLE;
credentials_->api_key = is_stable_channel
? google_apis::GetAPIKey()
: google_apis::GetNonStableAPIKey();
}
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
} }
KaleidoscopeDataProviderImpl::~KaleidoscopeDataProviderImpl() = default; KaleidoscopeDataProviderImpl::~KaleidoscopeDataProviderImpl() = default;
void KaleidoscopeDataProviderImpl::GetCredentials(GetCredentialsCallback cb) {
// If the profile is incognito then disable Kaleidoscope.
if (profile_->IsOffTheRecord()) {
std::move(cb).Run(nullptr,
media::mojom::CredentialsResult::kFailedIncognito);
return;
}
// If the profile is a child then disable Kaleidoscope.
if (profile_->IsSupervised() || profile_->IsChild()) {
std::move(cb).Run(nullptr, media::mojom::CredentialsResult::kFailedChild);
return;
}
// If the administrator has disabled Kaleidoscope then stop.
auto* prefs = profile_->GetPrefs();
if (!prefs->GetBoolean(kaleidoscope::prefs::kKaleidoscopePolicyEnabled)) {
std::move(cb).Run(nullptr,
media::mojom::CredentialsResult::kDisabledByPolicy);
return;
}
// If the user is not signed in, return the credentials without an access
// token. Sync consent is not required to use Kaleidoscope.
if (!identity_manager_->HasPrimaryAccount(
signin::ConsentLevel::kNotRequired)) {
std::move(cb).Run(credentials_.Clone(),
media::mojom::CredentialsResult::kSuccess);
return;
}
pending_callbacks_.push_back(std::move(cb));
// Get an OAuth token for the backend API. This token will be limited to just
// our backend scope. Destroying |token_fetcher_| will cancel the fetch so
// unretained is safe here.
signin::ScopeSet scopes = {kChromeMediaRecommendationsOAuth2Scope};
token_fetcher_ = std::make_unique<signin::PrimaryAccountAccessTokenFetcher>(
"kaleidoscope_service", identity_manager_, scopes,
base::BindOnce(&KaleidoscopeDataProviderImpl::OnAccessTokenAvailable,
base::Unretained(this)),
signin::PrimaryAccountAccessTokenFetcher::Mode::kImmediate,
signin::ConsentLevel::kNotRequired);
}
void KaleidoscopeDataProviderImpl::GetShouldShowFirstRunExperience( void KaleidoscopeDataProviderImpl::GetShouldShowFirstRunExperience(
GetShouldShowFirstRunExperienceCallback cb) { GetShouldShowFirstRunExperienceCallback cb) {
auto* service = kaleidoscope::KaleidoscopeService::Get(profile_); auto* service = kaleidoscope::KaleidoscopeService::Get(profile_);
...@@ -278,11 +215,15 @@ void KaleidoscopeDataProviderImpl::SendFeedback() { ...@@ -278,11 +215,15 @@ void KaleidoscopeDataProviderImpl::SendFeedback() {
std::string() /* extra_diagnostics */); std::string() /* extra_diagnostics */);
} }
void KaleidoscopeDataProviderImpl::GetCollections(const std::string& request, void KaleidoscopeDataProviderImpl::GetCollections(
GetCollectionsCallback cb) { media::mojom::CredentialsPtr credentials,
GetCredentials(base::BindOnce( const std::string& request,
&KaleidoscopeDataProviderImpl::OnGotCredentialsForCollections, GetCollectionsCallback cb) {
weak_ptr_factory.GetWeakPtr(), request, std::move(cb))); auto account_info = identity_manager_->GetPrimaryAccountInfo(
signin::ConsentLevel::kNotRequired);
kaleidoscope::KaleidoscopeService::Get(profile_)->GetCollections(
std::move(credentials), account_info.gaia, request, std::move(cb));
} }
void KaleidoscopeDataProviderImpl::GetSignedOutProviders( void KaleidoscopeDataProviderImpl::GetSignedOutProviders(
...@@ -320,50 +261,12 @@ void KaleidoscopeDataProviderImpl::RecordTimeTakenToStartWatchHistogram( ...@@ -320,50 +261,12 @@ void KaleidoscopeDataProviderImpl::RecordTimeTakenToStartWatchHistogram(
time); time);
} }
void KaleidoscopeDataProviderImpl::OnGotCredentialsForCollections(
const std::string& request,
GetCollectionsCallback cb,
media::mojom::CredentialsPtr credentials,
media::mojom::CredentialsResult result) {
// If we have no credentials then we should return an empty response.
if (result != media::mojom::CredentialsResult::kSuccess) {
std::move(cb).Run(media::mojom::GetCollectionsResponse::New(
"", media::mojom::GetCollectionsResult::kFailed));
return;
}
auto account_info = identity_manager_->GetPrimaryAccountInfo(
signin::ConsentLevel::kNotRequired);
kaleidoscope::KaleidoscopeService::Get(profile_)->GetCollections(
std::move(credentials), account_info.gaia, request, std::move(cb));
}
media_history::MediaHistoryKeyedService* media_history::MediaHistoryKeyedService*
KaleidoscopeDataProviderImpl::GetMediaHistoryService() { KaleidoscopeDataProviderImpl::GetMediaHistoryService() {
return media_history::MediaHistoryKeyedServiceFactory::GetForProfile( return media_history::MediaHistoryKeyedServiceFactory::GetForProfile(
profile_); profile_);
} }
void KaleidoscopeDataProviderImpl::OnAccessTokenAvailable(
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info) {
DCHECK(token_fetcher_);
token_fetcher_.reset();
if (error.state() == GoogleServiceAuthError::State::NONE) {
credentials_->access_token = access_token_info.token;
credentials_->expiry_time = access_token_info.expiration_time;
}
for (auto& callback : pending_callbacks_) {
std::move(callback).Run(credentials_.Clone(),
media::mojom::CredentialsResult::kSuccess);
}
pending_callbacks_.clear();
}
void KaleidoscopeDataProviderImpl::OnGotMediaFeedContents( void KaleidoscopeDataProviderImpl::OnGotMediaFeedContents(
GetMediaFeedContentsCallback callback, GetMediaFeedContentsCallback callback,
const int64_t feed_id, const int64_t feed_id,
......
...@@ -19,9 +19,7 @@ class MediaHistoryKeyedService; ...@@ -19,9 +19,7 @@ class MediaHistoryKeyedService;
} // namespace media_history } // namespace media_history
namespace signin { namespace signin {
struct AccessTokenInfo;
class IdentityManager; class IdentityManager;
class PrimaryAccountAccessTokenFetcher;
} // namespace signin } // namespace signin
class KaleidoscopeMetricsRecorder; class KaleidoscopeMetricsRecorder;
...@@ -34,6 +32,7 @@ class KaleidoscopeDataProviderImpl ...@@ -34,6 +32,7 @@ class KaleidoscopeDataProviderImpl
mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> receiver, mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> receiver,
Profile* profile, Profile* profile,
KaleidoscopeMetricsRecorder* metrics_recorder); KaleidoscopeMetricsRecorder* metrics_recorder);
KaleidoscopeDataProviderImpl(const KaleidoscopeDataProviderImpl&) = delete; KaleidoscopeDataProviderImpl(const KaleidoscopeDataProviderImpl&) = delete;
KaleidoscopeDataProviderImpl& operator=(const KaleidoscopeDataProviderImpl&) = KaleidoscopeDataProviderImpl& operator=(const KaleidoscopeDataProviderImpl&) =
delete; delete;
...@@ -48,7 +47,6 @@ class KaleidoscopeDataProviderImpl ...@@ -48,7 +47,6 @@ class KaleidoscopeDataProviderImpl
void GetContinueWatchingMediaFeedItems( void GetContinueWatchingMediaFeedItems(
media::mojom::KaleidoscopeTab tab, media::mojom::KaleidoscopeTab tab,
GetContinueWatchingMediaFeedItemsCallback callback) override; GetContinueWatchingMediaFeedItemsCallback callback) override;
void GetCredentials(GetCredentialsCallback cb) override;
void GetShouldShowFirstRunExperience( void GetShouldShowFirstRunExperience(
GetShouldShowFirstRunExperienceCallback cb) override; GetShouldShowFirstRunExperienceCallback cb) override;
void SetFirstRunExperienceStep( void SetFirstRunExperienceStep(
...@@ -63,7 +61,8 @@ class KaleidoscopeDataProviderImpl ...@@ -63,7 +61,8 @@ class KaleidoscopeDataProviderImpl
GetAutoSelectMediaFeedsConsentCallback cb) override; GetAutoSelectMediaFeedsConsentCallback cb) override;
void GetHighWatchTimeOrigins(GetHighWatchTimeOriginsCallback cb) override; void GetHighWatchTimeOrigins(GetHighWatchTimeOriginsCallback cb) override;
void SendFeedback() override; void SendFeedback() override;
void GetCollections(const std::string& request, void GetCollections(media::mojom::CredentialsPtr credentials,
const std::string& request,
GetCollectionsCallback cb) override; GetCollectionsCallback cb) override;
void GetSignedOutProviders(GetSignedOutProvidersCallback cb) override; void GetSignedOutProviders(GetSignedOutProvidersCallback cb) override;
void SetSignedOutProviders( void SetSignedOutProviders(
...@@ -73,15 +72,6 @@ class KaleidoscopeDataProviderImpl ...@@ -73,15 +72,6 @@ class KaleidoscopeDataProviderImpl
private: private:
media_history::MediaHistoryKeyedService* GetMediaHistoryService(); media_history::MediaHistoryKeyedService* GetMediaHistoryService();
void OnGotCredentialsForCollections(const std::string& request,
GetCollectionsCallback cb,
media::mojom::CredentialsPtr credentials,
media::mojom::CredentialsResult result);
// Called when an access token request completes (successfully or not).
void OnAccessTokenAvailable(GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info);
void OnGotMediaFeedContents( void OnGotMediaFeedContents(
GetMediaFeedContentsCallback callback, GetMediaFeedContentsCallback callback,
const int64_t feed_id, const int64_t feed_id,
...@@ -90,16 +80,6 @@ class KaleidoscopeDataProviderImpl ...@@ -90,16 +80,6 @@ class KaleidoscopeDataProviderImpl
GetContinueWatchingMediaFeedItemsCallback callback, GetContinueWatchingMediaFeedItemsCallback callback,
std::vector<media_feeds::mojom::MediaFeedItemPtr> items); std::vector<media_feeds::mojom::MediaFeedItemPtr> items);
// Helper for fetching OAuth2 access tokens. This is non-null iff an access
// token request is currently in progress.
std::unique_ptr<signin::PrimaryAccountAccessTokenFetcher> token_fetcher_;
// The current set of credentials.
media::mojom::CredentialsPtr credentials_;
// Pending credentials waiting on an access token.
std::vector<GetCredentialsCallback> pending_callbacks_;
signin::IdentityManager* identity_manager_; signin::IdentityManager* identity_manager_;
Profile* const profile_; Profile* const profile_;
......
// Copyright 2020 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/media/kaleidoscope/kaleidoscope_identity_manager_impl.h"
#include "base/callback.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/channel_info.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_access_token_fetcher.h"
#include "components/version_info/version_info.h"
#include "google_apis/google_api_keys.h"
namespace {
constexpr char kChromeMediaRecommendationsOAuth2Scope[] =
"https://www.googleapis.com/auth/chrome-media-recommendations";
} // namespace
KaleidoscopeIdentityManagerImpl::KaleidoscopeIdentityManagerImpl(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager> receiver,
content::WebUI* web_ui)
: KaleidoscopeIdentityManagerImpl(std::move(receiver),
Profile::FromWebUI(web_ui)) {
DCHECK(web_ui);
web_ui_ = web_ui;
}
KaleidoscopeIdentityManagerImpl::KaleidoscopeIdentityManagerImpl(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager> receiver,
Profile* profile)
: credentials_(media::mojom::Credentials::New()),
profile_(profile),
receiver_(this, std::move(receiver)) {
DCHECK(profile);
// If this is Google Chrome then we should use the official API key.
if (google_apis::IsGoogleChromeAPIKeyUsed()) {
bool is_stable_channel =
chrome::GetChannel() == version_info::Channel::STABLE;
credentials_->api_key = is_stable_channel
? google_apis::GetAPIKey()
: google_apis::GetNonStableAPIKey();
}
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
}
KaleidoscopeIdentityManagerImpl::~KaleidoscopeIdentityManagerImpl() = default;
void KaleidoscopeIdentityManagerImpl::GetCredentials(
GetCredentialsCallback cb) {
// If the profile is incognito then disable Kaleidoscope.
if (profile_->IsOffTheRecord()) {
std::move(cb).Run(nullptr,
media::mojom::CredentialsResult::kFailedIncognito);
return;
}
// If the profile is a child then disable Kaleidoscope.
if (profile_->IsSupervised() || profile_->IsChild()) {
std::move(cb).Run(nullptr, media::mojom::CredentialsResult::kFailedChild);
return;
}
// If the administrator has disabled Kaleidoscope then stop.
auto* prefs = profile_->GetPrefs();
if (!prefs->GetBoolean(kaleidoscope::prefs::kKaleidoscopePolicyEnabled)) {
std::move(cb).Run(nullptr,
media::mojom::CredentialsResult::kDisabledByPolicy);
return;
}
// If the user is not signed in, return the credentials without an access
// token. Sync consent is not required to use Kaleidoscope.
if (!identity_manager_->HasPrimaryAccount(
signin::ConsentLevel::kNotRequired)) {
std::move(cb).Run(credentials_.Clone(),
media::mojom::CredentialsResult::kSuccess);
return;
}
pending_callbacks_.push_back(std::move(cb));
// Get an OAuth token for the backend API. This token will be limited to just
// our backend scope. Destroying |token_fetcher_| will cancel the fetch so
// unretained is safe here.
signin::ScopeSet scopes = {kChromeMediaRecommendationsOAuth2Scope};
token_fetcher_ = std::make_unique<signin::PrimaryAccountAccessTokenFetcher>(
"kaleidoscope_service", identity_manager_, scopes,
base::BindOnce(&KaleidoscopeIdentityManagerImpl::OnAccessTokenAvailable,
base::Unretained(this)),
signin::PrimaryAccountAccessTokenFetcher::Mode::kImmediate,
signin::ConsentLevel::kNotRequired);
}
void KaleidoscopeIdentityManagerImpl::OnAccessTokenAvailable(
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info) {
DCHECK(token_fetcher_);
token_fetcher_.reset();
if (error.state() == GoogleServiceAuthError::State::NONE) {
credentials_->access_token = access_token_info.token;
credentials_->expiry_time = access_token_info.expiration_time;
}
for (auto& callback : pending_callbacks_) {
std::move(callback).Run(credentials_.Clone(),
media::mojom::CredentialsResult::kSuccess);
}
pending_callbacks_.clear();
}
// Copyright 2020 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 CHROME_BROWSER_MEDIA_KALEIDOSCOPE_KALEIDOSCOPE_IDENTITY_MANAGER_IMPL_H_
#define CHROME_BROWSER_MEDIA_KALEIDOSCOPE_KALEIDOSCOPE_IDENTITY_MANAGER_IMPL_H_
#include <memory>
#include "chrome/browser/media/kaleidoscope/mojom/kaleidoscope.mojom.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace content {
class WebUI;
} // namespace content
namespace signin {
struct AccessTokenInfo;
class IdentityManager;
class PrimaryAccountAccessTokenFetcher;
} // namespace signin
class Profile;
class KaleidoscopeIdentityManagerImpl
: public media::mojom::KaleidoscopeIdentityManager {
public:
KaleidoscopeIdentityManagerImpl(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager> receiver,
content::WebUI* web_ui);
KaleidoscopeIdentityManagerImpl(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager> receiver,
Profile* profile);
KaleidoscopeIdentityManagerImpl(const KaleidoscopeIdentityManagerImpl&) =
delete;
KaleidoscopeIdentityManagerImpl& operator=(
const KaleidoscopeIdentityManagerImpl&) = delete;
~KaleidoscopeIdentityManagerImpl() override;
// media::mojom::KaleidoscopeIdentityManager implementation.
void GetCredentials(GetCredentialsCallback cb) override;
private:
// Called when an access token request completes (successfully or not).
void OnAccessTokenAvailable(GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info);
// Helper for fetching OAuth2 access tokens. This is non-null iff an access
// token request is currently in progress.
std::unique_ptr<signin::PrimaryAccountAccessTokenFetcher> token_fetcher_;
// Pending credentials waiting on an access token.
std::vector<GetCredentialsCallback> pending_callbacks_;
// The current set of credentials.
media::mojom::CredentialsPtr credentials_;
signin::IdentityManager* identity_manager_;
content::WebUI* web_ui_ = nullptr;
Profile* profile_ = nullptr;
mojo::Receiver<media::mojom::KaleidoscopeIdentityManager> receiver_;
};
#endif // CHROME_BROWSER_MEDIA_KALEIDOSCOPE_KALEIDOSCOPE_IDENTITY_MANAGER_IMPL_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/media/kaleidoscope/constants.h" #include "chrome/browser/media/kaleidoscope/constants.h"
#include "chrome/browser/media/kaleidoscope/grit/kaleidoscope_resources.h" #include "chrome/browser/media/kaleidoscope/grit/kaleidoscope_resources.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_data_provider_impl.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_data_provider_impl.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_identity_manager_impl.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_metrics_recorder.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_metrics_recorder.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_switches.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_switches.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -246,6 +247,7 @@ KaleidoscopeUI::~KaleidoscopeUI() { ...@@ -246,6 +247,7 @@ KaleidoscopeUI::~KaleidoscopeUI() {
// provider has a pointer to the metrics recorder. // provider has a pointer to the metrics recorder.
provider_.reset(); provider_.reset();
metrics_recorder_.reset(); metrics_recorder_.reset();
identity_manager_.reset();
} }
// static // static
...@@ -393,4 +395,11 @@ void KaleidoscopeUI::BindInterface( ...@@ -393,4 +395,11 @@ void KaleidoscopeUI::BindInterface(
metrics_recorder_.get()); metrics_recorder_.get());
} }
void KaleidoscopeUI::BindInterface(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager>
identity_manager) {
identity_manager_ = std::make_unique<KaleidoscopeIdentityManagerImpl>(
std::move(identity_manager), web_ui());
}
WEB_UI_CONTROLLER_TYPE_IMPL(KaleidoscopeUI) WEB_UI_CONTROLLER_TYPE_IMPL(KaleidoscopeUI)
...@@ -24,6 +24,9 @@ class KaleidoscopeUI : public ui::MojoWebUIController { ...@@ -24,6 +24,9 @@ class KaleidoscopeUI : public ui::MojoWebUIController {
void BindInterface( void BindInterface(
mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> provider); mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> provider);
void BindInterface(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager>
identity_manager);
static content::WebUIDataSource* CreateWebUIDataSource(); static content::WebUIDataSource* CreateWebUIDataSource();
...@@ -32,6 +35,7 @@ class KaleidoscopeUI : public ui::MojoWebUIController { ...@@ -32,6 +35,7 @@ class KaleidoscopeUI : public ui::MojoWebUIController {
private: private:
std::unique_ptr<KaleidoscopeMetricsRecorder> metrics_recorder_; std::unique_ptr<KaleidoscopeMetricsRecorder> metrics_recorder_;
std::unique_ptr<media::mojom::KaleidoscopeDataProvider> provider_; std::unique_ptr<media::mojom::KaleidoscopeDataProvider> provider_;
std::unique_ptr<media::mojom::KaleidoscopeIdentityManager> identity_manager_;
WEB_UI_CONTROLLER_TYPE_DECL(); WEB_UI_CONTROLLER_TYPE_DECL();
}; };
......
...@@ -60,9 +60,6 @@ interface KaleidoscopeDataProvider { ...@@ -60,9 +60,6 @@ interface KaleidoscopeDataProvider {
// continue watching. Returned items will be appropriate for the |tab|. // continue watching. Returned items will be appropriate for the |tab|.
GetContinueWatchingMediaFeedItems(KaleidoscopeTab tab) => (array<media_feeds.mojom.MediaFeedItem> items); GetContinueWatchingMediaFeedItems(KaleidoscopeTab tab) => (array<media_feeds.mojom.MediaFeedItem> items);
// Retrieves the current credentials.
GetCredentials() => (Credentials? credentials, CredentialsResult result);
// Returns true if the first run experience should be shown. // Returns true if the first run experience should be shown.
GetShouldShowFirstRunExperience() => (bool should_show_first_run); GetShouldShowFirstRunExperience() => (bool should_show_first_run);
...@@ -92,10 +89,11 @@ interface KaleidoscopeDataProvider { ...@@ -92,10 +89,11 @@ interface KaleidoscopeDataProvider {
// Will trigger a feedback dialog to be displayed. // Will trigger a feedback dialog to be displayed.
SendFeedback(); SendFeedback();
// Gets the collections from the backend to be displayed. Takes a string that // Gets the collections from the backend to be displayed. Takes a credential
// contains the request to be sent to the server. The request is the // instance and a string that contains the request to be sent to the server.
// GetCollectionsRequest proto here: go/ks-media-proto. // The request is the GetCollectionsRequest proto here: go/ks-media-proto.
GetCollections(string request) => (GetCollectionsResponse response); GetCollections(Credentials credentials, string request)
=> (GetCollectionsResponse response);
// Gets a list of stored providers that will be used to filter the // Gets a list of stored providers that will be used to filter the
// recommendations on the server if the user is signed out. They are arbitary // recommendations on the server if the user is signed out. They are arbitary
...@@ -111,6 +109,12 @@ interface KaleidoscopeDataProvider { ...@@ -111,6 +109,12 @@ interface KaleidoscopeDataProvider {
RecordTimeTakenToStartWatchHistogram(mojo_base.mojom.TimeDelta time); RecordTimeTakenToStartWatchHistogram(mojo_base.mojom.TimeDelta time);
}; };
// Handles identity related tasks.
interface KaleidoscopeIdentityManager {
// Retrieves the current credentials.
GetCredentials() => (Credentials? credentials, CredentialsResult result);
};
enum GetCollectionsResult { enum GetCollectionsResult {
// The request was successful. // The request was successful.
kSuccess, kSuccess,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/buildflags.h" #include "chrome/browser/buildflags.h"
#include "chrome/browser/media/kaleidoscope/constants.h" #include "chrome/browser/media/kaleidoscope/constants.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_data_provider_impl.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_data_provider_impl.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_identity_manager_impl.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_ui.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_ui.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_service.h" #include "chrome/browser/search/instant_service.h"
...@@ -387,6 +388,14 @@ void NewTabPageUI::BindInterface( ...@@ -387,6 +388,14 @@ void NewTabPageUI::BindInterface(
std::move(pending_page_handler), profile_, nullptr); std::move(pending_page_handler), profile_, nullptr);
} }
void NewTabPageUI::BindInterface(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager>
pending_page_handler) {
kaleidoscope_identity_manager_ =
std::make_unique<KaleidoscopeIdentityManagerImpl>(
std::move(pending_page_handler), profile_);
}
void NewTabPageUI::BindInterface( void NewTabPageUI::BindInterface(
mojo::PendingReceiver<task_module::mojom::TaskModuleHandler> mojo::PendingReceiver<task_module::mojom::TaskModuleHandler>
pending_receiver) { pending_receiver) {
......
...@@ -34,6 +34,7 @@ class FooHandler; ...@@ -34,6 +34,7 @@ class FooHandler;
class GURL; class GURL;
class InstantService; class InstantService;
class KaleidoscopeDataProviderImpl; class KaleidoscopeDataProviderImpl;
class KaleidoscopeIdentityManagerImpl;
class NewTabPageHandler; class NewTabPageHandler;
class Profile; class Profile;
class PromoBrowserCommandHandler; class PromoBrowserCommandHandler;
...@@ -78,6 +79,13 @@ class NewTabPageUI ...@@ -78,6 +79,13 @@ class NewTabPageUI
mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider> mojo::PendingReceiver<media::mojom::KaleidoscopeDataProvider>
pending_receiver); pending_receiver);
// Instantiates the implementor of the
// media::mojom::KaleidoscopeIdentityManager mojo interface passing the
// pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<media::mojom::KaleidoscopeIdentityManager>
pending_receiver);
// Instantiates the implementor of the // Instantiates the implementor of the
// shopping_tasks::mojom::ShoppingTasksHandler mojo interface passing the // shopping_tasks::mojom::ShoppingTasksHandler mojo interface passing the
// pending receiver that will be internally bound. // pending receiver that will be internally bound.
...@@ -138,6 +146,8 @@ class NewTabPageUI ...@@ -138,6 +146,8 @@ class NewTabPageUI
// Mojo implementations for modules: // Mojo implementations for modules:
std::unique_ptr<KaleidoscopeDataProviderImpl> kaleidoscope_data_provider_; std::unique_ptr<KaleidoscopeDataProviderImpl> kaleidoscope_data_provider_;
std::unique_ptr<KaleidoscopeIdentityManagerImpl>
kaleidoscope_identity_manager_;
std::unique_ptr<TaskModuleHandler> task_module_handler_; std::unique_ptr<TaskModuleHandler> task_module_handler_;
WEB_UI_CONTROLLER_TYPE_DECL(); WEB_UI_CONTROLLER_TYPE_DECL();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment