Commit cd9bd929 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Prefetch notification service]: Init setup.

- Setup prefetch notification service, factory and client code.

Bug: 1047037
Change-Id: Iccc82d8b49f63213294eb0440fc59138db756912
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2029293
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Auto-Submit: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738697}
parent 46903fcd
...@@ -2856,6 +2856,10 @@ jumbo_static_library("browser") { ...@@ -2856,6 +2856,10 @@ jumbo_static_library("browser") {
"notifications/scheduler/display_agent_android.h", "notifications/scheduler/display_agent_android.h",
"notifications/scheduler/notification_background_task_scheduler_android.cc", "notifications/scheduler/notification_background_task_scheduler_android.cc",
"notifications/scheduler/notification_background_task_scheduler_android.h", "notifications/scheduler/notification_background_task_scheduler_android.h",
"offline_pages/prefetch/notifications/prefetch_notification_client.cc",
"offline_pages/prefetch/notifications/prefetch_notification_client.h",
"offline_pages/prefetch/notifications/prefetch_notification_service_factory.cc",
"offline_pages/prefetch/notifications/prefetch_notification_service_factory.h",
"page_load_metrics/observers/android_page_load_metrics_observer.cc", "page_load_metrics/observers/android_page_load_metrics_observer.cc",
"page_load_metrics/observers/android_page_load_metrics_observer.h", "page_load_metrics/observers/android_page_load_metrics_observer.h",
"password_manager/account_chooser_dialog_android.cc", "password_manager/account_chooser_dialog_android.cc",
...@@ -2967,6 +2971,7 @@ jumbo_static_library("browser") { ...@@ -2967,6 +2971,7 @@ jumbo_static_library("browser") {
"//chrome/browser/android/webapk:proto", "//chrome/browser/android/webapk:proto",
"//chrome/browser/notifications/chime/android", "//chrome/browser/notifications/chime/android",
"//chrome/browser/notifications/scheduler/public", "//chrome/browser/notifications/scheduler/public",
"//chrome/browser/offline_pages/prefetch/notifications",
"//chrome/browser/share", "//chrome/browser/share",
"//chrome/browser/updates", "//chrome/browser/updates",
"//chrome/services/media_gallery_util/public/cpp", "//chrome/services/media_gallery_util/public/cpp",
......
# Copyright 2020 The Chromium Authors.All rights reserved.
# Use of this source code is governed by a BSD - style license that can be
# found in the LICENSE file.
source_set("notifications") {
sources = [
"prefetch_notification_service.h",
"prefetch_notification_service_impl.cc",
"prefetch_notification_service_impl.h",
]
deps = [
"//base",
"//chrome/browser/notifications/scheduler/public",
"//components/keyed_service/content",
"//components/keyed_service/core",
"//skia",
]
}
include_rules = [
"+chrome/android/chrome_jni_headers",
]
hesen@chromium.org
dtrainor@chromium.org
xingliu@chromium.org
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/offline_pages/prefetch/notifications/prefetch_notification_client.h"
#include <utility>
#include "chrome/browser/offline_pages/prefetch/notifications/prefetch_notification_service.h"
namespace offline_pages {
PrefetchNotificationClient::PrefetchNotificationClient(
GetServiceCallback callback)
: get_service_callback_(std::move(callback)) {}
PrefetchNotificationClient::~PrefetchNotificationClient() = default;
void PrefetchNotificationClient::BeforeShowNotification(
std::unique_ptr<NotificationData> notification_data,
NotificationDataCallback callback) {
NOTIMPLEMENTED();
}
void PrefetchNotificationClient::OnSchedulerInitialized(
bool success,
std::set<std::string> guid) {
NOTIMPLEMENTED();
}
void PrefetchNotificationClient::OnUserAction(
const UserActionData& action_data) {
NOTIMPLEMENTED();
}
} // namespace offline_pages
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_CLIENT_H_
#define CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_CLIENT_H_
#include <memory>
#include <set>
#include <string>
#include "base/bind.h"
#include "chrome/browser/notifications/scheduler/public/notification_scheduler_client.h"
namespace offline_pages {
class PrefetchNotificationService;
// Client side code for offline prefetch notification, integrated with
// notification scheduler system.
class PrefetchNotificationClient
: public notifications::NotificationSchedulerClient {
public:
using NotificationData = notifications::NotificationData;
using UserActionData = notifications::UserActionData;
using GetServiceCallback =
base::RepeatingCallback<PrefetchNotificationService*()>;
explicit PrefetchNotificationClient(GetServiceCallback callback);
~PrefetchNotificationClient() override;
private:
// NotificationSchedulerClient implementation.
void BeforeShowNotification(
std::unique_ptr<NotificationData> notification_data,
NotificationDataCallback callback) override;
void OnSchedulerInitialized(bool success,
std::set<std::string> guids) override;
void OnUserAction(const UserActionData& action_data) override;
GetServiceCallback get_service_callback_;
DISALLOW_COPY_AND_ASSIGN(PrefetchNotificationClient);
};
} // namespace offline_pages
#endif // CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_CLIENT_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_H_
#define CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
namespace offline_pages {
// Service to manage offline prefetch notifications via
// notifications::NotificationScheduleService.
class PrefetchNotificationService : public KeyedService {
public:
~PrefetchNotificationService() override = default;
protected:
PrefetchNotificationService() = default;
private:
DISALLOW_COPY_AND_ASSIGN(PrefetchNotificationService);
};
} // namespace offline_pages
#endif // CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/offline_pages/prefetch/notifications/prefetch_notification_service_factory.h"
#include "chrome/browser/notifications/scheduler/notification_schedule_service_factory.h"
#include "chrome/browser/offline_pages/prefetch/notifications/prefetch_notification_service_impl.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
// static
PrefetchNotificationServiceFactory*
PrefetchNotificationServiceFactory::GetInstance() {
static base::NoDestructor<PrefetchNotificationServiceFactory> instance;
return instance.get();
}
// static
offline_pages::PrefetchNotificationService*
PrefetchNotificationServiceFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<offline_pages::PrefetchNotificationService*>(
GetInstance()->GetServiceForBrowserContext(context, true /* create */));
}
PrefetchNotificationServiceFactory::PrefetchNotificationServiceFactory()
: BrowserContextKeyedServiceFactory(
"offline_pages::PrefetchNotificationService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(NotificationScheduleServiceFactory::GetInstance());
}
KeyedService* PrefetchNotificationServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
auto* schedule_service =
NotificationScheduleServiceFactory::GetForBrowserContext(context);
return static_cast<KeyedService*>(
new offline_pages::PrefetchNotificationServiceImpl(schedule_service));
}
content::BrowserContext*
PrefetchNotificationServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
PrefetchNotificationServiceFactory::~PrefetchNotificationServiceFactory() =
default;
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_FACTORY_H_
#define CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_FACTORY_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace offline_pages {
class PrefetchNotificationService;
} // namespace offline_pages
class PrefetchNotificationServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static PrefetchNotificationServiceFactory* GetInstance();
static offline_pages::PrefetchNotificationService* GetForBrowserContext(
content::BrowserContext* context);
private:
friend class base::NoDestructor<PrefetchNotificationServiceFactory>;
// BrowserContextKeyedServiceFactory implementation.
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
PrefetchNotificationServiceFactory();
~PrefetchNotificationServiceFactory() override;
DISALLOW_COPY_AND_ASSIGN(PrefetchNotificationServiceFactory);
};
#endif // CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_FACTORY_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/offline_pages/prefetch/notifications/prefetch_notification_service_impl.h"
namespace offline_pages {
PrefetchNotificationServiceImpl::PrefetchNotificationServiceImpl(
notifications::NotificationScheduleService* schedule_service)
: schedule_service_(schedule_service) {
DCHECK(schedule_service_);
}
PrefetchNotificationServiceImpl::~PrefetchNotificationServiceImpl() = default;
} // namespace offline_pages
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_IMPL_H_
#define CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_IMPL_H_
#include "chrome/browser/offline_pages/prefetch/notifications/prefetch_notification_service.h"
#include <memory>
#include "base/memory/weak_ptr.h"
namespace notifications {
class NotificationScheduleService;
} // namespace notifications
namespace offline_pages {
// Service to manage offline prefetch notifications via
// notifications::NotificationScheduleService.
class PrefetchNotificationServiceImpl : public PrefetchNotificationService {
public:
PrefetchNotificationServiceImpl(
notifications::NotificationScheduleService* schedule_service);
~PrefetchNotificationServiceImpl() override;
private:
// Used to schedule notification to show in the future. Must outlive this
// class.
notifications::NotificationScheduleService* schedule_service_;
DISALLOW_COPY_AND_ASSIGN(PrefetchNotificationServiceImpl);
};
} // namespace offline_pages
#endif // CHROME_BROWSER_OFFLINE_PAGES_PREFETCH_NOTIFICATIONS_PREFETCH_NOTIFICATION_SERVICE_IMPL_H_
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