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 bool 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 false; | |
| 51 } | |
| 52 | |
| 53 // TODO(tbarzic): Implement this. | |
| 54 NOTIMPLEMENTED(); | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 void StateController::MoveToBackground() { | |
| 59 UpdateActionState(Action::kNewNote, ActionState::kHidden); | |
| 60 } | |
| 61 | |
| 62 StateController::StateController() {} | |
| 63 | |
| 64 StateController::~StateController() {} | |
| 65 | |
| 66 bool StateController::UpdateActionState(Action action, | |
| 67 ActionState action_state) { | |
| 68 DCHECK_EQ(Action::kNewNote, action); | |
| 69 | |
| 70 const ActionState kOldState = GetActionState(action); | |
|
jdufault
2017/05/02 20:16:02
kOldState => old_state? I don't think constant sty
tbarzic
2017/05/02 20:20:11
Done.
| |
| 71 if (kOldState == action_state) | |
| 72 return false; | |
| 73 | |
| 74 if (action_state == ActionState::kHidden && kOldState != ActionState::kActive) | |
| 75 return false; | |
| 76 | |
| 77 new_note_state_ = action_state; | |
| 78 NotifyStateChanged(Action::kNewNote); | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 void StateController::NotifyStateChanged(Action action) { | |
| 83 DCHECK_EQ(Action::kNewNote, action); | |
| 84 | |
| 85 for (auto& observer : observers_) | |
| 86 observer.OnLockScreenAppsStateChanged(Action::kNewNote, new_note_state_); | |
| 87 } | |
| 88 | |
| 89 } // namespace lock_screen_apps | |
| OLD | NEW |