Commit 96734430 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Add a Cancel button to remote copy notifications

This allows users to cancel downloading images.

Bug: 1059290
Change-Id: I5eeaf6ddecc22c28021161a15e61f6467b418bd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096759
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749420}
parent 34e411ac
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
#include "chrome/browser/sharing/proto/sharing_message.pb.h" #include "chrome/browser/sharing/proto/sharing_message.pb.h"
#include "chrome/browser/sharing/shared_clipboard/feature_flags.h" #include "chrome/browser/sharing/shared_clipboard/feature_flags.h"
#include "chrome/browser/sharing/sharing_metrics.h" #include "chrome/browser/sharing/sharing_metrics.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -154,10 +157,7 @@ void RemoteCopyMessageHandler::OnMessage( ...@@ -154,10 +157,7 @@ void RemoteCopyMessageHandler::OnMessage(
// First cancel any pending async tasks that might otherwise overwrite the // First cancel any pending async tasks that might otherwise overwrite the
// results of the more recent message. // results of the more recent message.
url_loader_.reset(); CancelAsyncTasks();
ImageDecoder::Cancel(this);
resize_callback_.Cancel();
write_detection_timer_.AbandonAndStop();
device_name_ = message.sender_device_name(); device_name_ = message.sender_device_name();
...@@ -291,8 +291,17 @@ void RemoteCopyMessageHandler::OnImageDownloadProgress(uint64_t current) { ...@@ -291,8 +291,17 @@ void RemoteCopyMessageHandler::OnImageDownloadProgress(uint64_t current) {
void RemoteCopyMessageHandler::UpdateProgressNotification( void RemoteCopyMessageHandler::UpdateProgressNotification(
const base::string16& context) { const base::string16& context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (image_notification_id_.empty()) if (image_notification_id_.empty()) {
image_notification_id_ = base::GenerateGUID(); image_notification_id_ = base::GenerateGUID();
// base::Unretained is safe as the SharingService owns |this| via the
// SharingHandlerRegistry and also the passed callback.
SharingServiceFactory::GetForBrowserContext(profile_)
->SetNotificationActionHandler(
image_notification_id_,
base::BindRepeating(
&RemoteCopyMessageHandler::OnProgressNotificationAction,
base::Unretained(this)));
}
message_center::RichNotificationData rich_notification_data; message_center::RichNotificationData rich_notification_data;
rich_notification_data.vector_small_image = &kSendTabToSelfIcon; rich_notification_data.vector_small_image = &kSendTabToSelfIcon;
...@@ -307,7 +316,13 @@ void RemoteCopyMessageHandler::UpdateProgressNotification( ...@@ -307,7 +316,13 @@ void RemoteCopyMessageHandler::UpdateProgressNotification(
/*display_source=*/base::string16(), /*display_source=*/base::string16(),
/*origin_url=*/GURL(), message_center::NotifierId(), /*origin_url=*/GURL(), message_center::NotifierId(),
rich_notification_data, rich_notification_data,
base::MakeRefCounted<message_center::NotificationDelegate>()); /*delegate=*/nullptr);
std::vector<message_center::ButtonInfo> notification_actions;
message_center::ButtonInfo button_info =
message_center::ButtonInfo(l10n_util::GetStringUTF16(IDS_CANCEL));
notification_actions.push_back(button_info);
notification.set_buttons(notification_actions);
if (image_content_length_ <= 0) { if (image_content_length_ <= 0) {
// TODO(knollr): Show transfer status if |image_content_progress_| is != 0. // TODO(knollr): Show transfer status if |image_content_progress_| is != 0.
...@@ -323,7 +338,7 @@ void RemoteCopyMessageHandler::UpdateProgressNotification( ...@@ -323,7 +338,7 @@ void RemoteCopyMessageHandler::UpdateProgressNotification(
} }
NotificationDisplayServiceFactory::GetForProfile(profile_)->Display( NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
NotificationHandler::Type::TRANSIENT, notification, /*metadata=*/nullptr); NotificationHandler::Type::SHARING, notification, /*metadata=*/nullptr);
// Unretained(this) is safe here because |this| owns // Unretained(this) is safe here because |this| owns
// |image_download_update_progress_timer_|. // |image_download_update_progress_timer_|.
...@@ -341,12 +356,41 @@ void RemoteCopyMessageHandler::CancelProgressNotification() { ...@@ -341,12 +356,41 @@ void RemoteCopyMessageHandler::CancelProgressNotification() {
if (image_notification_id_.empty()) if (image_notification_id_.empty())
return; return;
SharingServiceFactory::GetForBrowserContext(profile_)
->SetNotificationActionHandler(image_notification_id_,
base::NullCallback());
NotificationDisplayServiceFactory::GetForProfile(profile_)->Close( NotificationDisplayServiceFactory::GetForProfile(profile_)->Close(
NotificationHandler::Type::SHARING, image_notification_id_); NotificationHandler::Type::SHARING, image_notification_id_);
image_notification_id_.clear(); image_notification_id_.clear();
} }
void RemoteCopyMessageHandler::OnProgressNotificationAction(
base::Optional<int> button,
bool closed) {
// Clicks on the progress notification body are ignored.
if (!closed && !button)
return;
// Stop updating the progress notification.
image_download_update_progress_timer_.AbandonAndStop();
// Let the download continue if the notification was dismissed.
if (closed) {
// Remove the handler as this notification is now closed.
SharingServiceFactory::GetForBrowserContext(profile_)
->SetNotificationActionHandler(image_notification_id_,
base::NullCallback());
// The notification will be closed by the framework after this.
image_notification_id_.clear();
return;
}
// Cancel the download if the cancel button was pressed.
DCHECK_EQ(0, *button);
CancelAsyncTasks();
}
void RemoteCopyMessageHandler::OnURLLoadComplete( void RemoteCopyMessageHandler::OnURLLoadComplete(
std::unique_ptr<std::string> content) { std::unique_ptr<std::string> content) {
TRACE_EVENT0("sharing", "RemoteCopyMessageHandler::OnURLLoadComplete"); TRACE_EVENT0("sharing", "RemoteCopyMessageHandler::OnURLLoadComplete");
...@@ -451,9 +495,14 @@ void RemoteCopyMessageHandler::WriteImageAndShowNotification( ...@@ -451,9 +495,14 @@ void RemoteCopyMessageHandler::WriteImageAndShowNotification(
base::TimeTicks::Now(), /*is_image=*/true)); base::TimeTicks::Now(), /*is_image=*/true));
std::string notification_id = image_notification_id_; std::string notification_id = image_notification_id_;
if (notification_id.empty()) if (notification_id.empty()) {
notification_id = base::GenerateGUID(); notification_id = base::GenerateGUID();
image_notification_id_.clear(); } else {
SharingServiceFactory::GetForBrowserContext(profile_)
->SetNotificationActionHandler(image_notification_id_,
base::NullCallback());
image_notification_id_.clear();
}
ShowNotification(GetImageNotificationTitle(device_name_), resized_image, ShowNotification(GetImageNotificationTitle(device_name_), resized_image,
notification_id); notification_id);
...@@ -524,3 +573,12 @@ void RemoteCopyMessageHandler::Finish(RemoteCopyHandleMessageResult result) { ...@@ -524,3 +573,12 @@ void RemoteCopyMessageHandler::Finish(RemoteCopyHandleMessageResult result) {
LogRemoteCopyHandleMessageResult(result); LogRemoteCopyHandleMessageResult(result);
device_name_.clear(); device_name_.clear();
} }
void RemoteCopyMessageHandler::CancelAsyncTasks() {
url_loader_.reset();
ImageDecoder::Cancel(this);
resize_callback_.Cancel();
write_detection_timer_.AbandonAndStop();
image_download_update_progress_timer_.AbandonAndStop();
CancelProgressNotification();
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/cancelable_callback.h" #include "base/cancelable_callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/timer/elapsed_timer.h" #include "base/timer/elapsed_timer.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -51,6 +52,7 @@ class RemoteCopyMessageHandler : public SharingMessageHandler, ...@@ -51,6 +52,7 @@ class RemoteCopyMessageHandler : public SharingMessageHandler,
void OnImageDownloadProgress(uint64_t current); void OnImageDownloadProgress(uint64_t current);
void UpdateProgressNotification(const base::string16& context); void UpdateProgressNotification(const base::string16& context);
void CancelProgressNotification(); void CancelProgressNotification();
void OnProgressNotificationAction(base::Optional<int> button, bool closed);
void OnURLLoadComplete(std::unique_ptr<std::string> content); void OnURLLoadComplete(std::unique_ptr<std::string> content);
void WriteImageAndShowNotification(const SkBitmap& original_image, void WriteImageAndShowNotification(const SkBitmap& original_image,
const SkBitmap& resized_image); const SkBitmap& resized_image);
...@@ -61,6 +63,7 @@ class RemoteCopyMessageHandler : public SharingMessageHandler, ...@@ -61,6 +63,7 @@ class RemoteCopyMessageHandler : public SharingMessageHandler,
base::TimeTicks start_ticks, base::TimeTicks start_ticks,
bool is_image); bool is_image);
void Finish(RemoteCopyHandleMessageResult result); void Finish(RemoteCopyHandleMessageResult result);
void CancelAsyncTasks();
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
std::unique_ptr<network::SimpleURLLoader> url_loader_; std::unique_ptr<network::SimpleURLLoader> url_loader_;
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/notifications/notification_display_service_tester.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/sharing/mock_sharing_service.h"
#include "chrome/browser/sharing/proto/remote_copy_message.pb.h" #include "chrome/browser/sharing/proto/remote_copy_message.pb.h"
#include "chrome/browser/sharing/proto/sharing_message.pb.h" #include "chrome/browser/sharing/proto/sharing_message.pb.h"
#include "chrome/browser/sharing/shared_clipboard/feature_flags.h" #include "chrome/browser/sharing/shared_clipboard/feature_flags.h"
#include "chrome/browser/sharing/shared_clipboard/remote_copy_handle_message_result.h" #include "chrome/browser/sharing/shared_clipboard/remote_copy_handle_message_result.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/sync/protocol/sync_enums.pb.h" #include "components/sync/protocol/sync_enums.pb.h"
...@@ -48,6 +50,11 @@ class RemoteCopyMessageHandlerTest : public SharedClipboardTestBase { ...@@ -48,6 +50,11 @@ class RemoteCopyMessageHandlerTest : public SharedClipboardTestBase {
void SetUp() override { void SetUp() override {
SharedClipboardTestBase::SetUp(); SharedClipboardTestBase::SetUp();
SharingServiceFactory::GetInstance()->SetTestingFactory(
&profile_, base::BindRepeating([](content::BrowserContext* context)
-> std::unique_ptr<KeyedService> {
return std::make_unique<testing::NiceMock<MockSharingService>>();
}));
message_handler_ = std::make_unique<RemoteCopyMessageHandler>(&profile_); message_handler_ = std::make_unique<RemoteCopyMessageHandler>(&profile_);
} }
...@@ -243,6 +250,9 @@ TEST_F(RemoteCopyMessageHandlerTest, ImageNotificationWithProgressFlag) { ...@@ -243,6 +250,9 @@ TEST_F(RemoteCopyMessageHandlerTest, ImageNotificationWithProgressFlag) {
// download. // download.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
// After finishing the transfer there should be no progress notification.
EXPECT_FALSE(HasProgressNotification());
// Expect the image to be in the clipboard now. // Expect the image to be in the clipboard now.
SkBitmap image = GetClipboardImage(); SkBitmap image = GetClipboardImage();
EXPECT_TRUE(gfx::BitmapsAreEqual(*image_, image)); EXPECT_TRUE(gfx::BitmapsAreEqual(*image_, image));
...@@ -251,3 +261,54 @@ TEST_F(RemoteCopyMessageHandlerTest, ImageNotificationWithProgressFlag) { ...@@ -251,3 +261,54 @@ TEST_F(RemoteCopyMessageHandlerTest, ImageNotificationWithProgressFlag) {
auto notification = GetImageNotification(); auto notification = GetImageNotification();
EXPECT_FALSE(notification.image().IsEmpty()); EXPECT_FALSE(notification.image().IsEmpty());
} }
TEST_F(RemoteCopyMessageHandlerTest, CancelProgressNotification) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeaturesAndParameters(
{{kRemoteCopyReceiver, {{kRemoteCopyAllowedOrigins.name, kTestImageUrl}}},
{kRemoteCopyProgressNotification, {}}},
{});
message_handler_->OnMessage(CreateMessageWithImage(kTestImageUrl),
base::DoNothing());
auto notification = GetProgressNotification();
// Simulate a click on the cancel button at index 0.
notification_tester_->SimulateClick(NotificationHandler::Type::SHARING,
notification.id(), /*action_index=*/0,
/*reply=*/base::nullopt);
// The progress notification should now be closed.
EXPECT_FALSE(HasProgressNotification());
// Run remaining tasks to ensure no notification is shown at the end.
task_environment_.RunUntilIdle();
EXPECT_FALSE(HasProgressNotification());
EXPECT_FALSE(HasImageNotification());
}
TEST_F(RemoteCopyMessageHandlerTest, DismissProgressNotification) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeaturesAndParameters(
{{kRemoteCopyReceiver, {{kRemoteCopyAllowedOrigins.name, kTestImageUrl}}},
{kRemoteCopyProgressNotification, {}}},
{});
message_handler_->OnMessage(CreateMessageWithImage(kTestImageUrl),
base::DoNothing());
auto notification = GetProgressNotification();
// Simulate closing the notification by the user.
notification_tester_->RemoveNotification(NotificationHandler::Type::SHARING,
notification.id(), /*by_user=*/true,
/*silent=*/false);
// The progress notification should now be closed.
EXPECT_FALSE(HasProgressNotification());
// Let tasks run until the image is decoded and written to the clipboard.
task_environment_.RunUntilIdle();
EXPECT_TRUE(HasImageNotification());
}
...@@ -51,9 +51,18 @@ SkBitmap SharedClipboardTestBase::GetClipboardImage() { ...@@ -51,9 +51,18 @@ SkBitmap SharedClipboardTestBase::GetClipboardImage() {
ui::ClipboardBuffer::kCopyPaste); ui::ClipboardBuffer::kCopyPaste);
} }
bool SharedClipboardTestBase::HasImageNotification() {
auto notifications = notification_tester_->GetDisplayedNotificationsForType(
NotificationHandler::Type::SHARING);
if (notifications.size() != 1u)
return false;
return notifications[0].type() == message_center::NOTIFICATION_TYPE_IMAGE;
}
bool SharedClipboardTestBase::HasProgressNotification() { bool SharedClipboardTestBase::HasProgressNotification() {
auto notifications = notification_tester_->GetDisplayedNotificationsForType( auto notifications = notification_tester_->GetDisplayedNotificationsForType(
NotificationHandler::Type::TRANSIENT); NotificationHandler::Type::SHARING);
if (notifications.size() != 1u) if (notifications.size() != 1u)
return false; return false;
...@@ -74,7 +83,7 @@ message_center::Notification SharedClipboardTestBase::GetNotification() { ...@@ -74,7 +83,7 @@ message_center::Notification SharedClipboardTestBase::GetNotification() {
message_center::Notification message_center::Notification
SharedClipboardTestBase::GetProgressNotification() { SharedClipboardTestBase::GetProgressNotification() {
auto notifications = notification_tester_->GetDisplayedNotificationsForType( auto notifications = notification_tester_->GetDisplayedNotificationsForType(
NotificationHandler::Type::TRANSIENT); NotificationHandler::Type::SHARING);
EXPECT_EQ(notifications.size(), 1u); EXPECT_EQ(notifications.size(), 1u);
const message_center::Notification& notification = notifications[0]; const message_center::Notification& notification = notifications[0];
......
...@@ -41,6 +41,7 @@ class SharedClipboardTestBase : public testing::Test { ...@@ -41,6 +41,7 @@ class SharedClipboardTestBase : public testing::Test {
std::string GetClipboardText(); std::string GetClipboardText();
SkBitmap GetClipboardImage(); SkBitmap GetClipboardImage();
bool HasImageNotification();
bool HasProgressNotification(); bool HasProgressNotification();
message_center::Notification GetNotification(); message_center::Notification GetNotification();
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "chrome/browser/notifications/notification_display_service.h" #include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_display_service_factory.h" #include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sharing/sharing_service.h"
#include "chrome/browser/sharing/sharing_service_factory.h"
SharingNotificationHandler::SharingNotificationHandler() = default; SharingNotificationHandler::SharingNotificationHandler() = default;
SharingNotificationHandler::~SharingNotificationHandler() = default; SharingNotificationHandler::~SharingNotificationHandler() = default;
...@@ -19,8 +22,27 @@ void SharingNotificationHandler::OnClick( ...@@ -19,8 +22,27 @@ void SharingNotificationHandler::OnClick(
const base::Optional<int>& action_index, const base::Optional<int>& action_index,
const base::Optional<base::string16>& reply, const base::Optional<base::string16>& reply,
base::OnceClosure completed_closure) { base::OnceClosure completed_closure) {
NotificationDisplayServiceFactory::GetForProfile(profile)->Close( auto handler = SharingServiceFactory::GetForBrowserContext(profile)
NotificationHandler::Type::SHARING, notification_id); ->GetNotificationActionHandler(notification_id);
if (handler) {
handler.Run(action_index, /*closed=*/false);
} else {
// Close the notification by default.
NotificationDisplayServiceFactory::GetForProfile(profile)->Close(
NotificationHandler::Type::SHARING, notification_id);
}
std::move(completed_closure).Run();
}
void SharingNotificationHandler::OnClose(Profile* profile,
const GURL& origin,
const std::string& notification_id,
bool by_user,
base::OnceClosure completed_closure) {
auto handler = SharingServiceFactory::GetForBrowserContext(profile)
->GetNotificationActionHandler(notification_id);
if (handler)
handler.Run(/*button=*/base::nullopt, /*closed=*/true);
std::move(completed_closure).Run(); std::move(completed_closure).Run();
} }
......
...@@ -5,15 +5,23 @@ ...@@ -5,15 +5,23 @@
#ifndef CHROME_BROWSER_SHARING_SHARING_NOTIFICATION_HANDLER_H_ #ifndef CHROME_BROWSER_SHARING_SHARING_NOTIFICATION_HANDLER_H_
#define CHROME_BROWSER_SHARING_SHARING_NOTIFICATION_HANDLER_H_ #define CHROME_BROWSER_SHARING_SHARING_NOTIFICATION_HANDLER_H_
#include <map>
#include <string> #include <string>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "chrome/browser/notifications/notification_handler.h" #include "chrome/browser/notifications/notification_handler.h"
#include "url/gurl.h"
class Profile;
// Handles SHARING nofication actions. // Handles SHARING nofication actions.
class SharingNotificationHandler : public NotificationHandler { class SharingNotificationHandler : public NotificationHandler {
public: public:
SharingNotificationHandler(); SharingNotificationHandler();
SharingNotificationHandler(const SharingNotificationHandler&) = delete;
SharingNotificationHandler& operator=(const SharingNotificationHandler&) =
delete;
~SharingNotificationHandler() override; ~SharingNotificationHandler() override;
// NotificationHandler implementation: // NotificationHandler implementation:
...@@ -23,10 +31,12 @@ class SharingNotificationHandler : public NotificationHandler { ...@@ -23,10 +31,12 @@ class SharingNotificationHandler : public NotificationHandler {
const base::Optional<int>& action_index, const base::Optional<int>& action_index,
const base::Optional<base::string16>& reply, const base::Optional<base::string16>& reply,
base::OnceClosure completed_closure) override; base::OnceClosure completed_closure) override;
void OnClose(Profile* profile,
const GURL& origin,
const std::string& notification_id,
bool by_user,
base::OnceClosure completed_closure) override;
void OpenSettings(Profile* profile, const GURL& origin) override; void OpenSettings(Profile* profile, const GURL& origin) override;
protected:
DISALLOW_COPY_AND_ASSIGN(SharingNotificationHandler);
}; };
#endif // CHROME_BROWSER_SHARING_SHARING_NOTIFICATION_HANDLER_H_ #endif // CHROME_BROWSER_SHARING_SHARING_NOTIFICATION_HANDLER_H_
\ No newline at end of file
...@@ -130,6 +130,24 @@ void SharingService::UnregisterSharingHandler( ...@@ -130,6 +130,24 @@ void SharingService::UnregisterSharingHandler(
handler_registry_->UnregisterSharingHandler(payload_case); handler_registry_->UnregisterSharingHandler(payload_case);
} }
void SharingService::SetNotificationActionHandler(
const std::string& notification_id,
NotificationActionCallback callback) {
if (callback)
notification_action_handlers_[notification_id] = callback;
else
notification_action_handlers_.erase(notification_id);
}
SharingService::NotificationActionCallback
SharingService::GetNotificationActionHandler(
const std::string& notification_id) const {
auto iter = notification_action_handlers_.find(notification_id);
return iter == notification_action_handlers_.end()
? NotificationActionCallback()
: iter->second;
}
SharingDeviceSource* SharingService::GetDeviceSource() const { SharingDeviceSource* SharingService::GetDeviceSource() const {
return device_source_.get(); return device_source_.get();
} }
......
...@@ -44,6 +44,8 @@ enum class SharingDeviceRegistrationResult; ...@@ -44,6 +44,8 @@ enum class SharingDeviceRegistrationResult;
class SharingService : public KeyedService, public syncer::SyncServiceObserver { class SharingService : public KeyedService, public syncer::SyncServiceObserver {
public: public:
using SharingDeviceList = std::vector<std::unique_ptr<syncer::DeviceInfo>>; using SharingDeviceList = std::vector<std::unique_ptr<syncer::DeviceInfo>>;
using NotificationActionCallback =
base::RepeatingCallback<void(base::Optional<int> button, bool closed)>;
enum class State { enum class State {
// Device is unregistered with FCM and Sharing is unavailable. // Device is unregistered with FCM and Sharing is unavailable.
...@@ -100,6 +102,18 @@ class SharingService : public KeyedService, public syncer::SyncServiceObserver { ...@@ -100,6 +102,18 @@ class SharingService : public KeyedService, public syncer::SyncServiceObserver {
void UnregisterSharingHandler( void UnregisterSharingHandler(
chrome_browser_sharing::SharingMessage::PayloadCase payload_case); chrome_browser_sharing::SharingMessage::PayloadCase payload_case);
// Sets a notification action handler for |notification_id|. Replaces any
// previously set handlers for |notification_id|. |callback| may be a null
// callback which clears the handler for |notification_id|.
void SetNotificationActionHandler(const std::string& notification_id,
NotificationActionCallback callback);
// Returns the notification action handler for |notification_id| set by
// SetNotificationActionHandler(). The returned callback may be null if no
// handler has been set before for |notification_id|.
NotificationActionCallback GetNotificationActionHandler(
const std::string& notification_id) const;
// Used to register devices with required capabilities in tests. // Used to register devices with required capabilities in tests.
void RegisterDeviceInTesting( void RegisterDeviceInTesting(
std::set<sync_pb::SharingSpecificFields_EnabledFeatures> enabled_features, std::set<sync_pb::SharingSpecificFields_EnabledFeatures> enabled_features,
...@@ -149,6 +163,10 @@ class SharingService : public KeyedService, public syncer::SyncServiceObserver { ...@@ -149,6 +163,10 @@ class SharingService : public KeyedService, public syncer::SyncServiceObserver {
SharingServiceProxyAndroid sharing_service_proxy_android_{this}; SharingServiceProxyAndroid sharing_service_proxy_android_{this};
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
// Map of notification id to notification handler callback.
std::map<std::string, NotificationActionCallback>
notification_action_handlers_;
base::WeakPtrFactory<SharingService> weak_ptr_factory_{this}; base::WeakPtrFactory<SharingService> weak_ptr_factory_{this};
}; };
......
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