Commit ca01818e authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Add a "first run" state for the module

If Kaleidoscope is available to the user and also we
need to shown the first run to the user then we send
back a different state to the module telling it to
use the first run promo.

BUG=1121360

Change-Id: Id48006d0b4c079742b674c73a99895b2e8abcbdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401504
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805583}
parent ced2fad6
...@@ -131,33 +131,8 @@ void KaleidoscopeDataProviderImpl::GetCredentials(GetCredentialsCallback cb) { ...@@ -131,33 +131,8 @@ void KaleidoscopeDataProviderImpl::GetCredentials(GetCredentialsCallback cb) {
void KaleidoscopeDataProviderImpl::GetShouldShowFirstRunExperience( void KaleidoscopeDataProviderImpl::GetShouldShowFirstRunExperience(
GetShouldShowFirstRunExperienceCallback cb) { GetShouldShowFirstRunExperienceCallback cb) {
// If the flag for forcing the first run experience to show is set, then just std::move(cb).Run(kaleidoscope::KaleidoscopeService::Get(profile_)
// show it. ->ShouldShowFirstRunExperience());
if (base::FeatureList::IsEnabled(
media::kKaleidoscopeForceShowFirstRunExperience)) {
std::move(cb).Run(true);
return;
}
// Otherwise, check to see if the user has already completed the latest first
// run experience.
auto* prefs = profile_->GetPrefs();
if (!prefs) {
std::move(cb).Run(true);
return;
}
// If the pref is unset or lower than the current version, then we haven't
// shown the current first run experience before and we should show it now.
const base::Value* pref = prefs->GetUserPrefValue(
kaleidoscope::prefs::kKaleidoscopeFirstRunCompleted);
if (!pref || pref->GetInt() < kKaleidoscopeFirstRunLatestVersion) {
std::move(cb).Run(true);
return;
}
// Otherwise, we have shown it and don't need to.
std::move(cb).Run(false);
} }
void KaleidoscopeDataProviderImpl::SetFirstRunExperienceStep( void KaleidoscopeDataProviderImpl::SetFirstRunExperienceStep(
...@@ -175,6 +150,9 @@ void KaleidoscopeDataProviderImpl::SetFirstRunExperienceStep( ...@@ -175,6 +150,9 @@ void KaleidoscopeDataProviderImpl::SetFirstRunExperienceStep(
prefs->SetInteger(kaleidoscope::prefs::kKaleidoscopeFirstRunCompleted, prefs->SetInteger(kaleidoscope::prefs::kKaleidoscopeFirstRunCompleted,
kKaleidoscopeFirstRunLatestVersion); kKaleidoscopeFirstRunLatestVersion);
// Delete any cached data that has the first run stored in it.
GetMediaHistoryService()->DeleteKaleidoscopeData();
} }
void KaleidoscopeDataProviderImpl::GetAllMediaFeeds( void KaleidoscopeDataProviderImpl::GetAllMediaFeeds(
......
...@@ -10,9 +10,12 @@ ...@@ -10,9 +10,12 @@
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "chrome/browser/media/history/media_history_store.h" #include "chrome/browser/media/history/media_history_store.h"
#include "chrome/browser/media/kaleidoscope/constants.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_prefs.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_service_factory.h" #include "chrome/browser/media/kaleidoscope/kaleidoscope_service_factory.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"
#include "components/prefs/pref_service.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -178,6 +181,31 @@ void KaleidoscopeService::SetCollectionsForTesting( ...@@ -178,6 +181,31 @@ void KaleidoscopeService::SetCollectionsForTesting(
""); "");
} }
bool KaleidoscopeService::ShouldShowFirstRunExperience() {
// If the flag for forcing the first run experience to show is set, then just
// show it.
if (base::FeatureList::IsEnabled(
media::kKaleidoscopeForceShowFirstRunExperience)) {
return true;
}
// Otherwise, check to see if the user has already completed the latest first
// run experience.
auto* prefs = profile_->GetPrefs();
if (!prefs)
return true;
// If the pref is unset or lower than the current version, then we haven't
// shown the current first run experience before and we should show it now.
const base::Value* pref = prefs->GetUserPrefValue(
kaleidoscope::prefs::kKaleidoscopeFirstRunCompleted);
if (!pref || pref->GetInt() < kKaleidoscopeFirstRunLatestVersion)
return true;
// Otherwise, we have shown it and don't need to.
return false;
}
void KaleidoscopeService::OnGotCachedData( void KaleidoscopeService::OnGotCachedData(
media::mojom::CredentialsPtr credentials, media::mojom::CredentialsPtr credentials,
const std::string& gaia_id, const std::string& gaia_id,
...@@ -227,6 +255,11 @@ void KaleidoscopeService::OnURLFetchComplete( ...@@ -227,6 +255,11 @@ void KaleidoscopeService::OnURLFetchComplete(
response->result = media::mojom::GetCollectionsResult::kNotAvailable; response->result = media::mojom::GetCollectionsResult::kNotAvailable;
} else if (request_->has_failed()) { } else if (request_->has_failed()) {
response->result = media::mojom::GetCollectionsResult::kFailed; response->result = media::mojom::GetCollectionsResult::kFailed;
} else if (ShouldShowFirstRunExperience()) {
// If we should show the first run experience then we should send a special
// "first run" response which will trigger the module to display the first
// run promo message.
response->result = media::mojom::GetCollectionsResult::kFirstRun;
} else { } else {
response->result = media::mojom::GetCollectionsResult::kSuccess; response->result = media::mojom::GetCollectionsResult::kSuccess;
response->response = *data; response->response = *data;
......
...@@ -52,6 +52,8 @@ class KaleidoscopeService : public KeyedService { ...@@ -52,6 +52,8 @@ class KaleidoscopeService : public KeyedService {
void SetCollectionsForTesting(const std::string& collections); void SetCollectionsForTesting(const std::string& collections);
bool ShouldShowFirstRunExperience();
private: private:
friend class KaleidoscopeServiceTest; friend class KaleidoscopeServiceTest;
......
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "chrome/browser/media/kaleidoscope/constants.h"
#include "chrome/browser/media/kaleidoscope/kaleidoscope_prefs.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/prefs/pref_service.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h" #include "services/network/test/test_url_loader_factory.h"
...@@ -88,6 +91,12 @@ class KaleidoscopeServiceTest : public ChromeRenderViewHostTestHarness { ...@@ -88,6 +91,12 @@ class KaleidoscopeServiceTest : public ChromeRenderViewHostTestHarness {
return KaleidoscopeService::Get(profile()); return KaleidoscopeService::Get(profile());
} }
void MarkFirstRunAsComplete() {
profile()->GetPrefs()->SetInteger(
kaleidoscope::prefs::kKaleidoscopeFirstRunCompleted,
kKaleidoscopeFirstRunLatestVersion);
}
private: private:
std::string GetCurrentlyQueriedHeaderValue(const base::StringPiece& key) { std::string GetCurrentlyQueriedHeaderValue(const base::StringPiece& key) {
std::string out; std::string out;
...@@ -103,6 +112,8 @@ class KaleidoscopeServiceTest : public ChromeRenderViewHostTestHarness { ...@@ -103,6 +112,8 @@ class KaleidoscopeServiceTest : public ChromeRenderViewHostTestHarness {
}; };
TEST_F(KaleidoscopeServiceTest, Success) { TEST_F(KaleidoscopeServiceTest, Success) {
MarkFirstRunAsComplete();
GetService()->GetCollections( GetService()->GetCollections(
CreateCredentials(), "123", "abcd", CreateCredentials(), "123", "abcd",
base::BindLambdaForTesting( base::BindLambdaForTesting(
...@@ -143,6 +154,8 @@ TEST_F(KaleidoscopeServiceTest, Success) { ...@@ -143,6 +154,8 @@ TEST_F(KaleidoscopeServiceTest, Success) {
} }
TEST_F(KaleidoscopeServiceTest, ServerFail_Forbidden) { TEST_F(KaleidoscopeServiceTest, ServerFail_Forbidden) {
MarkFirstRunAsComplete();
GetService()->GetCollections( GetService()->GetCollections(
CreateCredentials(), "123", "abcd", CreateCredentials(), "123", "abcd",
base::BindLambdaForTesting( base::BindLambdaForTesting(
...@@ -171,6 +184,8 @@ TEST_F(KaleidoscopeServiceTest, ServerFail_Forbidden) { ...@@ -171,6 +184,8 @@ TEST_F(KaleidoscopeServiceTest, ServerFail_Forbidden) {
} }
TEST_F(KaleidoscopeServiceTest, ServerFail) { TEST_F(KaleidoscopeServiceTest, ServerFail) {
MarkFirstRunAsComplete();
GetService()->GetCollections( GetService()->GetCollections(
CreateCredentials(), "123", "abcd", CreateCredentials(), "123", "abcd",
base::BindLambdaForTesting( base::BindLambdaForTesting(
...@@ -198,6 +213,8 @@ TEST_F(KaleidoscopeServiceTest, ServerFail) { ...@@ -198,6 +213,8 @@ TEST_F(KaleidoscopeServiceTest, ServerFail) {
} }
TEST_F(KaleidoscopeServiceTest, NetworkFail) { TEST_F(KaleidoscopeServiceTest, NetworkFail) {
MarkFirstRunAsComplete();
GetService()->GetCollections( GetService()->GetCollections(
CreateCredentials(), "123", "abcd", CreateCredentials(), "123", "abcd",
base::BindLambdaForTesting( base::BindLambdaForTesting(
...@@ -225,6 +242,8 @@ TEST_F(KaleidoscopeServiceTest, NetworkFail) { ...@@ -225,6 +242,8 @@ TEST_F(KaleidoscopeServiceTest, NetworkFail) {
} }
TEST_F(KaleidoscopeServiceTest, ForceCache) { TEST_F(KaleidoscopeServiceTest, ForceCache) {
MarkFirstRunAsComplete();
base::test::ScopedFeatureList feature_list; base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(media::kKaleidoscopeModuleCacheOnly); feature_list.InitAndEnableFeature(media::kKaleidoscopeModuleCacheOnly);
...@@ -277,4 +296,57 @@ TEST_F(KaleidoscopeServiceTest, ForceCache) { ...@@ -277,4 +296,57 @@ TEST_F(KaleidoscopeServiceTest, ForceCache) {
} }
} }
TEST_F(KaleidoscopeServiceTest, FirstRun) {
GetService()->GetCollections(
CreateCredentials(), "123", "abcd",
base::BindOnce([](media::mojom::GetCollectionsResponsePtr result) {
EXPECT_TRUE(result->response.empty());
EXPECT_EQ(media::mojom::GetCollectionsResult::kFirstRun,
result->result);
}));
WaitForRequest();
ASSERT_TRUE(RespondToFetch(kTestData));
// If we call again then we should hit the cache.
GetService()->GetCollections(
CreateCredentials(), "123", "abcd",
base::BindOnce([](media::mojom::GetCollectionsResponsePtr result) {
EXPECT_TRUE(result->response.empty());
EXPECT_EQ(media::mojom::GetCollectionsResult::kFirstRun,
result->result);
}));
// A request should not be created.
task_environment()->RunUntilIdle();
EXPECT_TRUE(url_loader_factory()->pending_requests()->empty());
}
TEST_F(KaleidoscopeServiceTest, FirstRunNotAvailable) {
GetService()->GetCollections(
CreateCredentials(), "123", "abcd",
base::BindOnce([](media::mojom::GetCollectionsResponsePtr result) {
EXPECT_TRUE(result->response.empty());
EXPECT_EQ(media::mojom::GetCollectionsResult::kNotAvailable,
result->result);
}));
WaitForRequest();
ASSERT_TRUE(RespondToFetch("", net::HTTP_FORBIDDEN));
// If we call again then we should hit the cache. HTTP Forbidden is special
// cased because this indicates the user cannot access Kaleidoscope.
GetService()->GetCollections(
CreateCredentials(), "123", "abcd",
base::BindOnce([](media::mojom::GetCollectionsResponsePtr result) {
EXPECT_TRUE(result->response.empty());
EXPECT_EQ(media::mojom::GetCollectionsResult::kNotAvailable,
result->result);
}));
// A request should not be created.
task_environment()->RunUntilIdle();
EXPECT_TRUE(url_loader_factory()->pending_requests()->empty());
}
} // namespace kaleidoscope } // namespace kaleidoscope
...@@ -102,6 +102,9 @@ enum GetCollectionsResult { ...@@ -102,6 +102,9 @@ enum GetCollectionsResult {
// Kaleidoscope is not available to the user. // Kaleidoscope is not available to the user.
kNotAvailable, kNotAvailable,
// The user needs to complete the first run experience.
kFirstRun,
}; };
struct GetCollectionsResponse { struct GetCollectionsResponse {
......
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