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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_WALLPAPER_WALLPAPER_CONTROLLER_CLIENT_IMPL_H_
#define CHROME_BROWSER_UI_ASH_WALLPAPER_WALLPAPER_CONTROLLER_CLIENT_IMPL_H_
#include <memory>
#include "ash/public/cpp/wallpaper/online_wallpaper_params.h"
#include "ash/public/cpp/wallpaper/wallpaper_controller.h"
#include "ash/public/cpp/wallpaper/wallpaper_controller_client.h"
#include "ash/public/cpp/wallpaper/wallpaper_types.h"
#include "ash/webui/personalization_app/mojom/personalization_app.mojom-forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/scoped_multi_source_observation.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ash/file_manager/volume_manager_observer.h"
#include "chrome/browser/ash/wallpaper_handlers/wallpaper_handlers.h"
#include "chromeos/ash/components/settings/cros_settings.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "components/user_manager/user_manager.h"
class AccountId;
namespace {
class WallpaperControllerClientImplTest;
}
namespace content {
class WebContents;
} // namespace content
namespace wallpaper_handlers {
class WallpaperFetcherDelegate;
} // namespace wallpaper_handlers
// Handles chrome-side wallpaper control alongside the ash-side controller.
class WallpaperControllerClientImpl
: public ash::WallpaperControllerClient,
public file_manager::VolumeManagerObserver,
public session_manager::SessionManagerObserver,
public user_manager::UserManager::Observer {
public:
WallpaperControllerClientImpl(
PrefService& local_state,
std::unique_ptr<wallpaper_handlers::WallpaperFetcherDelegate>
wallpaper_fetcher_delegate);
WallpaperControllerClientImpl(const WallpaperControllerClientImpl&) = delete;
WallpaperControllerClientImpl& operator=(
const WallpaperControllerClientImpl&) = delete;
~WallpaperControllerClientImpl() override;
// Initializes and connects to ash.
void Init();
// Tests can provide a mock interface for the ash controller.
void InitForTesting(ash::WallpaperController* controller);
void SetWallpaperFetcherDelegateForTesting(
std::unique_ptr<wallpaper_handlers::WallpaperFetcherDelegate>);
// Sets the initial wallpaper. Should be called after the session manager has
// been initialized.
void SetInitialWallpaper();
static WallpaperControllerClientImpl* Get();
// ash::WallpaperControllerClient:
void OpenWallpaperPicker() override;
void FetchDailyRefreshWallpaper(
const std::string& collection_id,
DailyWallpaperUrlFetchedCallback callback) override;
void FetchImagesForCollection(
const std::string& collection_id,
FetchImagesForCollectionCallback callback) override;
void FetchGooglePhotosPhoto(const AccountId& account_id,
const std::string& id,
FetchGooglePhotosPhotoCallback callback) override;
void FetchDailyGooglePhotosPhoto(
const AccountId& account_id,
const std::string& album_id,
FetchGooglePhotosPhotoCallback callback) override;
void FetchGooglePhotosAccessToken(
const AccountId& account_id,
FetchGooglePhotosAccessTokenCallback callback) override;
void GetFilesId(const AccountId& account_id,
base::OnceCallback<void(const std::string&)>
files_id_callback) const override;
bool IsWallpaperSyncEnabled(const AccountId& account_id) const override;
void CancelPreviewWallpaper(Profile* profile);
void ConfirmPreviewWallpaper(Profile* profile);
void MakeOpaque(content::WebContents* web_contents);
void MakeTransparent(content::WebContents* web_contents);
// file_manager::VolumeManagerObserver:
void OnVolumeMounted(ash::MountError error_code,
const file_manager::Volume& volume) override;
// session_manager::SessionManagerObserver implementation.
void OnUserProfileLoaded(const AccountId& account_id) override;
// user_manager::UserManager::Observer:
void OnUserLoggedIn(const user_manager::User& user) override;
// Wrappers around the ash::WallpaperController interface.
void SetPolicyWallpaper(const AccountId& account_id,
std::unique_ptr<std::string> data);
bool SetThirdPartyWallpaper(const AccountId& account_id,
const std::string& file_name,
ash::WallpaperLayout layout,
const gfx::ImageSkia& image);
void ShowUserWallpaper(const AccountId& account_id);
void RemoveUserWallpaper(const AccountId& account_id,
base::OnceClosure on_removed);
void RemovePolicyWallpaper(const AccountId& account_id);
// Record Ash.Wallpaper.Source metric when a new wallpaper is set,
// either by built-in Wallpaper app or a third party extension/app.
void RecordWallpaperSourceUMA(const ash::WallpaperType type);
private:
friend class WallpaperControllerClientImplTest;
// Initialize the controller for this client and some wallpaper directories.
void InitController();
// Shows the wallpaper of the first user in |UserManager::GetUsers|, or a
// default signin wallpaper if there's no user. This ensures the wallpaper is
// shown right after boot, regardless of when the login screen is available.
void ShowWallpaperOnLoginScreen();
void DeviceWallpaperImageFilePathChanged();
// Returns true if user names should be shown on the login screen.
bool ShouldShowUserNamesOnLogin() const;
base::FilePath GetDeviceWallpaperImageFilePath();
void OnDailyImageInfoFetched(DailyWallpaperUrlFetchedCallback callback,
bool success,
const backdrop::Image& image,
const std::string& next_resume_token);
void OnFetchImagesForCollection(
FetchImagesForCollectionCallback callback,
std::unique_ptr<wallpaper_handlers::BackdropImageInfoFetcher> fetcher,
bool success,
const std::string& collection_id,
const std::vector<backdrop::Image>& images);
void OnGooglePhotosPhotoFetched(
FetchGooglePhotosPhotoCallback callback,
ash::personalization_app::mojom::FetchGooglePhotosPhotosResponsePtr
response);
void OnGooglePhotosDailyAlbumFetched(
const AccountId& account_id,
FetchGooglePhotosPhotoCallback callback,
ash::personalization_app::mojom::FetchGooglePhotosPhotosResponsePtr
response);
void ObserveVolumeManagerForAccountId(const AccountId& account_id);
// WallpaperController interface in ash.
raw_ptr<ash::WallpaperController> wallpaper_controller_;
raw_ref<PrefService> local_state_;
// The registrar used to watch DeviceWallpaperImageFilePath pref changes.
PrefChangeRegistrar pref_registrar_;
// Subscription for a callback that monitors if user names should be shown on
// the login screen, which determines whether a user wallpaper or a default
// wallpaper should be shown.
base::CallbackListSubscription show_user_names_on_signin_subscription_;
std::map<std::string,
std::unique_ptr<wallpaper_handlers::BackdropSurpriseMeImageFetcher>>
surprise_me_image_fetchers_;
std::map<AccountId,
std::unique_ptr<wallpaper_handlers::GooglePhotosPhotosFetcher>>
google_photos_photos_fetchers_;
std::unique_ptr<wallpaper_handlers::WallpaperFetcherDelegate>
wallpaper_fetcher_delegate_;
base::ScopedMultiSourceObservation<file_manager::VolumeManager,
file_manager::VolumeManagerObserver>
volume_manager_observation_{this};
base::ScopedObservation<session_manager::SessionManager,
session_manager::SessionManagerObserver>
session_observation_{this};
base::ScopedObservation<user_manager::UserManager,
user_manager::UserManager::Observer>
user_manager_observation_{this};
base::WeakPtrFactory<WallpaperControllerClientImpl> weak_factory_{this};
};
#endif // CHROME_BROWSER_UI_ASH_WALLPAPER_WALLPAPER_CONTROLLER_CLIENT_IMPL_H_
|