lock_screen_action_background_controller.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/lock_screen_action/lock_screen_action_background_controller.h"
  5. #include "ash/lock_screen_action/lock_screen_action_background_controller_impl.h"
  6. #include "ash/lock_screen_action/lock_screen_action_background_controller_stub.h"
  7. #include "ash/lock_screen_action/lock_screen_action_background_observer.h"
  8. #include "base/callback.h"
  9. namespace ash {
  10. namespace {
  11. LockScreenActionBackgroundController::FactoryCallback*
  12. g_testing_factory_callback = nullptr;
  13. } // namespace
  14. // static
  15. std::unique_ptr<LockScreenActionBackgroundController>
  16. LockScreenActionBackgroundController::Create() {
  17. if (g_testing_factory_callback)
  18. return g_testing_factory_callback->Run();
  19. return std::make_unique<LockScreenActionBackgroundControllerImpl>();
  20. }
  21. // static
  22. void LockScreenActionBackgroundController::SetFactoryCallbackForTesting(
  23. FactoryCallback* testing_factory_callback) {
  24. g_testing_factory_callback = testing_factory_callback;
  25. }
  26. LockScreenActionBackgroundController::LockScreenActionBackgroundController() =
  27. default;
  28. LockScreenActionBackgroundController::~LockScreenActionBackgroundController() {
  29. UpdateState(LockScreenActionBackgroundState::kHidden);
  30. }
  31. void LockScreenActionBackgroundController::SetParentWindow(
  32. aura::Window* parent_window) {
  33. DCHECK(!parent_window_);
  34. parent_window_ = parent_window;
  35. }
  36. void LockScreenActionBackgroundController::AddObserver(
  37. LockScreenActionBackgroundObserver* observer) {
  38. observers_.AddObserver(observer);
  39. }
  40. void LockScreenActionBackgroundController::RemoveObserver(
  41. LockScreenActionBackgroundObserver* observer) {
  42. observers_.RemoveObserver(observer);
  43. }
  44. void LockScreenActionBackgroundController::UpdateState(
  45. LockScreenActionBackgroundState state) {
  46. if (state_ == state)
  47. return;
  48. state_ = state;
  49. for (auto& observer : observers_)
  50. observer.OnLockScreenActionBackgroundStateChanged(state_);
  51. }
  52. } // namespace ash