1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117

ash / assistant / assistant_ui_controller_impl.h [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_IMPL_H_
#define ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_IMPL_H_

#include <optional>

#include "ash/ash_export.h"
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/public/cpp/assistant/controller/assistant_controller.h"
#include "ash/public/cpp/assistant/controller/assistant_controller_observer.h"
#include "ash/public/cpp/assistant/controller/assistant_ui_controller.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_observer.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"

class PrefRegistrySimple;

namespace chromeos {
namespace assistant {
namespace mojom {
class Assistant;
}  // namespace mojom
}  // namespace assistant
}  // namespace chromeos

namespace ash {

class AssistantControllerImpl;

class ASH_EXPORT AssistantUiControllerImpl
    : public AssistantUiController,
      public AssistantControllerObserver,
      public AssistantInteractionModelObserver,
      public AssistantUiModelObserver,
      public AssistantViewDelegateObserver,
      public OverviewObserver {
 public:
  explicit AssistantUiControllerImpl(
      AssistantControllerImpl* assistant_controller);

  AssistantUiControllerImpl(const AssistantUiControllerImpl&) = delete;
  AssistantUiControllerImpl& operator=(const AssistantUiControllerImpl&) =
      delete;

  ~AssistantUiControllerImpl() override;

  static void RegisterProfilePrefs(PrefRegistrySimple* registry);

  // Provides a pointer to the |assistant| owned by AssistantService.
  void SetAssistant(assistant::Assistant* assistant);

  // AssistantUiController:
  const AssistantUiModel* GetModel() const override;
  int GetNumberOfSessionsWhereOnboardingShown() const override;
  bool HasShownOnboarding() const override;
  void SetKeyboardTraversalMode(bool keyboard_traversal_mode) override;
  void ShowUi(AssistantEntryPoint entry_point) override;
  void ToggleUi(std::optional<AssistantEntryPoint> entry_point,
                std::optional<AssistantExitPoint> exit_point) override;
  std::optional<base::ScopedClosureRunner> CloseUi(
      AssistantExitPoint exit_point) override;
  void SetAppListBubbleWidth(int width) override;

  // AssistantInteractionModelObserver:
  void OnInteractionStateChanged(InteractionState interaction_state) override;

  // AssistantControllerObserver:
  void OnAssistantControllerConstructed() override;
  void OnAssistantControllerDestroying() override;
  void OnOpeningUrl(const GURL& url,
                    bool in_background,
                    bool from_server) override;

  // AssistantUiModelObserver:
  void OnUiVisibilityChanged(
      AssistantVisibility new_visibility,
      AssistantVisibility old_visibility,
      std::optional<AssistantEntryPoint> entry_point,
      std::optional<AssistantExitPoint> exit_point) override;

  // AssistantViewDelegateObserver:
  void OnOnboardingShown() override;

  // OverviewObserver:
  void OnOverviewModeWillStart() override;

  void ShowUnboundErrorToast();

 private:
  const raw_ptr<AssistantControllerImpl>
      assistant_controller_;  // Owned by Shell.
  AssistantUiModel model_;
  bool has_shown_onboarding_ = false;

  // Owned by AssistantService.
  raw_ptr<assistant::Assistant> assistant_ = nullptr;

  base::ScopedObservation<AssistantController, AssistantControllerObserver>
      assistant_controller_observation_{this};

  base::ScopedObservation<OverviewController, OverviewObserver>
      overview_controller_observation_{this};

  base::WeakPtrFactory<AssistantUiControllerImpl>
      weak_factory_for_delayed_visibility_changes_{this};
};

}  // namespace ash

#endif  // ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_IMPL_H_