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

Side by Side Diff: ash/tray_action/tray_action.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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "ash/tray_action/tray_action.h"
6
7 #include <utility>
8
9 #include "ash/tray_action/tray_action_observer.h"
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/logging.h"
13
14 namespace ash {
15
16 TrayAction::TrayAction() = default;
17
18 TrayAction::~TrayAction() = default;
19
20 void TrayAction::AddObserver(TrayActionObserver* observer) {
21 observers_.AddObserver(observer);
22 }
23
24 void TrayAction::RemoveObserver(TrayActionObserver* observer) {
25 observers_.RemoveObserver(observer);
26 }
27
28 void TrayAction::BindRequest(mojom::TrayActionRequest request) {
29 bindings_.AddBinding(this, std::move(request));
30 }
31
32 mojom::TrayActionState TrayAction::GetLockScreenNoteState() {
33 if (!tray_action_client_)
34 return mojom::TrayActionState::kNotAvailable;
35 return lock_screen_note_state_;
36 }
37
38 void TrayAction::SetClient(mojom::TrayActionClientPtr tray_action_client,
39 mojom::TrayActionState lock_screen_note_state) {
40 mojom::TrayActionState old_lock_screen_note_state = GetLockScreenNoteState();
41
42 tray_action_client_ = std::move(tray_action_client);
43
44 if (tray_action_client_) {
45 // Makes sure the state is updated in case the connection is lost.
46 tray_action_client_.set_connection_error_handler(
47 base::Bind(&TrayAction::SetClient, base::Unretained(this), nullptr,
48 mojom::TrayActionState::kNotAvailable));
49 lock_screen_note_state_ = lock_screen_note_state;
50 }
51
52 // Setting action handler value can change effective state - notify observers
53 // if that was the case.
54 if (GetLockScreenNoteState() != old_lock_screen_note_state)
55 NotifyLockScreenNoteStateChanged();
56 }
57
58 void TrayAction::UpdateLockScreenNoteState(mojom::TrayActionState state) {
59 if (state == lock_screen_note_state_)
60 return;
61
62 lock_screen_note_state_ = state;
63
64 // If the client is not set, the effective state has not changed, so no need
65 // to notify observers of a state change.
66 if (tray_action_client_)
67 NotifyLockScreenNoteStateChanged();
68 }
69
70 void TrayAction::RequestNewLockScreenNote() {
71 if (GetLockScreenNoteState() != mojom::TrayActionState::kAvailable)
72 return;
73
74 // An action state can be kAvailable only if |tray_action_client_| is set.
75 DCHECK(tray_action_client_);
76 tray_action_client_->RequestNewLockScreenNote();
77 }
78
79 void TrayAction::NotifyLockScreenNoteStateChanged() {
80 for (auto& observer : observers_)
81 observer.OnLockScreenNoteStateChanged(GetLockScreenNoteState());
82 }
83
84 } // namespace ash
OLDNEW
« 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