Commit 437ab657 authored by yilkal's avatar yilkal Committed by Commit Bot

Record accepted TOS version number in pref.

This cl records the accepted edu coexistence terms
of service version number in user pref. The stored pref
is a dictionary mapping the secondary edu account's gaia id to
the accepted terms of service version number.

Bug: 1134682
Change-Id: I73cf4872c6bddec0f7a92663b9a5cacb0a014567
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510874Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822873}
parent 0a34cf07
...@@ -99,6 +99,13 @@ void SecondaryAccountConsentLogger::RegisterPrefs( ...@@ -99,6 +99,13 @@ void SecondaryAccountConsentLogger::RegisterPrefs(
// ToS were accepted (OOBE or Settings flow). // ToS were accepted (OOBE or Settings flow).
registry->RegisterStringPref(chromeos::prefs::kEduCoexistenceToSVersion, registry->RegisterStringPref(chromeos::prefs::kEduCoexistenceToSVersion,
std::string()); std::string());
// |kEduCoexistenceToSAcceptedVersion| is a dictionary associating the
// edu accounts present in account manager to the accepted terms of service
// version.
registry->RegisterDictionaryPref(
chromeos::prefs::kEduCoexistenceToSAcceptedVersion,
base::Value(base::Value::Type::DICTIONARY));
} }
// static // static
......
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h" #include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/supervised_user/logged_in_user_mixin.h" #include "chrome/browser/supervised_user/logged_in_user_mixin.h"
#include "chrome/browser/supervised_user/supervised_user_features.h" #include "chrome/browser/supervised_user/supervised_user_features.h"
#include "chrome/browser/supervised_user/supervised_user_service.h" #include "chrome/browser/supervised_user/supervised_user_service.h"
...@@ -19,6 +22,8 @@ ...@@ -19,6 +22,8 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h" #include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chromeos/constants/chromeos_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/access_token_info.h" #include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -33,6 +38,16 @@ namespace { ...@@ -33,6 +38,16 @@ namespace {
constexpr char kResponseCallback[] = "cr.webUIResponse"; constexpr char kResponseCallback[] = "cr.webUIResponse";
std::string GetAcceptedTosVersionForAccount(const std::string& user_gaia_id) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
const base::Value* accepted_values =
prefs->Get(chromeos::prefs::kEduCoexistenceToSAcceptedVersion);
const std::string* entry = accepted_values->FindStringKey(user_gaia_id);
return entry ? *entry : std::string();
}
} // namespace } // namespace
class EduCoexistenceLoginHandlerBrowserTest class EduCoexistenceLoginHandlerBrowserTest
...@@ -126,14 +141,15 @@ IN_PROC_BROWSER_TEST_F(EduCoexistenceLoginHandlerBrowserTest, ...@@ -126,14 +141,15 @@ IN_PROC_BROWSER_TEST_F(EduCoexistenceLoginHandlerBrowserTest,
IN_PROC_BROWSER_TEST_F(EduCoexistenceLoginHandlerBrowserTest, IN_PROC_BROWSER_TEST_F(EduCoexistenceLoginHandlerBrowserTest,
HandleConsentLogged) { HandleConsentLogged) {
std::unique_ptr<EduCoexistenceLoginHandler> handler = SetUpHandler(); std::unique_ptr<EduCoexistenceLoginHandler> handler = SetUpHandler();
constexpr char consentLoggedCallback[] = "consent-logged-callback"; constexpr char kConsentLoggedCallback[] = "consent-logged-callback";
constexpr char kAcceptedTosVersion[] = "12345678";
base::ListValue call_args; base::ListValue call_args;
call_args.Append(FakeGaiaMixin::kFakeUserEmail); call_args.Append(FakeGaiaMixin::kFakeUserEmail);
call_args.Append("12345678"); call_args.Append(kAcceptedTosVersion);
base::ListValue list_args; base::ListValue list_args;
list_args.Append(consentLoggedCallback); list_args.Append(kConsentLoggedCallback);
list_args.Append(std::move(call_args)); list_args.Append(std::move(call_args));
web_ui()->HandleReceivedMessage("consentLogged", &list_args); web_ui()->HandleReceivedMessage("consentLogged", &list_args);
...@@ -150,13 +166,18 @@ IN_PROC_BROWSER_TEST_F(EduCoexistenceLoginHandlerBrowserTest, ...@@ -150,13 +166,18 @@ IN_PROC_BROWSER_TEST_F(EduCoexistenceLoginHandlerBrowserTest,
// Simulate account added. // Simulate account added.
CoreAccountInfo account; CoreAccountInfo account;
account.email = FakeGaiaMixin::kFakeUserEmail; account.email = FakeGaiaMixin::kFakeUserEmail;
account.gaia = FakeGaiaMixin::kFakeUserGaiaId;
handler->OnRefreshTokenUpdatedForAccount(account); handler->OnRefreshTokenUpdatedForAccount(account);
const std::string& accepted_tos =
GetAcceptedTosVersionForAccount(FakeGaiaMixin::kFakeUserGaiaId);
EXPECT_EQ(accepted_tos, std::string(kAcceptedTosVersion));
EXPECT_EQ(web_ui()->call_data().size(), 1u); EXPECT_EQ(web_ui()->call_data().size(), 1u);
const content::TestWebUI::CallData& second_call = *web_ui()->call_data()[0]; const content::TestWebUI::CallData& second_call = *web_ui()->call_data()[0];
// TODO(yilkal): verify the exact the call arguments. // TODO(yilkal): verify the exact the call arguments.
VerifyJavascriptCallResolved(second_call, consentLoggedCallback, VerifyJavascriptCallResolved(second_call, kConsentLoggedCallback,
kResponseCallback); kResponseCallback);
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "components/policy/core/common/cloud/cloud_policy_core.h" #include "components/policy/core/common/cloud/cloud_policy_core.h"
#include "components/policy/proto/device_management_backend.pb.h" #include "components/policy/proto/device_management_backend.pb.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/session_manager/core/session_manager.h" #include "components/session_manager/core/session_manager.h"
#include "components/signin/public/identity_manager/access_token_info.h" #include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
...@@ -113,6 +114,17 @@ std::string GetDeviceIdForActiveUserProfile() { ...@@ -113,6 +114,17 @@ std::string GetDeviceIdForActiveUserProfile() {
return policy->device_id(); return policy->device_id();
} }
void UpdateEduCoexistenceTokenForAccount(
Profile* profile,
const std::string& edu_account_gaia_id,
const std::string& terms_of_service_version_number) {
DictionaryPrefUpdate update(
profile->GetPrefs(), chromeos::prefs::kEduCoexistenceToSAcceptedVersion);
base::DictionaryValue* dict = update.Get();
dict->SetStringPath(edu_account_gaia_id, terms_of_service_version_number);
}
} // namespace } // namespace
EduCoexistenceLoginHandler::EduCoexistenceLoginHandler( EduCoexistenceLoginHandler::EduCoexistenceLoginHandler(
...@@ -188,7 +200,9 @@ void EduCoexistenceLoginHandler::OnRefreshTokenUpdatedForAccount( ...@@ -188,7 +200,9 @@ void EduCoexistenceLoginHandler::OnRefreshTokenUpdatedForAccount(
AllowJavascript(); AllowJavascript();
// TODO(yilkal): Record |terms_of_service_version_number_| in user preference. Profile* profile = ProfileManager::GetActiveUserProfile();
UpdateEduCoexistenceTokenForAccount(profile, account_info.gaia,
terms_of_service_version_number_);
// Otherwise, notify the ui that account addition was successful!! // Otherwise, notify the ui that account addition was successful!!
ResolveJavascriptCallback(base::Value(account_added_callback_), ResolveJavascriptCallback(base::Value(account_added_callback_),
......
...@@ -73,6 +73,12 @@ const char kEduCoexistenceSecondaryAccountsInvalidationVersion[] = ...@@ -73,6 +73,12 @@ const char kEduCoexistenceSecondaryAccountsInvalidationVersion[] =
const char kEduCoexistenceToSVersion[] = const char kEduCoexistenceToSVersion[] =
"family_link_user.edu_coexistence_tos_version"; "family_link_user.edu_coexistence_tos_version";
// A dictionary pref that associates the secondary edu accounts gaia id string
// with the corresponding accepted Edu Coexistence Terms of Service version
// number.
const char kEduCoexistenceToSAcceptedVersion[] =
"family_link_user.edu_coexistence_tos_accepted_version";
// A dictionary of info for Quirks Client/Server interaction, mostly last server // A dictionary of info for Quirks Client/Server interaction, mostly last server
// request times, keyed to display product_id's. // request times, keyed to display product_id's.
const char kQuirksClientLastServerCheck[] = "quirks_client.last_server_check"; const char kQuirksClientLastServerCheck[] = "quirks_client.last_server_check";
......
...@@ -33,6 +33,8 @@ extern const char kEduCoexistenceSecondaryAccountsInvalidationVersion[]; ...@@ -33,6 +33,8 @@ extern const char kEduCoexistenceSecondaryAccountsInvalidationVersion[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kEduCoexistenceToSVersion[]; extern const char kEduCoexistenceToSVersion[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kEduCoexistenceToSAcceptedVersion[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kQuirksClientLastServerCheck[]; extern const char kQuirksClientLastServerCheck[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kDeviceWiFiFastTransitionEnabled[]; extern const char kDeviceWiFiFastTransitionEnabled[];
......
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