Chromium Code Reviews| Index: ash/tray_action/tray_action.cc |
| diff --git a/ash/tray_action/tray_action.cc b/ash/tray_action/tray_action.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba51feac71e7244bfce5d1ba9799736f3b8d379e |
| --- /dev/null |
| +++ b/ash/tray_action/tray_action.cc |
| @@ -0,0 +1,69 @@ |
| +// 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 "ash/tray_action/tray_action.h" |
| + |
| +#include <utility> |
| + |
| +#include "ash/tray_action/tray_action_observer.h" |
| +#include "base/logging.h" |
| + |
| +namespace ash { |
| + |
| +TrayAction::TrayAction() = default; |
| + |
| +TrayAction::~TrayAction() = default; |
| + |
| +void TrayAction::AddObserver(TrayActionObserver* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void TrayAction::RemoveObserver(TrayActionObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void TrayAction::BindRequest(mojom::TrayActionRequest request) { |
| + bindings_.AddBinding(this, std::move(request)); |
| +} |
| + |
| +mojom::TrayActionState TrayAction::GetLockScreenNoteState() { |
| + if (!tray_action_client_) |
| + return mojom::TrayActionState::kNotSupported; |
| + return lock_screen_note_state_; |
| +} |
| + |
| +void TrayAction::SetClient(mojom::TrayActionClientPtr tray_action_client) { |
| + mojom::TrayActionState old_lock_screen_note_state = GetLockScreenNoteState(); |
| + |
| + tray_action_client_ = std::move(tray_action_client); |
| + |
| + // Setting action handler value can change effective state - notify observers |
| + // if that was the case. |
| + 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
|
| + NotifyLockScreenNoteStateChanged(); |
| +} |
| + |
| +void TrayAction::UpdateLockScreenNoteState(mojom::TrayActionState state) { |
| + if (state == lock_screen_note_state_) |
| + return; |
| + |
| + lock_screen_note_state_ = state; |
| + |
| + 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
|
| + NotifyLockScreenNoteStateChanged(); |
| +} |
| + |
| +void TrayAction::RequestNewLockScreenNote() { |
| + if (!tray_action_client_) |
| + return; |
| + |
| + tray_action_client_->RequestNewLockScreenNote(); |
| +} |
| + |
| +void TrayAction::NotifyLockScreenNoteStateChanged() { |
| + for (auto& observer : observers_) |
| + observer.OnLockScreenNoteStateChanged(GetLockScreenNoteState()); |
| +} |
| + |
| +} // namespace ash |