Commit b91cf9d1 authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Add PhoneStatusProcessor

PhoneStatusProcessor is responsible for converting incoming proto
messages to PhoneHub objects and have clients be notified of the
incoming changes.

Bug: 1106937
Test: unittest
Change-Id: Ib22c626ccd7c571692ae8c687935243a948c0581
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427107
Commit-Queue: Jimmy Gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812471}
parent 79e85116
......@@ -64,6 +64,8 @@ static_library("phonehub") {
"phone_model.h",
"phone_status_model.cc",
"phone_status_model.h",
"phone_status_processor.cc",
"phone_status_processor.h",
"pref_names.cc",
"pref_names.h",
"tether_controller.cc",
......@@ -161,6 +163,7 @@ source_set("unit_tests") {
"notification_manager_impl_unittest.cc",
"onboarding_ui_tracker_impl_unittest.cc",
"phone_status_model_unittest.cc",
"phone_status_processor_unittest.cc",
"tether_controller_impl_unittest.cc",
]
......@@ -181,5 +184,6 @@ source_set("unit_tests") {
"//components/prefs:test_support",
"//device/bluetooth:mocks",
"//testing/gtest",
"//ui/gfx",
]
}
......@@ -38,6 +38,8 @@ class DoNotDisturbController {
void RemoveObserver(Observer* observer);
protected:
friend class PhoneStatusProcessor;
DoNotDisturbController();
// This only sets the internal state of the DoNotDisturb mode and does not
......
......@@ -16,8 +16,8 @@ class FakeMessageReceiver : public MessageReceiver {
FakeMessageReceiver() = default;
~FakeMessageReceiver() override = default;
using MessageReceiver::NotifyPhoneStatusSnapshotUpdated;
using MessageReceiver::NotifyPhoneStatusUpdated;
using MessageReceiver::NotifyPhoneStatusSnapshotReceived;
using MessageReceiver::NotifyPhoneStatusUpdateReceived;
};
} // namespace phonehub
......
......@@ -63,6 +63,16 @@ void FakeNotificationManager::RemoveNotificationsInternal(
NotifyNotificationsRemoved(ids);
}
void FakeNotificationManager::ClearNotificationsInternal() {
base::flat_set<int64_t> removed_ids;
for (const auto& pair : id_to_notification_map_) {
removed_ids.emplace(pair.first);
}
id_to_notification_map_.clear();
NotifyNotificationsRemoved(removed_ids);
}
const Notification* FakeNotificationManager::GetNotification(
int64_t notification_id) const {
auto it = id_to_notification_map_.find(notification_id);
......
......@@ -27,10 +27,14 @@ class FakeNotificationManager : public NotificationManager {
void RemoveNotification(int64_t id);
void RemoveNotificationsInternal(const base::flat_set<int64_t>& ids) override;
void ClearNotificationsInternal() override;
const std::vector<int64_t>& dismissed_notification_ids() const {
return dismissed_notification_ids_;
}
size_t num_notifications() const { return id_to_notification_map_.size(); }
struct InlineReplyMetadata {
InlineReplyMetadata(int64_t notification_id,
const base::string16& inline_reply_text);
......
......@@ -40,6 +40,8 @@ class FindMyDeviceController {
void RemoveObserver(Observer* observer);
protected:
friend class PhoneStatusProcessor;
FindMyDeviceController();
// This only sets the internal state of the whether the phone is ringin
......
......@@ -71,6 +71,7 @@ class NotificationAccessManager {
private:
friend class NotificationAccessManagerImplTest;
friend class PhoneStatusProcessor;
// This only sets the internal state of the whether notification access has
// mode been enabled and does not send a request to set the state of the
......
......@@ -61,6 +61,8 @@ class NotificationManager {
void RemoveObserver(Observer* observer);
protected:
friend class PhoneStatusProcessor;
NotificationManager();
// Sets the internal collection of notifications. This does not send any
......@@ -74,6 +76,10 @@ class NotificationManager {
virtual void RemoveNotificationsInternal(
const base::flat_set<int64_t>& notification_ids) = 0;
// Clears the underlying internal collection of notifications. This does not
// send any requests to clear the phone's notifications.
virtual void ClearNotificationsInternal() = 0;
void NotifyNotificationsAdded(
const base::flat_set<int64_t>& notification_ids);
void NotifyNotificationsUpdated(
......
......@@ -35,6 +35,11 @@ void NotificationManagerImpl::DismissNotification(int64_t notification_id) {
PA_LOG(INFO) << "Dismissing notification with ID " << notification_id << ".";
}
void NotificationManagerImpl::ClearNotificationsInternal() {
PA_LOG(INFO) << "Clearing notification internally.";
// TODO(jimmyxgong): Implement this stub function.
}
void NotificationManagerImpl::SendInlineReply(
int64_t notification_id,
const base::string16& inline_reply_text) {
......
......@@ -25,6 +25,7 @@ class NotificationManagerImpl : public NotificationManager {
const base::flat_set<Notification>& notifications) override;
void RemoveNotificationsInternal(
const base::flat_set<int64_t>& notification_ids) override;
void ClearNotificationsInternal() override;
void DismissNotification(int64_t notification_id) override;
void SendInlineReply(int64_t notification_id,
const base::string16& inline_reply_text) override;
......
......@@ -15,6 +15,8 @@
#include "chromeos/components/phonehub/notification_access_manager_impl.h"
#include "chromeos/components/phonehub/notification_manager_impl.h"
#include "chromeos/components/phonehub/onboarding_ui_tracker_impl.h"
#include "chromeos/components/phonehub/phone_model.h"
#include "chromeos/components/phonehub/phone_status_processor.h"
#include "chromeos/components/phonehub/tether_controller_impl.h"
namespace chromeos {
......@@ -54,6 +56,15 @@ PhoneHubManagerImpl::PhoneHubManagerImpl(
multidevice_setup_client,
show_multidevice_setup_dialog_callback)),
phone_model_(std::make_unique<MutablePhoneModel>()),
phone_status_processor_(std::make_unique<PhoneStatusProcessor>(
do_not_disturb_controller_.get(),
feature_status_provider_.get(),
message_receiver_.get(),
find_my_device_controller_.get(),
notification_access_manager_.get(),
notification_manager_.get(),
multidevice_setup_client,
phone_model_.get())),
tether_controller_(
std::make_unique<TetherControllerImpl>(multidevice_setup_client)) {}
......@@ -99,6 +110,7 @@ TetherController* PhoneHubManagerImpl::GetTetherController() {
// initialized in the constructor.
void PhoneHubManagerImpl::Shutdown() {
tether_controller_.reset();
phone_status_processor_.reset();
phone_model_.reset();
onboarding_ui_tracker_.reset();
notification_access_manager_.reset();
......
......@@ -32,6 +32,8 @@ namespace phonehub {
class ConnectionManager;
class MessageSender;
class MessageReceiver;
class MutablePhoneModel;
class PhoneStatusProcessor;
// Implemented as a KeyedService which is keyed by the primary Profile.
class PhoneHubManagerImpl : public PhoneHubManager, public KeyedService {
......@@ -69,7 +71,8 @@ class PhoneHubManagerImpl : public PhoneHubManager, public KeyedService {
std::unique_ptr<NotificationAccessManager> notification_access_manager_;
std::unique_ptr<NotificationManager> notification_manager_;
std::unique_ptr<OnboardingUiTracker> onboarding_ui_tracker_;
std::unique_ptr<PhoneModel> phone_model_;
std::unique_ptr<MutablePhoneModel> phone_model_;
std::unique_ptr<PhoneStatusProcessor> phone_status_processor_;
std::unique_ptr<TetherController> tether_controller_;
};
......
This diff is collapsed.
// Copyright 2020 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.
#ifndef CHROMEOS_COMPONENTS_PHONEHUB_PHONE_STATUS_PROCESSOR_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_PHONE_STATUS_PROCESSOR_H_
#include "chromeos/components/phonehub/feature_status_provider.h"
#include "chromeos/components/phonehub/message_receiver.h"
#include "chromeos/components/phonehub/proto/phonehub_api.pb.h"
#include "chromeos/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
#include <google/protobuf/repeated_field.h>
using google::protobuf::RepeatedPtrField;
namespace chromeos {
namespace phonehub {
class DoNotDisturbController;
class FeatureStatusProvider;
class FindMyDeviceController;
class NotificationAccessManager;
class NotificationManager;
class MutablePhoneModel;
// Responsible for receiving incoming protos and calling on clients to update
// their models.
class PhoneStatusProcessor
: public MessageReceiver::Observer,
public FeatureStatusProvider::Observer,
public multidevice_setup::MultiDeviceSetupClient::Observer {
public:
PhoneStatusProcessor(
DoNotDisturbController* do_not_disturb_controller,
FeatureStatusProvider* feature_status_provider,
MessageReceiver* message_receiver,
FindMyDeviceController* find_my_device_controller,
NotificationAccessManager* notification_access_manager,
NotificationManager* notification_manager,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
MutablePhoneModel* phone_model);
~PhoneStatusProcessor() override;
PhoneStatusProcessor(const PhoneStatusProcessor&) = delete;
PhoneStatusProcessor& operator=(const PhoneStatusProcessor&) = delete;
private:
// FeatureStatusProvider::Observer:
void OnFeatureStatusChanged() override;
// MessageReceiver::Observer:
void OnPhoneStatusSnapshotReceived(
proto::PhoneStatusSnapshot phone_status_snapshot) override;
void OnPhoneStatusUpdateReceived(
proto::PhoneStatusUpdate phone_status_update) override;
// MultiDeviceSetupClient::Observer:
void OnHostStatusChanged(
const multidevice_setup::MultiDeviceSetupClient::HostStatusWithDevice&
host_device_with_status) override;
void SetReceivedNotifications(
const RepeatedPtrField<proto::Notification>& notification_protos);
void SetReceivedPhoneStatusModelStates(
const proto::PhoneProperties& phone_properties);
void MaybeSetPhoneModelName(
const base::Optional<multidevice::RemoteDeviceRef>& remote_device);
void SetDoNotDisturbState(proto::NotificationMode mode);
DoNotDisturbController* do_not_disturb_controller_;
FeatureStatusProvider* feature_status_provider_;
MessageReceiver* message_receiver_;
FindMyDeviceController* find_my_device_controller_;
NotificationAccessManager* notification_access_manager_;
NotificationManager* notification_manager_;
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client_;
MutablePhoneModel* phone_model_;
};
} // namespace phonehub
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PHONEHUB_PHONE_STATUS_PROCESSOR_H_
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment