Commit f22a9ed7 authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Move GetProfileIdFromLaunchId() to class NotificationLaunchId

The associated unit test is also moved.

Change-Id: Ia35c2873d8c40071f204fbecc064285ee3ed0ecf
Reviewed-on: https://chromium-review.googlesource.com/c/1277373
Commit-Queue: Xi Cheng <chengx@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598910}
parent 117ee57c
...@@ -875,16 +875,6 @@ bool NotificationPlatformBridgeWin::HandleActivation( ...@@ -875,16 +875,6 @@ bool NotificationPlatformBridgeWin::HandleActivation(
return true; return true;
} }
// static
std::string NotificationPlatformBridgeWin::GetProfileIdFromLaunchId(
const base::string16& launch_id_str) {
NotificationLaunchId launch_id(base::UTF16ToUTF8(launch_id_str));
// The launch_id_invalid failure is logged via HandleActivation(). We don't
// re-log it here, which would skew the UMA failure metrics.
return launch_id.is_valid() ? launch_id.profile_id() : std::string();
}
// static // static
bool NotificationPlatformBridgeWin::NativeNotificationEnabled() { bool NotificationPlatformBridgeWin::NativeNotificationEnabled() {
// Windows 10 native notification seems to have memory leak issues on OS // Windows 10 native notification seems to have memory leak issues on OS
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/string16.h"
#include "chrome/browser/notifications/notification_platform_bridge.h" #include "chrome/browser/notifications/notification_platform_bridge.h"
namespace base { namespace base {
...@@ -46,10 +45,6 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge { ...@@ -46,10 +45,6 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge {
// notification-launch-id switch. // notification-launch-id switch.
static bool HandleActivation(const base::CommandLine& command_line); static bool HandleActivation(const base::CommandLine& command_line);
// Extracts the profile ID from |launch_id_str|.
static std::string GetProfileIdFromLaunchId(
const base::string16& launch_id_str);
// Checks if native notification is enabled. // Checks if native notification is enabled.
static bool NativeNotificationEnabled(); static bool NativeNotificationEnabled();
......
...@@ -261,15 +261,3 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) { ...@@ -261,15 +261,3 @@ TEST_F(NotificationPlatformBridgeWinTest, Suppress) {
notification_platform_bridge_win_->SetDisplayedNotificationsForTesting( notification_platform_bridge_win_->SetDisplayedNotificationsForTesting(
nullptr); nullptr);
} }
TEST_F(NotificationPlatformBridgeWinTest, GetProfileIdFromLaunchId) {
// Given a valid launch id, the profile id can be obtained correctly.
ASSERT_EQ(NotificationPlatformBridgeWin::GetProfileIdFromLaunchId(
L"1|1|0|Default|0|https://example.com/|notification_id"),
"Default");
// Given an invalid launch id, the profile id is set to an empty string.
ASSERT_EQ(NotificationPlatformBridgeWin::GetProfileIdFromLaunchId(
L"1|Default|0|https://example.com/|notification_id"),
"");
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
namespace { namespace {
...@@ -165,3 +166,13 @@ std::string NotificationLaunchId::Serialize() const { ...@@ -165,3 +166,13 @@ std::string NotificationLaunchId::Serialize() const {
static_cast<int>(notification_type_), profile_id_.c_str(), incognito_, static_cast<int>(notification_type_), profile_id_.c_str(), incognito_,
origin_url_.spec().c_str(), notification_id_.c_str()); origin_url_.spec().c_str(), notification_id_.c_str());
} }
// static
std::string NotificationLaunchId::GetProfileIdFromLaunchId(
const base::string16& launch_id_str) {
NotificationLaunchId launch_id(base::UTF16ToUTF8(launch_id_str));
// The launch_id_invalid failure is logged via HandleActivation(). We don't
// re-log it here, which would skew the UMA failure metrics.
return launch_id.is_valid() ? launch_id.profile_id() : std::string();
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_ #ifndef CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_
#define CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_ #define CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_
#include "base/strings/string16.h"
#include "chrome/browser/notifications/notification_handler.h" #include "chrome/browser/notifications/notification_handler.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -90,6 +91,10 @@ class NotificationLaunchId { ...@@ -90,6 +91,10 @@ class NotificationLaunchId {
return is_for_dismiss_button_; return is_for_dismiss_button_;
} }
// Extracts the profile ID from |launch_id_str|.
static std::string GetProfileIdFromLaunchId(
const base::string16& launch_id_str);
private: private:
// The notification type this launch ID is associated with. // The notification type this launch ID is associated with.
NotificationHandler::Type notification_type_; NotificationHandler::Type notification_type_;
......
...@@ -183,3 +183,15 @@ TEST(NotificationLaunchIdTest, ParsingErrorCases) { ...@@ -183,3 +183,15 @@ TEST(NotificationLaunchIdTest, ParsingErrorCases) {
EXPECT_FALSE(id.is_valid()); EXPECT_FALSE(id.is_valid());
} }
} }
TEST(NotificationLaunchIdTest, GetProfileIdFromLaunchId) {
// Given a valid launch id, the profile id can be obtained correctly.
ASSERT_EQ(NotificationLaunchId::GetProfileIdFromLaunchId(
L"1|1|0|Default|0|https://example.com/|notification_id"),
"Default");
// Given an invalid launch id, the profile id is set to an empty string.
ASSERT_EQ(NotificationLaunchId::GetProfileIdFromLaunchId(
L"1|Default|0|https://example.com/|notification_id"),
"");
}
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/metrics/jumplist_metrics_win.h" #include "chrome/browser/metrics/jumplist_metrics_win.h"
#include "chrome/browser/notifications/notification_platform_bridge_win.h" #include "chrome/browser/notifications/win/notification_launch_id.h"
#include "chrome/browser/ui/webui/settings/reset_settings_handler.h" #include "chrome/browser/ui/webui/settings/reset_settings_handler.h"
#endif #endif
...@@ -965,9 +965,8 @@ base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, ...@@ -965,9 +965,8 @@ base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir,
// all others. // all others.
#if defined(OS_WIN) #if defined(OS_WIN)
if (command_line.HasSwitch(switches::kNotificationLaunchId)) { if (command_line.HasSwitch(switches::kNotificationLaunchId)) {
std::string profile_id = std::string profile_id = NotificationLaunchId::GetProfileIdFromLaunchId(
NotificationPlatformBridgeWin::GetProfileIdFromLaunchId( command_line.GetSwitchValueNative(switches::kNotificationLaunchId));
command_line.GetSwitchValueNative(switches::kNotificationLaunchId));
if (!profile_id.empty()) { if (!profile_id.empty()) {
return user_data_dir.Append( return user_data_dir.Append(
base::FilePath(base::UTF8ToUTF16(profile_id))); base::FilePath(base::UTF8ToUTF16(profile_id)));
......
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