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
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_TABS_SAVED_TAB_GROUPS_COLLABORATION_MESSAGING_OBSERVER_H_
#define CHROME_BROWSER_UI_TABS_SAVED_TAB_GROUPS_COLLABORATION_MESSAGING_OBSERVER_H_
#include <set>
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/uuid.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/instant_message_queue_processor.h"
#include "components/collaboration/public/messaging/messaging_backend_service.h"
#include "components/keyed_service/core/keyed_service.h"
class Profile;
namespace tab_groups {
using collaboration::messaging::InstantMessage;
using collaboration::messaging::MessagingBackendService;
using collaboration::messaging::PersistentMessage;
// Dictates the intended display status of the message.
enum class MessageDisplayStatus {
// The message should be displayed.
kDisplay,
// The message should be hidden.
kHide,
kMaxValue = kHide,
};
// This class is responsible for listener for and delivering messages from
// the MessagingBackendService for Desktop. Once the backend service has
// been initialized, this observer will query for any active (but
// previously undelivered) messages and populate the UI with various
// activity indicators.
class CollaborationMessagingObserver
: public MessagingBackendService::PersistentMessageObserver,
public MessagingBackendService::InstantMessageDelegate,
public KeyedService {
public:
explicit CollaborationMessagingObserver(Profile* profile);
CollaborationMessagingObserver(const CollaborationMessagingObserver&) =
delete;
CollaborationMessagingObserver& operator=(
const CollaborationMessagingObserver&) = delete;
~CollaborationMessagingObserver() override;
using InstantMessageSuccessCallback =
CollaborationMessagingObserver::InstantMessageDelegate::SuccessCallback;
// Testing-only method. Dispatch method as though it came from the
// backend service.
void DispatchMessageForTests(PersistentMessage message, bool display);
// Reopens the tab specified by the currently showing instant message.
// Called from the action button of the toast.
void ReopenTabForCurrentInstantMessage();
// Opens the manage sharing dialog for the group in the currently showing
// instant message. Called from the action button of the toast.
void ManageSharingForCurrentInstantMessage(
BrowserWindowInterface* current_browser_window_interface);
protected:
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
HandlesMessages);
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
HandlesTabMessagesInCollapsedGroup);
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
IgnoresTabMessagesWithIncompleteData);
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
InstantMessageReopensTab);
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
InstantMessageManagesSharing);
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
InstantMessageManagesSharingWithClosedGroup);
FRIEND_TEST_ALL_PREFIXES(CollaborationMessagingObserverBrowserTest,
InstantMessageForTabGroupRemoved);
// MessagingBackendService::PersistentMessageObserver
void OnMessagingBackendServiceInitialized() override;
void DisplayPersistentMessage(PersistentMessage message) override;
void HidePersistentMessage(PersistentMessage message) override;
// MessagingBackendService::InstantMessageDelegate
void DisplayInstantaneousMessage(
InstantMessage message,
InstantMessageSuccessCallback success_callback) override;
void HideInstantaneousMessage(
const std::set<base::Uuid>& message_ids) override;
private:
// Finds the tab group designated by this message and sets/hides an
// attention indicator on the tab group header.
void HandleDirtyTabGroup(PersistentMessage message,
MessageDisplayStatus display);
// Finds the tab designated by this message and sets/hides an attention
// indicator on the tab's icon.
void HandleDirtyTab(PersistentMessage message, MessageDisplayStatus display);
// Finds the tab designated by this message and sets/clears data in
// TabFeatures to be used by the tab's Hovercard and PageAction.
void HandleChip(PersistentMessage message, MessageDisplayStatus display);
// All messages this observer receives are routed through this method
// and dispatched to a handler. Treatment of the specific message is
// delegated to the appropriate handler for this type.
void DispatchMessage(PersistentMessage message, MessageDisplayStatus display);
raw_ptr<Profile> profile_;
InstantMessageQueueProcessor instant_message_queue_processor_;
raw_ptr<MessagingBackendService> service_;
// Observation for persistent messages.
base::ScopedObservation<MessagingBackendService,
MessagingBackendService::PersistentMessageObserver>
persistent_message_service_observation_{this};
};
} // namespace tab_groups
#endif // CHROME_BROWSER_UI_TABS_SAVED_TAB_GROUPS_COLLABORATION_MESSAGING_OBSERVER_H_
|