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

Unified Diff: ash/tray_action/tray_action.cc

Issue 2848813002: Introduce ash mojo interface for lock screen action handlers (Closed)
Patch Set: add ASH_EXPORTS 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
« no previous file with comments | « ash/tray_action/tray_action.h ('k') | ash/tray_action/tray_action_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/tray_action/tray_action.cc
diff --git a/ash/tray_action/tray_action.cc b/ash/tray_action/tray_action.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6437c61f17db8de21b6b553e56acde0e8889609c
--- /dev/null
+++ b/ash/tray_action/tray_action.cc
@@ -0,0 +1,84 @@
+// 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/tray_action.h"
+
+#include <utility>
+
+#include "ash/tray_action/tray_action_observer.h"
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/logging.h"
+
+namespace ash {
+
+TrayAction::TrayAction() = default;
+
+TrayAction::~TrayAction() = default;
+
+void TrayAction::AddObserver(TrayActionObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void TrayAction::RemoveObserver(TrayActionObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void TrayAction::BindRequest(mojom::TrayActionRequest request) {
+ bindings_.AddBinding(this, std::move(request));
+}
+
+mojom::TrayActionState TrayAction::GetLockScreenNoteState() {
+ if (!tray_action_client_)
+ return mojom::TrayActionState::kNotAvailable;
+ return lock_screen_note_state_;
+}
+
+void TrayAction::SetClient(mojom::TrayActionClientPtr tray_action_client,
+ mojom::TrayActionState lock_screen_note_state) {
+ mojom::TrayActionState old_lock_screen_note_state = GetLockScreenNoteState();
+
+ tray_action_client_ = std::move(tray_action_client);
+
+ if (tray_action_client_) {
+ // Makes sure the state is updated in case the connection is lost.
+ tray_action_client_.set_connection_error_handler(
+ base::Bind(&TrayAction::SetClient, base::Unretained(this), nullptr,
+ mojom::TrayActionState::kNotAvailable));
+ lock_screen_note_state_ = lock_screen_note_state;
+ }
+
+ // Setting action handler value can change effective state - notify observers
+ // if that was the case.
+ if (GetLockScreenNoteState() != old_lock_screen_note_state)
+ NotifyLockScreenNoteStateChanged();
+}
+
+void TrayAction::UpdateLockScreenNoteState(mojom::TrayActionState state) {
+ if (state == lock_screen_note_state_)
+ return;
+
+ lock_screen_note_state_ = state;
+
+ // If the client is not set, the effective state has not changed, so no need
+ // to notify observers of a state change.
+ if (tray_action_client_)
+ NotifyLockScreenNoteStateChanged();
+}
+
+void TrayAction::RequestNewLockScreenNote() {
+ if (GetLockScreenNoteState() != mojom::TrayActionState::kAvailable)
+ return;
+
+ // An action state can be kAvailable only if |tray_action_client_| is set.
+ DCHECK(tray_action_client_);
+ tray_action_client_->RequestNewLockScreenNote();
+}
+
+void TrayAction::NotifyLockScreenNoteStateChanged() {
+ for (auto& observer : observers_)
+ observer.OnLockScreenNoteStateChanged(GetLockScreenNoteState());
+}
+
+} // namespace ash
« no previous file with comments | « ash/tray_action/tray_action.h ('k') | ash/tray_action/tray_action_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698