Commit 4693a267 authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Clean up notification_platform_bridge_win.{h,cc} and related tests

... mostly by removing the inclusion of redundant header files.

Bug: 734095
Change-Id: Ibed243cbdedba4499a6e62f2b79d31cdbf77b535
Reviewed-on: https://chromium-review.googlesource.com/989396Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Xi Cheng <chengx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548100}
parent fa0aceda
......@@ -4,26 +4,19 @@
#include "chrome/browser/notifications/notification_platform_bridge_win.h"
#include <NotificationActivationCallback.h>
#include <activation.h>
#include <wrl.h>
#include <memory>
#include <wrl/client.h>
#include <wrl/event.h>
#include <wrl/wrappers/corewrappers.h>
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/feature_list.h"
#include "base/hash.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_scheduler/post_task.h"
......@@ -46,13 +39,10 @@
#include "chrome/install_static/install_util.h"
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/shell_util.h"
#include "components/version_info/channel.h"
#include "content/public/browser/browser_thread.h"
#include "ui/message_center/public/cpp/notification.h"
namespace mswr = Microsoft::WRL;
namespace mswrw = Microsoft::WRL::Wrappers;
namespace winfoundtn = ABI::Windows::Foundation;
namespace winui = ABI::Windows::UI;
namespace winxml = ABI::Windows::Data::Xml;
......@@ -73,7 +63,7 @@ namespace {
// This string needs to be max 16 characters to work on Windows 10 prior to
// applying Creators Update (build 15063).
const wchar_t kGroup[] = L"Notifications";
constexpr wchar_t kGroup[] = L"Notifications";
typedef winfoundtn::ITypedEventHandler<
winui::Notifications::ToastNotification*,
......@@ -511,8 +501,9 @@ class NotificationPlatformBridgeWinImpl
continue;
}
if (launch_id.profile_id() != profile_id ||
launch_id.incognito() != incognito)
launch_id.incognito() != incognito) {
continue;
}
LogGetDisplayedLaunchIdStatus(GetDisplayedLaunchIdStatus::SUCCESS);
displayed_notifications->insert(launch_id.notification_id());
}
......@@ -593,9 +584,9 @@ class NotificationPlatformBridgeWinImpl
ScopedHString arguments_scoped(arguments);
NotificationLaunchId launch_id(arguments_scoped.GetAsUTF8());
if (!launch_id.is_valid() || launch_id.button_index() < 0)
return base::nullopt;
return launch_id.button_index();
return (launch_id.is_valid() && launch_id.button_index() >= 0)
? base::Optional<int>(launch_id.button_index())
: base::nullopt;
}
void ForwardHandleEventForTesting(
......@@ -879,9 +870,11 @@ bool NotificationPlatformBridgeWin::HandleActivation(
std::string NotificationPlatformBridgeWin::GetProfileIdFromLaunchId(
const base::string16& launch_id_str) {
NotificationLaunchId launch_id(base::UTF16ToUTF8(launch_id_str));
if (!launch_id.is_valid())
if (!launch_id.is_valid()) {
LogActivationStatus(ActivationStatus::GET_PROFILE_ID_INVALID_LAUNCH_ID);
return launch_id.is_valid() ? launch_id.profile_id() : std::string();
return std::string();
}
return launch_id.profile_id();
}
// static
......
......@@ -5,12 +5,13 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
#include <windows.ui.notifications.h>
#include <string>
#include <windows.ui.notifications.h>
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "chrome/browser/notifications/notification_platform_bridge.h"
namespace base {
......
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/win/scoped_hstring.h"
#include "base/win/windows_version.h"
#include "chrome/browser/browser_process.h"
......@@ -181,12 +182,11 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, HandleEvent) {
run_loop.Run();
// Validate the click values.
base::Optional<int> action_index = 1;
EXPECT_EQ(NotificationCommon::CLICK, last_operation_);
EXPECT_EQ(NotificationHandler::Type::WEB_PERSISTENT, last_notification_type_);
EXPECT_EQ(GURL("https://example.com/"), last_origin_);
EXPECT_EQ("notification_id", last_notification_id_);
EXPECT_EQ(action_index, last_action_index_);
EXPECT_EQ(base::Optional<int>(1), last_action_index_);
EXPECT_EQ(base::nullopt, last_reply_);
EXPECT_EQ(base::nullopt, last_by_user_);
}
......@@ -211,12 +211,11 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, HandleActivation) {
run_loop.Run();
// Validate the values.
base::Optional<int> action_index = 1;
EXPECT_EQ(NotificationCommon::CLICK, last_operation_);
EXPECT_EQ(NotificationHandler::Type::WEB_PERSISTENT, last_notification_type_);
EXPECT_EQ(GURL("https://example.com/"), last_origin_);
EXPECT_EQ("notification_id", last_notification_id_);
EXPECT_EQ(action_index, last_action_index_);
EXPECT_EQ(base::Optional<int>(1), last_action_index_);
EXPECT_EQ(base::nullopt, last_reply_);
EXPECT_EQ(true, last_by_user_);
}
......
......@@ -4,13 +4,14 @@
#include "chrome/browser/notifications/notification_platform_bridge_win.h"
#include <memory>
#include <windows.ui.notifications.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
#include <memory>
#include "base/hash.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
......@@ -34,10 +35,11 @@ using message_center::Notification;
namespace {
const char kLaunchId[] = "0|0|Default|0|https://example.com/|notification_id";
const char kOrigin[] = "https://www.google.com/";
const char kNotificationId[] = "id";
const char kProfileId[] = "Default";
constexpr char kLaunchId[] =
"0|0|Default|0|https://example.com/|notification_id";
constexpr char kOrigin[] = "https://www.google.com/";
constexpr char kNotificationId[] = "id";
constexpr char kProfileId[] = "Default";
} // namespace
......
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