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

Side by Side Diff: chrome/browser/ui/ash/tray_action_handler_client.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 "chrome/browser/ui/ash/tray_action_handler_client.h"
6
7 #include "ash/public/interfaces/constants.mojom.h"
8 #include "base/logging.h"
9 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
10 #include "content/public/common/service_manager_connection.h"
11 #include "services/service_manager/public/cpp/connector.h"
12
13 namespace {
14
15 ash::mojom::TrayActionHandlerState ActionStateToMojo(
16 lock_screen_apps::ActionState state) {
17 switch (state) {
18 case lock_screen_apps::ActionState::kNotSupported:
James Cook 2017/05/03 23:31:51 Can these two action state enums go somewhere shar
tbarzic 2017/05/04 20:58:31 Done.
19 return ash::mojom::TrayActionHandlerState::kNotSupported;
20 case lock_screen_apps::ActionState::kNotAvailable:
21 return ash::mojom::TrayActionHandlerState::kNotSupported;
22 case lock_screen_apps::ActionState::kAvailable:
23 return ash::mojom::TrayActionHandlerState::kAvailable;
24 case lock_screen_apps::ActionState::kLaunching:
25 return ash::mojom::TrayActionHandlerState::kLaunching;
26 case lock_screen_apps::ActionState::kActive:
27 return ash::mojom::TrayActionHandlerState::kActive;
28 case lock_screen_apps::ActionState::kHidden:
James Cook 2017/05/03 23:31:51 Why is there a difference in name between "hidden"
tbarzic 2017/05/04 20:58:31 I changed my mind about naming after lading kHidde
29 return ash::mojom::TrayActionHandlerState::kBackground;
30 }
31 NOTREACHED() << "Unexpected lock screen app action state "
32 << static_cast<int>(state);
33 return ash::mojom::TrayActionHandlerState::kNotSupported;
34 }
35
36 } // namespace
37
38 TrayActionHandlerClient::TrayActionHandlerClient(
39 lock_screen_apps::StateController* state_controller)
40 : lock_screen_apps_state_controller_(state_controller),
41 observer_(this),
42 binding_(this) {}
James Cook 2017/05/03 23:31:51 nit: DCHECK(state_controller_)
tbarzic 2017/05/04 20:58:31 Acknowledged.
43
44 TrayActionHandlerClient::~TrayActionHandlerClient() {}
45
46 void TrayActionHandlerClient::Init() {
47 if (!lock_screen_apps_state_controller_)
James Cook 2017/05/03 23:31:51 Can this happen in production?
tbarzic 2017/05/04 20:58:31 It could happen, in case lock screen apps were not
48 return;
49
50 service_manager::Connector* connector =
51 content::ServiceManagerConnection::GetForProcess()->GetConnector();
52 connector->BindInterface(ash::mojom::kServiceName,
53 &tray_action_handler_controller_);
54 tray_action_handler_controller_->SetClient(
55 binding_.CreateInterfacePtrAndBind());
56
57 observer_.Add(lock_screen_apps_state_controller_);
58
59 // Currently the only supported action.
60 const lock_screen_apps::Action kAction = lock_screen_apps::Action::kNewNote;
61 OnLockScreenAppsStateChanged(
62 kAction, lock_screen_apps_state_controller_->GetActionState(kAction));
63 }
64
65 void TrayActionHandlerClient::RequestHandleAction(
66 ash::mojom::TrayActionHandlerAction action) {
67 if (action != ash::mojom::TrayActionHandlerAction::kNewLockScreenNote) {
68 LOG(ERROR) << "Unexpected action " << action;
69 return;
70 }
71
72 lock_screen_apps_state_controller_->HandleAction(
73 lock_screen_apps::Action::kNewNote);
74 }
75
76 void TrayActionHandlerClient::OnLockScreenAppsStateChanged(
77 lock_screen_apps::Action action,
78 lock_screen_apps::ActionState state) {
79 if (action != lock_screen_apps::Action::kNewNote) {
80 LOG(ERROR) << "Unexpected action " << static_cast<int>(action);
81 return;
82 }
83
84 tray_action_handler_controller_->UpdateActionHandlerState(
85 ash::mojom::TrayActionHandlerAction::kNewLockScreenNote,
86 ActionStateToMojo(state));
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698