1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
ash / system / phonehub / phone_hub_notification_controller.h [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_
#define ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "ash/ash_export.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/phonehub/camera_roll_manager.h"
#include "chromeos/ash/components/phonehub/feature_status_provider.h"
#include "chromeos/ash/components/phonehub/notification_manager.h"
#include "chromeos/ash/components/phonehub/tether_controller.h"
namespace message_center {
class MessageView;
class Notification;
} // namespace message_center
namespace ash {
namespace phonehub {
class Notification;
class NotificationInteractionHandler;
class PhoneHubManager;
class PhoneModel;
namespace proto {
class CameraRollItemMetadata;
} // namespace proto
} // namespace phonehub
// This controller creates and manages a message_center::Notification for each
// PhoneHub corresponding notification.
class ASH_EXPORT PhoneHubNotificationController
: public phonehub::CameraRollManager::Observer,
public phonehub::NotificationManager::Observer,
public phonehub::TetherController::Observer {
public:
PhoneHubNotificationController();
~PhoneHubNotificationController() override;
PhoneHubNotificationController(const PhoneHubNotificationController&) =
delete;
PhoneHubNotificationController& operator=(
const PhoneHubNotificationController&) = delete;
// Sets the NotifictionManager that provides the underlying PhoneHub
// notifications.
void SetManager(phonehub::PhoneHubManager* phone_hub_manager);
const std::u16string GetPhoneName() const;
private:
FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
CustomActionRowExpanded);
FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
ReplyBrieflyDisabled);
FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
NotificationHasPhoneName);
class NotificationDelegate;
// phonehub::NotificationManager::Observer:
void OnNotificationsAdded(
const base::flat_set<int64_t>& notification_ids) override;
void OnNotificationsUpdated(
const base::flat_set<int64_t>& notification_ids) override;
void OnNotificationsRemoved(
const base::flat_set<int64_t>& notification_ids) override;
// phonehub::TetherController::Observer:
void OnAttemptConnectionScanFailed() override;
void OnTetherStatusChanged() override {}
// phonehub::CameraRollManager::Observer:
void OnCameraRollDownloadError(
DownloadErrorType error_type,
const phonehub::proto::CameraRollItemMetadata& metadata) override;
// Helper functions for creating Camera Roll notifications
std::unique_ptr<message_center::Notification>
CreateCameraRollGenericNotification(
const phonehub::proto::CameraRollItemMetadata& metadata);
std::unique_ptr<message_center::Notification>
CreateCameraRollStorageNotification(
const phonehub::proto::CameraRollItemMetadata& metadata);
std::unique_ptr<message_center::Notification>
CreateCameraRollNetworkNotification(
const phonehub::proto::CameraRollItemMetadata& metadata);
// Callbacks for user interactions.
void OpenSettings();
void DismissNotification(int64_t notification_id);
void HandleNotificationBodyClick(
int64_t notification_id,
const phonehub::Notification::AppMetadata& app_metadata);
void SendInlineReply(int64_t notification_id,
const std::u16string& inline_reply_text);
// Logs the number of PhoneHub notifications.
void LogNotificationCount();
// Shows a Chrome OS notification for the provided phonehub::Notification.
// If |is_update| is true, this function updates an existing notification;
// otherwise, a new notification is created.
void SetNotification(const phonehub::Notification* notification,
bool is_update);
// Creates a message_center::Notification from the PhoneHub notification data.
std::unique_ptr<message_center::Notification> CreateNotification(
const phonehub::Notification* notification,
const std::string& cros_id,
NotificationDelegate* delegate,
bool is_update);
int GetSystemPriorityForNotification(
const phonehub::Notification* notification,
bool is_update);
static std::unique_ptr<message_center::MessageView>
CreateCustomNotificationView(
base::WeakPtr<PhoneHubNotificationController> notification_controller,
const message_center::Notification& notification,
bool shown_in_popup);
static std::unique_ptr<message_center::MessageView>
CreateCustomActionNotificationView(
base::WeakPtr<PhoneHubNotificationController> notification_controller,
const message_center::Notification& notification,
bool shown_in_popup);
raw_ptr<phonehub::NotificationInteractionHandler>
notification_interaction_handler_ = nullptr;
raw_ptr<phonehub::NotificationManager> manager_ = nullptr;
raw_ptr<phonehub::TetherController> tether_controller_ = nullptr;
raw_ptr<phonehub::CameraRollManager> camera_roll_manager_ = nullptr;
raw_ptr<phonehub::PhoneModel> phone_model_ = nullptr;
std::unordered_map<int64_t, std::unique_ptr<NotificationDelegate>>
notification_map_;
base::WeakPtrFactory<PhoneHubNotificationController> weak_ptr_factory_{this};
};
} // namespace ash
#endif // ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_