Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 5 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/location.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "chromeos/chromeos_switches.h" | |
| 13 | |
| 14 namespace lock_screen_apps { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 base::LazyInstance<StateController>::Leaky g_instance = | |
| 19 LAZY_INSTANCE_INITIALIZER; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 // static | |
| 24 StateController* StateController::Get() { | |
| 25 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 26 chromeos::switches::kEnableLockScreenApps)) { | |
| 27 return nullptr; | |
| 28 } | |
| 29 return g_instance.Pointer(); | |
| 30 } | |
| 31 | |
| 32 void StateController::AddObserver(StateObserver* observer) { | |
| 33 observers_.AddObserver(observer); | |
| 34 } | |
| 35 | |
| 36 void StateController::RemoveObserver(StateObserver* observer) { | |
| 37 observers_.RemoveObserver(observer); | |
| 38 } | |
| 39 | |
| 40 ActionState StateController::GetActionState(Action action) const { | |
| 41 DCHECK_EQ(Action::kNewNote, action); | |
| 42 return new_note_state_; | |
| 43 } | |
| 44 | |
| 45 void StateController::HandleAction(Action action) { | |
| 46 DCHECK_EQ(Action::kNewNote, action); | |
| 47 | |
| 48 if (new_note_state_ != ActionState::kAvailable && | |
| 49 new_note_state_ != ActionState::kHidden) { | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 // TODO(tbarzic): Implement this. | |
| 54 NOTIMPLEMENTED(); | |
| 55 } | |
| 56 | |
| 57 void StateController::MoveToBackground() { | |
| 58 UpdateActionState(Action::kNewNote, ActionState::kHidden); | |
| 59 } | |
| 60 | |
| 61 StateController::StateController() {} | |
| 62 | |
| 63 StateController::~StateController() {} | |
| 64 | |
| 65 bool StateController::UpdateActionState(Action action, | |
| 66 ActionState action_state) { | |
|
xiyuan
2017/05/02 18:12:22
nit: DCHECK_EQ(Action::kNewNote, action);
tbarzic
2017/05/02 18:43:37
Done.
| |
| 67 ActionState old_state = GetActionState(action); | |
|
xiyuan
2017/05/02 18:12:22
nit: const
tbarzic
2017/05/02 18:43:36
Done.
| |
| 68 if (old_state == action_state) | |
| 69 return false; | |
| 70 | |
| 71 if (action_state == ActionState::kHidden && old_state != ActionState::kActive) | |
| 72 return false; | |
| 73 | |
| 74 new_note_state_ = action_state; | |
| 75 NotifyStateChanged(Action::kNewNote); | |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 void StateController::NotifyStateChanged(Action action) { | |
| 80 DCHECK_EQ(Action::kNewNote, action); | |
| 81 | |
| 82 for (auto& observer : observers_) | |
| 83 observer.OnLockScreenAppsStateChanged(Action::kNewNote, new_note_state_); | |
| 84 } | |
| 85 | |
| 86 } // namespace lock_screen_apps | |
| OLD | NEW |