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

Side by Side Diff: ash/tray_action/tray_action.cc

Issue 2848813002: 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
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/logging.h"
11
12 namespace ash {
13
14 TrayAction::TrayAction() = default;
15
16 TrayAction::~TrayAction() = default;
17
18 void TrayAction::AddObserver(TrayActionObserver* observer) {
19 observers_.AddObserver(observer);
20 }
21
22 void TrayAction::RemoveObserver(TrayActionObserver* observer) {
23 observers_.RemoveObserver(observer);
24 }
25
26 void TrayAction::BindRequest(mojom::TrayActionRequest request) {
27 bindings_.AddBinding(this, std::move(request));
28 }
29
30 mojom::TrayActionState TrayAction::GetLockScreenNoteState() {
31 if (!tray_action_client_)
32 return mojom::TrayActionState::kNotSupported;
33 return lock_screen_note_state_;
34 }
35
36 void TrayAction::SetClient(mojom::TrayActionClientPtr tray_action_client) {
37 mojom::TrayActionState old_lock_screen_note_state = GetLockScreenNoteState();
38
39 tray_action_client_ = std::move(tray_action_client);
40
41 // Setting action handler value can change effective state - notify observers
42 // if that was the case.
43 if (GetLockScreenNoteState() != old_lock_screen_note_state)
xiyuan 2017/05/04 21:19:16 Do we need to worry about SetClient to nullptr cas
tbarzic 2017/05/04 23:27:18 Yeah good point, I planned to do this, but it slip
44 NotifyLockScreenNoteStateChanged();
45 }
46
47 void TrayAction::UpdateLockScreenNoteState(mojom::TrayActionState state) {
48 if (state == lock_screen_note_state_)
49 return;
50
51 lock_screen_note_state_ = state;
52
53 if (tray_action_client_)
xiyuan 2017/05/04 21:19:16 Why the notification does not need to fire without
tbarzic 2017/05/04 23:27:18 If client us not set, the effective action state h
54 NotifyLockScreenNoteStateChanged();
55 }
56
57 void TrayAction::RequestNewLockScreenNote() {
58 if (!tray_action_client_)
59 return;
60
61 tray_action_client_->RequestNewLockScreenNote();
62 }
63
64 void TrayAction::NotifyLockScreenNoteStateChanged() {
65 for (auto& observer : observers_)
66 observer.OnLockScreenNoteStateChanged(GetLockScreenNoteState());
67 }
68
69 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698