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
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152

ash / birch / stub_birch_client.cc [blame]

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

#include "ash/birch/stub_birch_client.h"

#include "ash/birch/birch_data_provider.h"
#include "ash/birch/birch_model.h"
#include "ash/constants/ash_features.h"
#include "ash/shell.h"
#include "ui/base/models/image_model.h"

namespace ash {

//------------------------------------------------------------------------------
// StubBirchClient::StubDataProvider
StubBirchClient::StubDataProvider::StubDataProvider() = default;

StubBirchClient::StubDataProvider::~StubDataProvider() = default;

void StubBirchClient::StubDataProvider::RunDataProviderChangedCallback() {
  NotifyDataProviderChanged();
}

void StubBirchClient::StubDataProvider::RequestBirchDataFetch() {
  did_request_birch_data_fetch_ = true;
}

//------------------------------------------------------------------------------
// StubBirchClient:
StubBirchClient::StubBirchClient()
    : calendar_provider_(std::make_unique<StubDataProvider>()),
      file_suggest_provider_(std::make_unique<StubDataProvider>()),
      recent_tabs_provider_(std::make_unique<StubDataProvider>()),
      last_active_provider_(std::make_unique<StubDataProvider>()),
      most_visited_provider_(std::make_unique<StubDataProvider>()),
      self_share_provider_(std::make_unique<StubDataProvider>()),
      lost_media_provider_(std::make_unique<StubDataProvider>()),
      release_notes_provider_(std::make_unique<StubDataProvider>()) {
  CHECK(test_dir_.CreateUniqueTempDir());
}

StubBirchClient::~StubBirchClient() = default;

StubBirchClient::StubDataProvider*
StubBirchClient::InstallStubWeatherDataProvider() {
  auto weather_provider = std::make_unique<StubDataProvider>();
  auto* weather_provider_ptr = weather_provider.get();
  Shell::Get()->birch_model()->OverrideWeatherProviderForTest(
      std::move(weather_provider));
  return weather_provider_ptr;
}

StubBirchClient::StubDataProvider*
StubBirchClient::InstallStubCoralDataProvider() {
  auto coral_provider = std::make_unique<StubDataProvider>();
  auto* coral_provider_ptr = coral_provider.get();
  Shell::Get()->birch_model()->OverrideCoralProviderForTest(
      std::move(coral_provider));
  return coral_provider_ptr;
}

bool StubBirchClient::DidRequestCalendarDataFetch() const {
  return calendar_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestFileSuggestDataFetch() const {
  return file_suggest_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestRecentTabsDataFetch() const {
  return recent_tabs_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestLastActiveDataFetch() const {
  return last_active_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestMostVisitedDataFetch() const {
  return most_visited_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestSelfShareDataFetch() const {
  return self_share_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestLostMediaDataFetch() const {
  return lost_media_provider_->did_request_birch_data_fetch();
}

bool StubBirchClient::DidRequestReleaseNotesDataFetch() const {
  return release_notes_provider_->did_request_birch_data_fetch();
}

BirchDataProvider* StubBirchClient::GetCalendarProvider() {
  return calendar_provider_.get();
}

BirchDataProvider* StubBirchClient::GetFileSuggestProvider() {
  return file_suggest_provider_.get();
}

BirchDataProvider* StubBirchClient::GetRecentTabsProvider() {
  return recent_tabs_provider_.get();
}

BirchDataProvider* StubBirchClient::GetLastActiveProvider() {
  return last_active_provider_.get();
}

BirchDataProvider* StubBirchClient::GetMostVisitedProvider() {
  return most_visited_provider_.get();
}

BirchDataProvider* StubBirchClient::GetSelfShareProvider() {
  return self_share_provider_.get();
}

BirchDataProvider* StubBirchClient::GetLostMediaProvider() {
  return lost_media_provider_.get();
}

BirchDataProvider* StubBirchClient::GetReleaseNotesProvider() {
  return release_notes_provider_.get();
}

void StubBirchClient::WaitForRefreshTokens(base::OnceClosure callback) {
  did_wait_for_refresh_tokens_ = true;
  std::move(callback).Run();
}

base::FilePath StubBirchClient::GetRemovedItemsFilePath() {
  return test_dir_.GetPath();
}

void StubBirchClient::RemoveFileItemFromLauncher(const base::FilePath& path) {
  last_removed_path_ = path;
}

void StubBirchClient::GetFaviconImage(
    const GURL& url,
    const bool is_page_url,
    base::OnceCallback<void(const ui::ImageModel&)> callback) {
  did_get_favicon_image_ = true;
  std::move(callback).Run(ui::ImageModel());
}

ui::ImageModel StubBirchClient::GetChromeBackupIcon() {
  return ui::ImageModel();
}

}  // namespace ash