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

Unified Diff: ash/tray_action_handler/tray_action_handler_controller.cc

Issue 2848813002: Introduce ash mojo interface for lock screen action handlers (Closed)
Patch Set: . Created 3 years, 8 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: ash/tray_action_handler/tray_action_handler_controller.cc
diff --git a/ash/tray_action_handler/tray_action_handler_controller.cc b/ash/tray_action_handler/tray_action_handler_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..22503d194e3cc0b93337b71986ed14b4710522d0
--- /dev/null
+++ b/ash/tray_action_handler/tray_action_handler_controller.cc
@@ -0,0 +1,89 @@
+// 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 "ash/tray_action_handler/tray_action_handler_controller.h"
+
+#include <utility>
+
+#include "ash/tray_action_handler/tray_action_handler_observer.h"
+#include "base/logging.h"
+
+namespace ash {
+
+TrayActionHandlerController::TrayActionHandlerController() {}
James Cook 2017/05/03 23:31:51 optional: = default
tbarzic 2017/05/04 20:58:30 Done.
+
+TrayActionHandlerController::~TrayActionHandlerController() {}
+
+void TrayActionHandlerController::AddObserver(
+ TrayActionHandlerObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void TrayActionHandlerController::RemoveObserver(
+ TrayActionHandlerObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void TrayActionHandlerController::BindRequest(
+ mojom::TrayActionHandlerControllerRequest request) {
+ bindings_.AddBinding(this, std::move(request));
+}
+
+mojom::TrayActionHandlerState TrayActionHandlerController::GetState(
+ mojom::TrayActionHandlerAction action) {
+ DCHECK_EQ(mojom::TrayActionHandlerAction::kNewLockScreenNote, action);
+
+ if (!action_handler_client_)
+ return mojom::TrayActionHandlerState::kNotSupported;
+ return new_note_state_;
+}
+
+void TrayActionHandlerController::SetClient(
+ mojom::TrayActionHandlerClientPtr action_handler_client) {
+ mojom::TrayActionHandlerState old_effective_new_note_state =
James Cook 2017/05/03 23:31:50 What does "effective" mean here? Isn't this just "
tbarzic 2017/05/04 20:58:30 yeah, pretty much
+ GetState(mojom::TrayActionHandlerAction::kNewLockScreenNote);
+
+ action_handler_client_ = std::move(action_handler_client);
+
+ // Setting action handler value can change effective state - notify observers
+ // if that was the case.
+ if (GetState(mojom::TrayActionHandlerAction::kNewLockScreenNote) !=
+ old_effective_new_note_state) {
+ NotifyActionStateChanged(
+ mojom::TrayActionHandlerAction::kNewLockScreenNote);
+ }
+}
+
+void TrayActionHandlerController::UpdateActionHandlerState(
+ mojom::TrayActionHandlerAction action,
+ mojom::TrayActionHandlerState state) {
+ if (action != mojom::TrayActionHandlerAction::kNewLockScreenNote) {
+ LOG(ERROR) << "Unexpected action " << action;
+ return;
+ }
+
+ if (state == new_note_state_)
+ return;
+
+ new_note_state_ = state;
+
+ if (action_handler_client_)
+ NotifyActionStateChanged(action);
+}
+
+void TrayActionHandlerController::RequestHandleAction(
+ mojom::TrayActionHandlerAction action) {
+ if (!action_handler_client_)
+ return;
+
+ action_handler_client_->RequestHandleAction(action);
+}
+
+void TrayActionHandlerController::NotifyActionStateChanged(
+ mojom::TrayActionHandlerAction action) {
+ for (auto& observer : observers_)
+ observer.OnActionStateChanged(action, GetState(action));
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698