Chromium Code Reviews| Index: chrome/browser/ui/ash/tray_action_handler_client.cc |
| diff --git a/chrome/browser/ui/ash/tray_action_handler_client.cc b/chrome/browser/ui/ash/tray_action_handler_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..97410bad5218549ee74b0e5b96b2bdc0d71917c8 |
| --- /dev/null |
| +++ b/chrome/browser/ui/ash/tray_action_handler_client.cc |
| @@ -0,0 +1,87 @@ |
| +// 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 "chrome/browser/ui/ash/tray_action_handler_client.h" |
| + |
| +#include "ash/public/interfaces/constants.mojom.h" |
| +#include "base/logging.h" |
| +#include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" |
| +#include "content/public/common/service_manager_connection.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| + |
| +namespace { |
| + |
| +ash::mojom::TrayActionHandlerState ActionStateToMojo( |
| + lock_screen_apps::ActionState state) { |
| + switch (state) { |
| + 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.
|
| + return ash::mojom::TrayActionHandlerState::kNotSupported; |
| + case lock_screen_apps::ActionState::kNotAvailable: |
| + return ash::mojom::TrayActionHandlerState::kNotSupported; |
| + case lock_screen_apps::ActionState::kAvailable: |
| + return ash::mojom::TrayActionHandlerState::kAvailable; |
| + case lock_screen_apps::ActionState::kLaunching: |
| + return ash::mojom::TrayActionHandlerState::kLaunching; |
| + case lock_screen_apps::ActionState::kActive: |
| + return ash::mojom::TrayActionHandlerState::kActive; |
| + 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
|
| + return ash::mojom::TrayActionHandlerState::kBackground; |
| + } |
| + NOTREACHED() << "Unexpected lock screen app action state " |
| + << static_cast<int>(state); |
| + return ash::mojom::TrayActionHandlerState::kNotSupported; |
| +} |
| + |
| +} // namespace |
| + |
| +TrayActionHandlerClient::TrayActionHandlerClient( |
| + lock_screen_apps::StateController* state_controller) |
| + : lock_screen_apps_state_controller_(state_controller), |
| + observer_(this), |
| + binding_(this) {} |
|
James Cook
2017/05/03 23:31:51
nit: DCHECK(state_controller_)
tbarzic
2017/05/04 20:58:31
Acknowledged.
|
| + |
| +TrayActionHandlerClient::~TrayActionHandlerClient() {} |
| + |
| +void TrayActionHandlerClient::Init() { |
| + 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
|
| + return; |
| + |
| + service_manager::Connector* connector = |
| + content::ServiceManagerConnection::GetForProcess()->GetConnector(); |
| + connector->BindInterface(ash::mojom::kServiceName, |
| + &tray_action_handler_controller_); |
| + tray_action_handler_controller_->SetClient( |
| + binding_.CreateInterfacePtrAndBind()); |
| + |
| + observer_.Add(lock_screen_apps_state_controller_); |
| + |
| + // Currently the only supported action. |
| + const lock_screen_apps::Action kAction = lock_screen_apps::Action::kNewNote; |
| + OnLockScreenAppsStateChanged( |
| + kAction, lock_screen_apps_state_controller_->GetActionState(kAction)); |
| +} |
| + |
| +void TrayActionHandlerClient::RequestHandleAction( |
| + ash::mojom::TrayActionHandlerAction action) { |
| + if (action != ash::mojom::TrayActionHandlerAction::kNewLockScreenNote) { |
| + LOG(ERROR) << "Unexpected action " << action; |
| + return; |
| + } |
| + |
| + lock_screen_apps_state_controller_->HandleAction( |
| + lock_screen_apps::Action::kNewNote); |
| +} |
| + |
| +void TrayActionHandlerClient::OnLockScreenAppsStateChanged( |
| + lock_screen_apps::Action action, |
| + lock_screen_apps::ActionState state) { |
| + if (action != lock_screen_apps::Action::kNewNote) { |
| + LOG(ERROR) << "Unexpected action " << static_cast<int>(action); |
| + return; |
| + } |
| + |
| + tray_action_handler_controller_->UpdateActionHandlerState( |
| + ash::mojom::TrayActionHandlerAction::kNewLockScreenNote, |
| + ActionStateToMojo(state)); |
| +} |