Commit 1bab11fe authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Chrome OS: Implement bindings for Sync settings screen.


Bug: 794371
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ie2eced66d7d36dea4fdff07262bf808ab0f60cb5
Reviewed-on: https://chromium-review.googlesource.com/885642
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531928}
parent c36931f5
...@@ -7,12 +7,22 @@ ...@@ -7,12 +7,22 @@
#include <string> #include <string>
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/user_manager/user_manager.h"
namespace chromeos { namespace chromeos {
namespace { namespace {
constexpr const char kUserActionButtonClicked[] = "save-and-continue"; constexpr const char kUserActionButtonClicked[] = "save-and-continue";
browser_sync::ProfileSyncService* GetSyncService(Profile* profile) {
if (ProfileSyncServiceFactory::HasProfileSyncService(profile))
return ProfileSyncServiceFactory::GetForProfile(profile);
return nullptr;
}
} // namespace } // namespace
SyncConsentScreen::SyncConsentScreen(BaseScreenDelegate* base_screen_delegate, SyncConsentScreen::SyncConsentScreen(BaseScreenDelegate* base_screen_delegate,
...@@ -28,6 +38,13 @@ SyncConsentScreen::~SyncConsentScreen() { ...@@ -28,6 +38,13 @@ SyncConsentScreen::~SyncConsentScreen() {
} }
void SyncConsentScreen::Show() { void SyncConsentScreen::Show() {
const user_manager::User* user =
user_manager::UserManager::Get()->GetPrimaryUser();
profile_ = ProfileHelper::Get()->GetProfileByUser(user);
// Populate initial value.
view_->OnUserPrefKnown(true, GetSyncService(profile_)->IsManaged());
// Show the screen. // Show the screen.
view_->Show(); view_->Show();
} }
...@@ -44,4 +61,14 @@ void SyncConsentScreen::OnUserAction(const std::string& action_id) { ...@@ -44,4 +61,14 @@ void SyncConsentScreen::OnUserAction(const std::string& action_id) {
BaseScreen::OnUserAction(action_id); BaseScreen::OnUserAction(action_id);
} }
void SyncConsentScreen::SetSyncAllValue(bool sync_all) {
browser_sync::ProfileSyncService* service = GetSyncService(profile_);
if (!service->IsManaged()) {
// When |sync_all| is true, second parameter is ignored.
// When it's false, second set defines individual data types to be synced.
// We want none, so empty set does what we need.
service->OnUserChoseDatatypes(sync_all, syncer::ModelTypeSet());
}
}
} // namespace chromeos } // namespace chromeos
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SYNC_CONSENT_SCREEN_H_ #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SYNC_CONSENT_SCREEN_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SYNC_CONSENT_SCREEN_H_ #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SYNC_CONSENT_SCREEN_H_
#include <memory>
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/login/screens/base_screen.h" #include "chrome/browser/chromeos/login/screens/base_screen.h"
#include "chrome/browser/chromeos/login/screens/sync_consent_screen_view.h" #include "chrome/browser/chromeos/login/screens/sync_consent_screen_view.h"
class Profile;
namespace chromeos { namespace chromeos {
class BaseScreenDelegate; class BaseScreenDelegate;
...@@ -28,9 +31,15 @@ class SyncConsentScreen : public BaseScreen { ...@@ -28,9 +31,15 @@ class SyncConsentScreen : public BaseScreen {
void Hide() override; void Hide() override;
void OnUserAction(const std::string& action_id) override; void OnUserAction(const std::string& action_id) override;
// Modifies user sync preference on user action.
void SetSyncAllValue(bool sync_all);
private: private:
SyncConsentScreenView* const view_; SyncConsentScreenView* const view_;
// Profile of the primary user (if screen is shown).
Profile* profile_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(SyncConsentScreen); DISALLOW_COPY_AND_ASSIGN(SyncConsentScreen);
}; };
......
...@@ -27,6 +27,9 @@ class SyncConsentScreenView { ...@@ -27,6 +27,9 @@ class SyncConsentScreenView {
// Hides the contents of the screen. // Hides the contents of the screen.
virtual void Hide() = 0; virtual void Hide() = 0;
// Updates view state after user sync preferences are known.
virtual void OnUserPrefKnown(bool sync_everything, bool is_managed) = 0;
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -582,6 +582,16 @@ void WizardController::ShowTermsOfServiceScreen() { ...@@ -582,6 +582,16 @@ void WizardController::ShowTermsOfServiceScreen() {
} }
void WizardController::ShowSyncConsentScreen() { void WizardController::ShowSyncConsentScreen() {
const user_manager::UserManager* user_manager =
user_manager::UserManager::Get();
// Skip for non-regular users.
if (user_manager->IsLoggedInAsPublicAccount() ||
(user_manager->IsCurrentUserNonCryptohomeDataEphemeral() &&
user_manager->GetActiveUser()->GetType() !=
user_manager::USER_TYPE_REGULAR)) {
ShowArcTermsOfServiceScreen();
return;
}
VLOG(1) << "Showing Sync Consent screen."; VLOG(1) << "Showing Sync Consent screen.";
UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_SYNC_CONSENT); UpdateStatusAreaVisibilityForScreen(OobeScreen::SCREEN_SYNC_CONSENT);
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_SYNC_CONSENT)); SetCurrentScreen(GetScreen(OobeScreen::SCREEN_SYNC_CONSENT));
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
login.createScreen('SyncConsentScreen', 'sync-consent', function() { login.createScreen('SyncConsentScreen', 'sync-consent', function() {
return { return {
EXTERNAL_API: ['onUserSyncPrefsKnown'],
/** /**
* Returns the control which should receive initial focus. * Returns the control which should receive initial focus.
*/ */
...@@ -21,6 +23,15 @@ login.createScreen('SyncConsentScreen', 'sync-consent', function() { ...@@ -21,6 +23,15 @@ login.createScreen('SyncConsentScreen', 'sync-consent', function() {
*/ */
onBeforeShow: function(data) { onBeforeShow: function(data) {
Oobe.getInstance().headerHidden = true; Oobe.getInstance().headerHidden = true;
} },
/**
* This is called once user sync preferences are known.
* @param {boolean} sync_everything Whether sync_everything is enabled.
* @param {boolean} is_managed Whether sync preferences are managed.
*/
onUserSyncPrefsKnown: function(sync_everything, is_managed) {
$('sync-consent-impl').onUserSyncPrefsKnown(sync_everything, is_managed);
},
}; };
}); });
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
</div> </div>
<div class="bottom-buttons layout horizontal end-justified"> <div class="bottom-buttons layout horizontal end-justified">
<oobe-next-button on-tap="onSettingsSaveAndContinue_" <oobe-next-button on-tap="onSettingsSaveAndContinue_"
class="focus-on-show"> disabled="[[!userPrefsKnown_]]" class="focus-on-show">
</oobe-next-button> </oobe-next-button>
</div> </div>
</oobe-dialog> </oobe-dialog>
...@@ -108,6 +108,7 @@ ...@@ -108,6 +108,7 @@
<oobe-a11y-option checked="[[syncAllEnabled_]]" <oobe-a11y-option checked="[[syncAllEnabled_]]"
on-change="onSyncAllEnabledChanged_" on-change="onSyncAllEnabledChanged_"
label-for-aria="[[i18nDynamic(locale, 'syncConsentSyncAllOptionTitle')]]" label-for-aria="[[i18nDynamic(locale, 'syncConsentSyncAllOptionTitle')]]"
disabled="[[isManaged_]]"
class="focus-on-show"> class="focus-on-show">
<span class="title"> <span class="title">
[[i18nDynamic(locale, 'syncConsentSyncAllOptionTitle')]] [[i18nDynamic(locale, 'syncConsentSyncAllOptionTitle')]]
...@@ -127,7 +128,8 @@ ...@@ -127,7 +128,8 @@
</div> </div>
</div> </div>
<div class="bottom-buttons layout horizontal end-justified"> <div class="bottom-buttons layout horizontal end-justified">
<oobe-text-button inverse on-tap="onSettingsSaveAndContinue_"> <oobe-text-button inverse on-tap="onSettingsSaveAndContinue_"
disabled="[[!userPrefsKnown_]]">
<div> <div>
[[i18nDynamic(locale, 'syncConsentSettingsSaveAndContinue')]] [[i18nDynamic(locale, 'syncConsentSettingsSaveAndContinue')]]
</div> </div>
......
...@@ -21,6 +21,22 @@ Polymer({ ...@@ -21,6 +21,22 @@ Polymer({
value: true, value: true,
}, },
/**
* False until user sync prefs are known.
*/
userPrefsKnown_: {
type: Boolean,
value: false,
},
/**
* True when sync preferences are managed.
*/
isManaged_: {
type: Boolean,
value: true,
},
/** /**
* Name of currently active section. * Name of currently active section.
*/ */
...@@ -70,7 +86,11 @@ Polymer({ ...@@ -70,7 +86,11 @@ Polymer({
* @private * @private
*/ */
onSyncAllEnabledChanged_: function(event) { onSyncAllEnabledChanged_: function(event) {
if (this.syncAllEnabled_ == event.currentTarget.checked)
return;
this.syncAllEnabled_ = event.currentTarget.checked; this.syncAllEnabled_ = event.currentTarget.checked;
chrome.send('syncEverythingChanged', [this.syncAllEnabled_]);
}, },
/** /**
...@@ -80,4 +100,15 @@ Polymer({ ...@@ -80,4 +100,15 @@ Polymer({
onSettingsSaveAndContinue_: function() { onSettingsSaveAndContinue_: function() {
chrome.send('login.SyncConsentScreen.userActed', ['save-and-continue']); chrome.send('login.SyncConsentScreen.userActed', ['save-and-continue']);
}, },
/**
* Modify UI state to match given user preferences.
* @param {boolean} sync_all_enabled Whether "sync everything" is enabled.
* @param {boolean} is_managed Whether sync preferences are managed.
*/
onUserSyncPrefsKnown: function(sync_all_enabled, is_managed) {
this.isManaged_ = is_managed;
this.syncAllEnabled_ = sync_all_enabled;
this.userPrefsKnown_ = true;
},
}); });
...@@ -55,7 +55,15 @@ void SyncConsentScreenHandler::DeclareLocalizedValues( ...@@ -55,7 +55,15 @@ void SyncConsentScreenHandler::DeclareLocalizedValues(
IDS_LOGIN_SYNC_CONSENT_SAVE_AND_CONTINUE); IDS_LOGIN_SYNC_CONSENT_SAVE_AND_CONTINUE);
} }
void SyncConsentScreenHandler::RegisterMessages() {
BaseScreenHandler::RegisterMessages();
AddCallback("syncEverythingChanged",
&SyncConsentScreenHandler::HandleSyncEverythingChanged);
}
void SyncConsentScreenHandler::Bind(SyncConsentScreen* screen) { void SyncConsentScreenHandler::Bind(SyncConsentScreen* screen) {
screen_ = screen;
BaseScreenHandler::SetBaseScreen(screen); BaseScreenHandler::SetBaseScreen(screen);
} }
...@@ -67,4 +75,14 @@ void SyncConsentScreenHandler::Hide() {} ...@@ -67,4 +75,14 @@ void SyncConsentScreenHandler::Hide() {}
void SyncConsentScreenHandler::Initialize() {} void SyncConsentScreenHandler::Initialize() {}
void SyncConsentScreenHandler::HandleSyncEverythingChanged(
bool sync_everything) {
screen_->SetSyncAllValue(sync_everything);
}
void SyncConsentScreenHandler::OnUserPrefKnown(bool sync_everything,
bool is_managed) {
CallJS("onUserSyncPrefsKnown", sync_everything, is_managed);
}
} // namespace chromeos } // namespace chromeos
...@@ -24,15 +24,23 @@ class SyncConsentScreenHandler : public BaseScreenHandler, ...@@ -24,15 +24,23 @@ class SyncConsentScreenHandler : public BaseScreenHandler,
void DeclareLocalizedValues( void DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) override; ::login::LocalizedValuesBuilder* builder) override;
// WebUIMessageHandler:
void RegisterMessages() override;
// SyncConsentScreenView: // SyncConsentScreenView:
void Bind(SyncConsentScreen* screen) override; void Bind(SyncConsentScreen* screen) override;
void Show() override; void Show() override;
void Hide() override; void Hide() override;
void OnUserPrefKnown(bool sync_everything, bool is_managed) override;
private: private:
// BaseScreenHandler: // BaseScreenHandler:
void Initialize() override; void Initialize() override;
// WebUI message handlers:
void HandleSyncEverythingChanged(bool sync_everything);
SyncConsentScreen* screen_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(SyncConsentScreenHandler); DISALLOW_COPY_AND_ASSIGN(SyncConsentScreenHandler);
}; };
......
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