Commit 33f648c0 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Disable Kaleidoscope for incognito and child users

Change-Id: I63b64b85cd4c9b42bef2a3f1518d79d573e9131f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352514Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797385}
parent 6acc2daa
......@@ -81,17 +81,30 @@ KaleidoscopeDataProviderImpl::KaleidoscopeDataProviderImpl(
}
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
DCHECK(identity_manager_);
}
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 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());
std::move(cb).Run(credentials_.Clone(),
media::mojom::CredentialsResult::kSuccess);
return;
}
......@@ -183,8 +196,10 @@ void KaleidoscopeDataProviderImpl::OnAccessTokenAvailable(
if (error.state() == GoogleServiceAuthError::State::NONE)
credentials_->access_token = access_token_info.token;
for (auto& callback : pending_callbacks_)
std::move(callback).Run(credentials_.Clone());
for (auto& callback : pending_callbacks_) {
std::move(callback).Run(credentials_.Clone(),
media::mojom::CredentialsResult::kSuccess);
}
pending_callbacks_.clear();
}
......
......@@ -7,6 +7,13 @@ module media.mojom;
import "chrome/browser/media/feeds/media_feeds_store.mojom";
import "url/mojom/origin.mojom";
// The result of getting the credentials.
enum CredentialsResult {
kSuccess,
kFailedIncognito,
kFailedChild,
};
// The credentials required to make Google API calls from JS.
struct Credentials {
// Chrome's API Key.
......@@ -43,7 +50,7 @@ interface KaleidoscopeDataProvider {
GetContinueWatchingMediaFeedItems(KaleidoscopeTab tab) => (array<media_feeds.mojom.MediaFeedItem> items);
// Retrieves the current credentials.
GetCredentials() => (Credentials credentials);
GetCredentials() => (Credentials? credentials, CredentialsResult result);
// Returns all the watch time origins from media history store that have
// watch time above a threshold.
......
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