blob: 8738a3303a1c639b2516ac3d10818834844c1307 [file] [log] [blame]
// Copyright 2017 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 <memory>
#include <string>
#include "base/macros.h"
#include "base/optional.h"
#include "chrome/browser/chromeos/login/screens/base_screen.h"
#include "chrome/browser/chromeos/login/screens/sync_consent_screen_view.h"
#include "components/sync/driver/sync_service_observer.h"
#include "components/user_manager/user.h"
class Profile;
namespace chromeos {
class BaseScreenDelegate;
// This is Sync settings screen that is displayed as a part of user first
// sign-in flow.
class SyncConsentScreen : public BaseScreen,
public syncer::SyncServiceObserver {
enum SyncScreenBehavior {
UNKNOWN, // Not yet known.
SHOW, // Screen should be shown.
SKIP // Skip screen for this user.
class SyncConsentScreenTestDelegate {
SyncConsentScreenTestDelegate() = default;
// This is called from SyncConsentScreen when user consent is passed to
// consent auditor with resource ids recorder as consent.
virtual void OnConsentRecordedIds(
const std::vector<int>& consent_description,
const int consent_confirmation) = 0;
// This is called from SyncConsentScreenHandler when user consent is passed
// to consent auditor with resource strings recorder as consent.
virtual void OnConsentRecordedStrings(
const ::login::StringList& consent_description,
const std::string& consent_confirmation) = 0;
// Launches the sync consent settings dialog if the user requested to review
// them after completing OOBE.
static void MaybeLaunchSyncConsentSettings(Profile* profile);
SyncConsentScreen(BaseScreenDelegate* base_screen_delegate,
SyncConsentScreenView* view);
~SyncConsentScreen() override;
// BaseScreen:
void Show() override;
void Hide() override;
void OnUserAction(const std::string& action_id) override;
// syncer::SyncServiceObserver:
void OnStateChanged(syncer::SyncService* sync) override;
// Reacts to "Continue and review settings after sign-in"
void OnContinueAndReview(const std::vector<int>& consent_description,
const int consent_confirmation);
// Reacts to "Continue with default settings"
void OnContinueWithDefaults(const std::vector<int>& consent_description,
const int consent_confirmation);
// Sets internal condition "Sync disabled by policy" for tests.
void SetProfileSyncDisabledByPolicyForTesting(bool value);
// Sets internal condition "Sync engine initialized" for tests.
void SetProfileSyncEngineInitializedForTesting(bool value);
// Test API.
void SetDelegateForTesting(
SyncConsentScreen::SyncConsentScreenTestDelegate* delegate);
SyncConsentScreenTestDelegate* GetDelegateForTesting() const;
// Returns new SyncScreenBehavior value.
SyncScreenBehavior GetSyncScreenBehavior() const;
// Calculates updated |behavior_| and performs required update actions.
void UpdateScreen();
// Records user Sync consent.
void RecordConsent(const std::vector<int>& consent_description,
const int consent_confirmation);
// Returns true if profile sync is disabled by policy.
bool IsProfileSyncDisabledByPolicy() const;
// Returns true if profile sync has finished initialization.
bool IsProfileSyncEngineInitialized() const;
// Controls screen appearance.
// Spinner is shown until sync status has been decided.
SyncScreenBehavior behavior_ = UNKNOWN;
SyncConsentScreenView* const view_;
// Primary user ind his Profile (if screen is shown).
const user_manager::User* user_ = nullptr;
Profile* profile_ = nullptr;
// True when screen is shown.
bool shown_ = false;
base::Optional<bool> test_sync_disabled_by_policy_;
base::Optional<bool> test_sync_engine_initialized_;
// Notify tests.
SyncConsentScreenTestDelegate* test_delegate_ = nullptr;
} // namespace chromeos