This migration has been effected in upstream, but several places in our codebase got broken by this transition. This change makes several parts of our codebase more friendly to passing `string_view`. Chromium changes: https://chromium.googlesource.com/chromium/src/+/0e1784e3cf990560b173f40338e582f50aba0e85 commit 0e1784e3cf990560b173f40338e582f50aba0e85 Author: Charlie Harrison <csharrison@chromium.org> Date: Fri Oct 3 11:04:26 2025 -0700 RELAND: Migrate GURL::path() and friends to return string_view This relands crrev.com/c/7003625. Missing cases were found by staring at the output of `git grep` for the whole codebase. Origin description: Also migrates some last remaining callers of the std::string APIs. This completes phase 1 of crbug.com/448174617. Bug: 448174617 Change-Id: I7f24f81d1fbf129d8b0dd94f4cf948626deab933 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7007010 Reviewed-by: Daniel Cheng <dcheng@chromium.org> Commit-Queue: Charlie Harrison <csharrison@chromium.org> Cr-Commit-Position: refs/heads/main@{#1524878}
90 lines
2.8 KiB
C++
90 lines
2.8 KiB
C++
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "brave/browser/notifications/ads_notification_handler.h"
|
|
|
|
#include <optional>
|
|
|
|
#include "base/check.h"
|
|
#include "brave/browser/brave_ads/ads_service_factory.h"
|
|
#include "brave/components/brave_ads/core/browser/service/ads_service.h"
|
|
#include "build/build_config.h"
|
|
#include "url/gurl.h"
|
|
|
|
namespace brave_ads {
|
|
|
|
namespace {
|
|
const void* const kUserDataKey = &kUserDataKey;
|
|
} // namespace
|
|
|
|
AdsNotificationHandler::AdsNotificationHandler(Profile& profile)
|
|
: profile_(profile) {}
|
|
|
|
AdsNotificationHandler::~AdsNotificationHandler() = default;
|
|
|
|
void AdsNotificationHandler::OnShow(Profile* profile, const std::string& id) {
|
|
AdsService* ads_service = AdsServiceFactory::GetForProfile(profile);
|
|
if (!ads_service) {
|
|
return;
|
|
}
|
|
|
|
did_click_notification_ad_ = false;
|
|
|
|
ads_service->OnNotificationAdShown(id);
|
|
}
|
|
|
|
void AdsNotificationHandler::OnClose(Profile* profile,
|
|
const GURL& origin,
|
|
const std::string& id,
|
|
const bool by_user,
|
|
base::OnceClosure completed_closure) {
|
|
AdsService* ads_service = AdsServiceFactory::GetForProfile(profile);
|
|
if (!ads_service) {
|
|
return;
|
|
}
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
|
if (did_click_notification_ad_) {
|
|
// On Linux, clicking the notification triggers both 'clicked' and 'closed'
|
|
// events. To avoid redundant event handling, we suppress the 'closed' event
|
|
// if the notification ad was clicked.
|
|
return;
|
|
}
|
|
#endif // BUILDFLAG(IS_LINUX)
|
|
|
|
ads_service->OnNotificationAdClosed(id, by_user);
|
|
}
|
|
|
|
void AdsNotificationHandler::OnClick(Profile* profile,
|
|
const GURL& origin,
|
|
const std::string& id,
|
|
const std::optional<int>& action_index,
|
|
const std::optional<std::u16string>& reply,
|
|
base::OnceClosure completed_closure) {
|
|
AdsService* ads_service = AdsServiceFactory::GetForProfile(profile);
|
|
if (!ads_service) {
|
|
return;
|
|
}
|
|
|
|
did_click_notification_ad_ = true;
|
|
|
|
ads_service->OnNotificationAdClicked(id);
|
|
}
|
|
|
|
void AdsNotificationHandler::OpenSettings(Profile* profile,
|
|
const GURL& origin) {
|
|
AdsService* ads_service = AdsServiceFactory::GetForProfile(profile);
|
|
if (!ads_service) {
|
|
return;
|
|
}
|
|
|
|
did_click_notification_ad_ = true;
|
|
|
|
CHECK(origin.has_query());
|
|
ads_service->OnNotificationAdClicked(std::string(origin.query()));
|
|
}
|
|
|
|
} // namespace brave_ads
|