Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3405)

Unified Diff: chrome/browser/chromeos/lock_screen_apps/state_controller.cc

Issue 2870473002: Revert of Introduce ash mojo interface for lock screen action handlers (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index 7ca018ee915afcbf64722d696a09470a05a5c81f..12562dbf722bd7f02d1fd6db1d2d38cf4678e2af 100644
--- a/chrome/browser/chromeos/lock_screen_apps/state_controller.cc
+++ b/chrome/browser/chromeos/lock_screen_apps/state_controller.cc
@@ -4,67 +4,29 @@
#include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
-#include <utility>
-
-#include "ash/public/interfaces/constants.mojom.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"
-#include "content/public/common/service_manager_connection.h"
-#include "services/service_manager/public/cpp/connector.h"
-
-using ash::mojom::TrayActionState;
namespace lock_screen_apps {
namespace {
-StateController* g_instance = nullptr;
+base::LazyInstance<StateController>::Leaky g_instance =
+ LAZY_INSTANCE_INITIALIZER;
} // namespace
// static
-bool StateController::IsEnabled() {
- return base::CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kEnableLockScreenApps);
-}
-
-// static
StateController* StateController::Get() {
- DCHECK(g_instance || !IsEnabled());
- return g_instance;
-}
-
-StateController::StateController() : binding_(this) {
- DCHECK(!g_instance);
- DCHECK(IsEnabled());
-
- g_instance = this;
-}
-
-StateController::~StateController() {
- DCHECK_EQ(g_instance, this);
- g_instance = nullptr;
-}
-
-void StateController::SetTrayActionPtrForTesting(
- ash::mojom::TrayActionPtr tray_action_ptr) {
- tray_action_ptr_ = std::move(tray_action_ptr);
-}
-
-void StateController::FlushTrayActionForTesting() {
- tray_action_ptr_.FlushForTesting();
-}
-
-void StateController::Initialize() {
- // The tray action ptr might be set previously if the client was being created
- // for testing.
- if (!tray_action_ptr_) {
- service_manager::Connector* connector =
- content::ServiceManagerConnection::GetForProcess()->GetConnector();
- connector->BindInterface(ash::mojom::kServiceName, &tray_action_ptr_);
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kEnableLockScreenApps)) {
+ return nullptr;
}
- tray_action_ptr_->SetClient(binding_.CreateInterfacePtrAndBind(),
- lock_screen_note_state_);
+ return g_instance.Pointer();
}
void StateController::AddObserver(StateObserver* observer) {
@@ -75,49 +37,53 @@
observers_.RemoveObserver(observer);
}
-TrayActionState StateController::GetLockScreenNoteState() const {
- return lock_screen_note_state_;
+ActionState StateController::GetActionState(Action action) const {
+ DCHECK_EQ(Action::kNewNote, action);
+ return new_note_state_;
}
-void StateController::RequestNewLockScreenNote() {
- if (lock_screen_note_state_ != TrayActionState::kAvailable) {
- return;
+bool StateController::HandleAction(Action action) {
+ DCHECK_EQ(Action::kNewNote, action);
+
+ if (new_note_state_ != ActionState::kAvailable &&
+ new_note_state_ != ActionState::kHidden) {
+ return false;
}
- // TODO(tbarzic): Implement this properly.
- UpdateLockScreenNoteState(TrayActionState::kActive);
+ // TODO(tbarzic): Implement this.
+ NOTIMPLEMENTED();
+ return true;
}
void StateController::MoveToBackground() {
- UpdateLockScreenNoteState(TrayActionState::kBackground);
+ UpdateActionState(Action::kNewNote, ActionState::kHidden);
}
-void StateController::SetLockScreenNoteStateForTesting(
- ash::mojom::TrayActionState state) {
- lock_screen_note_state_ = state;
-}
+StateController::StateController() {}
-bool StateController::UpdateLockScreenNoteState(TrayActionState state) {
- const TrayActionState old_state = GetLockScreenNoteState();
- if (old_state == state)
+StateController::~StateController() {}
+
+bool StateController::UpdateActionState(Action action,
+ ActionState action_state) {
+ DCHECK_EQ(Action::kNewNote, action);
+
+ const ActionState old_state = GetActionState(action);
+ if (old_state == action_state)
return false;
- // Action state can be moved to background only if the action is currently
- // active.
- if (state == TrayActionState::kBackground &&
- old_state != TrayActionState::kActive)
+ if (action_state == ActionState::kHidden && old_state != ActionState::kActive)
return false;
- lock_screen_note_state_ = state;
- NotifyLockScreenNoteStateChanged();
+ new_note_state_ = action_state;
+ NotifyStateChanged(Action::kNewNote);
return true;
}
-void StateController::NotifyLockScreenNoteStateChanged() {
+void StateController::NotifyStateChanged(Action action) {
+ DCHECK_EQ(Action::kNewNote, action);
+
for (auto& observer : observers_)
- observer.OnLockScreenNoteStateChanged(lock_screen_note_state_);
-
- tray_action_ptr_->UpdateLockScreenNoteState(lock_screen_note_state_);
+ observer.OnLockScreenAppsStateChanged(Action::kNewNote, new_note_state_);
}
} // namespace lock_screen_apps

Powered by Google App Engine
This is Rietveld 408576698