blob: 3568cd14886ff9b7c85f1361e55df930c04a6fcf [file] [log] [blame]
// Copyright 2018 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 "base/macros.h"
#include "base/values.h"
#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
#include "components/prefs/pref_service.h"
namespace chromeos {
class RecommendAppsScreen;
class RecommendAppsScreenViewObserver;
// Interface for dependency injection between RecommendAppsScreen and its
// WebUI representation.
class RecommendAppsScreenView {
constexpr static OobeScreen kScreenId = OobeScreen::SCREEN_RECOMMEND_APPS;
virtual ~RecommendAppsScreenView() = default;
// Adds/Removes observer for view.
virtual void AddObserver(RecommendAppsScreenViewObserver* observer) = 0;
virtual void RemoveObserver(RecommendAppsScreenViewObserver* observer) = 0;
// Sets screen this view belongs to.
virtual void Bind(RecommendAppsScreen* screen) = 0;
// Shows the contents of the screen.
virtual void Show() = 0;
// Hides the contents of the screen.
virtual void Hide() = 0;
// Called when the download of the recommend app list fails. Show an error
// message to the user.
virtual void OnLoadError() = 0;
// Called when the download of the recommend app list is successful. Shows the
// downloaded |app_list| to the user.
virtual void OnLoadSuccess(const base::Value& app_list) = 0;
// Called when parsing the recommend app list response fails. Should skip this
// screen.
virtual void OnParseResponseError() = 0;
// The sole implementation of the RecommendAppsScreenView, using WebUI.
class RecommendAppsScreenHandler : public BaseScreenHandler,
public RecommendAppsScreenView {
explicit RecommendAppsScreenHandler(JSCallsContainer* js_calls_container);
~RecommendAppsScreenHandler() override;
// BaseScreenHandler:
void DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) override;
void RegisterMessages() override;
// RecommendAppsScreenView:
void AddObserver(RecommendAppsScreenViewObserver* observer) override;
void RemoveObserver(RecommendAppsScreenViewObserver* observer) override;
void Bind(RecommendAppsScreen* screen) override;
void Show() override;
void Hide() override;
// BaseScreenHandler:
void Initialize() override;
// RecommendAppsScreenView:
void OnLoadError() override;
void OnLoadSuccess(const base::Value& app_list) override;
void OnParseResponseError() override;
void OnUserSkip();
// Call the JS function to load the list of apps in the WebView.
void LoadAppListInUI(const base::Value& app_list);
void HandleSkip();
void HandleRetry();
void HandleInstall(const base::ListValue* args);
RecommendAppsScreen* screen_ = nullptr;
PrefService* pref_service_;
base::ObserverList<RecommendAppsScreenViewObserver, true>::Unchecked
int recommended_app_count_ = 0;
} // namespace chromeos