[go: nahoru, domu]

blob: 65e48b3eb6c602253847e1b264b4f9ad8629d519 [file] [log] [blame]
Fahad Mansoordfde4c02023-03-16 13:01:241// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/ambient/ambient_managed_slideshow_ui_launcher.h"
6
Fahad Mansoorbb5651f2023-04-03 10:08:257#include <vector>
8
Fahad Mansoordfde4c02023-03-16 13:01:249#include "ash/ambient/ambient_managed_photo_controller.h"
10#include "ash/ambient/ambient_view_delegate_impl.h"
11#include "ash/ambient/model/ambient_slideshow_photo_config.h"
12#include "ash/ambient/ui/photo_view.h"
Fahad Mansoorbb5651f2023-04-03 10:08:2513#include "ash/public/cpp/ambient/ambient_managed_photo_source.h"
Fahad Mansoordfde4c02023-03-16 13:01:2414#include "base/check.h"
15#include "base/functional/callback.h"
Fahad Mansoorbb5651f2023-04-03 10:08:2516#include "base/logging.h"
17#include "base/memory/weak_ptr.h"
Fahad Mansoordfde4c02023-03-16 13:01:2418
19namespace ash {
20
21AmbientManagedSlideshowUiLauncher::AmbientManagedSlideshowUiLauncher(
22 AmbientViewDelegateImpl* view_delegate)
23 : photo_controller_(*view_delegate,
24 CreateAmbientManagedSlideshowPhotoConfig()),
25 delegate_(view_delegate) {
26 ambient_backend_model_observer_.Observe(
27 photo_controller_.ambient_backend_model());
Fahad Mansoorbb5651f2023-04-03 10:08:2528 CHECK(AmbientManagedPhotoSource::Get());
29 AmbientManagedPhotoSource::Get()->SetScreensaverImagesUpdatedCallback(
30 base::BindRepeating(
31 &AmbientManagedSlideshowUiLauncher::UpdateImageFilePaths,
32 weak_factory_.GetWeakPtr()));
Fahad Mansoordfde4c02023-03-16 13:01:2433}
34AmbientManagedSlideshowUiLauncher::~AmbientManagedSlideshowUiLauncher() =
35 default;
36
Fahad Mansoor013aa59d2023-04-06 12:16:0837void AmbientManagedSlideshowUiLauncher::Initialize(
38 InitializationCallback on_done) {
Fahad Mansoordfde4c02023-03-16 13:01:2439 initialization_callback_ = std::move(on_done);
Fahad Mansoorbb5651f2023-04-03 10:08:2540 if (!AmbientManagedPhotoSource::Get()) {
41 LOG(WARNING) << "AmbientManagedPhotoSource not present. Probably "
42 "AmbientManagedPhotoController screen update is being "
43 "started during a shutdown";
Fahad Mansoor013aa59d2023-04-06 12:16:0844 std::move(initialization_callback_).Run(/*success=*/false);
Fahad Mansoorbb5651f2023-04-03 10:08:2545 return;
46 }
47 photo_controller_.UpdateImageFilePaths(
48 AmbientManagedPhotoSource::Get()->GetScreensaverImages());
Fahad Mansoordfde4c02023-03-16 13:01:2449 photo_controller_.StartScreenUpdate();
50}
51
Fahad Mansoorbb5651f2023-04-03 10:08:2552void AmbientManagedSlideshowUiLauncher::UpdateImageFilePaths(
53 const std::vector<base::FilePath>& path_to_images) {
54 photo_controller_.UpdateImageFilePaths(path_to_images);
55}
56
Fahad Mansoordfde4c02023-03-16 13:01:2457std::unique_ptr<views::View> AmbientManagedSlideshowUiLauncher::CreateView() {
Fahad Mansoor258b5df2023-04-06 10:05:1958 return std::make_unique<PhotoView>(delegate_,
59 /*peripheral_ui_visible=*/false);
Fahad Mansoordfde4c02023-03-16 13:01:2460}
61
62void AmbientManagedSlideshowUiLauncher::Finalize() {
63 photo_controller_.StopScreenUpdate();
64}
65
66AmbientBackendModel*
67AmbientManagedSlideshowUiLauncher::GetAmbientBackendModel() {
68 return photo_controller_.ambient_backend_model();
69}
Fahad Mansoor258b5df2023-04-06 10:05:1970
Fahad Mansoordfde4c02023-03-16 13:01:2471void AmbientManagedSlideshowUiLauncher::OnImagesReady() {
72 CHECK(initialization_callback_);
Fahad Mansoor013aa59d2023-04-06 12:16:0873 std::move(initialization_callback_).Run(/*success=*/true);
Fahad Mansoordfde4c02023-03-16 13:01:2474}
75
76bool AmbientManagedSlideshowUiLauncher::IsActive() {
77 return photo_controller_.IsScreenUpdateActive();
78}
79
Fahad Mansoorbb5651f2023-04-03 10:08:2580} // namespace ash