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

Side by Side 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, 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_handler/tray_action_handler_controller.h"
6
7 #include <utility>
8
9 #include "ash/tray_action_handler/tray_action_handler_observer.h"
10 #include "base/logging.h"
11
12 namespace ash {
13
14 TrayActionHandlerController::TrayActionHandlerController() {}
James Cook 2017/05/03 23:31:51 optional: = default
tbarzic 2017/05/04 20:58:30 Done.
15
16 TrayActionHandlerController::~TrayActionHandlerController() {}
17
18 void TrayActionHandlerController::AddObserver(
19 TrayActionHandlerObserver* observer) {
20 observers_.AddObserver(observer);
21 }
22
23 void TrayActionHandlerController::RemoveObserver(
24 TrayActionHandlerObserver* observer) {
25 observers_.RemoveObserver(observer);
26 }
27
28 void TrayActionHandlerController::BindRequest(
29 mojom::TrayActionHandlerControllerRequest request) {
30 bindings_.AddBinding(this, std::move(request));
31 }
32
33 mojom::TrayActionHandlerState TrayActionHandlerController::GetState(
34 mojom::TrayActionHandlerAction action) {
35 DCHECK_EQ(mojom::TrayActionHandlerAction::kNewLockScreenNote, action);
36
37 if (!action_handler_client_)
38 return mojom::TrayActionHandlerState::kNotSupported;
39 return new_note_state_;
40 }
41
42 void TrayActionHandlerController::SetClient(
43 mojom::TrayActionHandlerClientPtr action_handler_client) {
44 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
45 GetState(mojom::TrayActionHandlerAction::kNewLockScreenNote);
46
47 action_handler_client_ = std::move(action_handler_client);
48
49 // Setting action handler value can change effective state - notify observers
50 // if that was the case.
51 if (GetState(mojom::TrayActionHandlerAction::kNewLockScreenNote) !=
52 old_effective_new_note_state) {
53 NotifyActionStateChanged(
54 mojom::TrayActionHandlerAction::kNewLockScreenNote);
55 }
56 }
57
58 void TrayActionHandlerController::UpdateActionHandlerState(
59 mojom::TrayActionHandlerAction action,
60 mojom::TrayActionHandlerState state) {
61 if (action != mojom::TrayActionHandlerAction::kNewLockScreenNote) {
62 LOG(ERROR) << "Unexpected action " << action;
63 return;
64 }
65
66 if (state == new_note_state_)
67 return;
68
69 new_note_state_ = state;
70
71 if (action_handler_client_)
72 NotifyActionStateChanged(action);
73 }
74
75 void TrayActionHandlerController::RequestHandleAction(
76 mojom::TrayActionHandlerAction action) {
77 if (!action_handler_client_)
78 return;
79
80 action_handler_client_->RequestHandleAction(action);
81 }
82
83 void TrayActionHandlerController::NotifyActionStateChanged(
84 mojom::TrayActionHandlerAction action) {
85 for (auto& observer : observers_)
86 observer.OnActionStateChanged(action, GetState(action));
87 }
88
89 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698