Chromium Code Reviews| Index: chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
| diff --git a/chrome/browser/chromeos/lock_screen_apps/state_controller.cc b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e645ad998bcf438abcb1772019051fdaeb8582bd |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/command_line.h" |
| +#include "base/location.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "base/time/time.h" |
| +#include "chromeos/chromeos_switches.h" |
| + |
| +namespace lock_screen_apps { |
| + |
| +namespace { |
| + |
| +base::LazyInstance<StateController>::Leaky g_instance = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +// static |
| +StateController* StateController::Get() { |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + chromeos::switches::kEnableLockScreenApps)) { |
| + return nullptr; |
| + } |
| + return g_instance.Pointer(); |
| +} |
| + |
| +void StateController::AddObserver(StateObserver* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void StateController::RemoveObserver(StateObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +ActionState StateController::GetActionState(Action action) const { |
| + DCHECK_EQ(Action::kNewNote, action); |
| + return new_note_state_; |
| +} |
| + |
| +void StateController::HandleAction(Action action) { |
| + DCHECK_EQ(Action::kNewNote, action); |
| + |
| + if (new_note_state_ != ActionState::kAvailable && |
| + new_note_state_ != ActionState::kHidden) { |
| + return; |
| + } |
| + |
| + // TODO(tbarzic): Implement this. |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void StateController::MoveToBackground() { |
| + UpdateActionState(Action::kNewNote, ActionState::kHidden); |
| +} |
| + |
| +StateController::StateController() {} |
| + |
| +StateController::~StateController() {} |
| + |
| +bool StateController::UpdateActionState(Action action, |
| + ActionState action_state) { |
|
xiyuan
2017/05/02 18:12:22
nit: DCHECK_EQ(Action::kNewNote, action);
tbarzic
2017/05/02 18:43:37
Done.
|
| + ActionState old_state = GetActionState(action); |
|
xiyuan
2017/05/02 18:12:22
nit: const
tbarzic
2017/05/02 18:43:36
Done.
|
| + if (old_state == action_state) |
| + return false; |
| + |
| + if (action_state == ActionState::kHidden && old_state != ActionState::kActive) |
| + return false; |
| + |
| + new_note_state_ = action_state; |
| + NotifyStateChanged(Action::kNewNote); |
| + return true; |
| +} |
| + |
| +void StateController::NotifyStateChanged(Action action) { |
| + DCHECK_EQ(Action::kNewNote, action); |
| + |
| + for (auto& observer : observers_) |
| + observer.OnLockScreenAppsStateChanged(Action::kNewNote, new_note_state_); |
| +} |
| + |
| +} // namespace lock_screen_apps |