File: schedule_service_factory_helper.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 5,978 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/notifications/scheduler/schedule_service_factory_helper.h"

#include <utility>
#include <vector>

#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/default_clock.h"
#include "chrome/browser/notifications/scheduler/internal/background_task_coordinator.h"
#include "chrome/browser/notifications/scheduler/internal/display_decider.h"
#include "chrome/browser/notifications/scheduler/internal/icon_store.h"
#include "chrome/browser/notifications/scheduler/internal/impression_history_tracker.h"
#include "chrome/browser/notifications/scheduler/internal/impression_store.h"
#include "chrome/browser/notifications/scheduler/internal/init_aware_scheduler.h"
#include "chrome/browser/notifications/scheduler/internal/noop_notification_schedule_service.h"
#include "chrome/browser/notifications/scheduler/internal/notification_schedule_service_impl.h"
#include "chrome/browser/notifications/scheduler/internal/notification_scheduler_context.h"
#include "chrome/browser/notifications/scheduler/internal/notification_store.h"
#include "chrome/browser/notifications/scheduler/internal/png_icon_converter_impl.h"
#include "chrome/browser/notifications/scheduler/internal/scheduled_notification_manager.h"
#include "chrome/browser/notifications/scheduler/internal/scheduler_config.h"
#include "chrome/browser/notifications/scheduler/internal/scheduler_utils.h"
#include "chrome/browser/notifications/scheduler/internal/webui_client.h"
#include "chrome/browser/notifications/scheduler/public/display_agent.h"
#include "chrome/browser/notifications/scheduler/public/features.h"
#include "chrome/browser/notifications/scheduler/public/notification_background_task_scheduler.h"
#include "chrome/browser/notifications/scheduler/public/notification_scheduler_client_registrar.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"

namespace notifications {
namespace {
const base::FilePath::CharType kImpressionDBName[] =
    FILE_PATH_LITERAL("ImpressionDB");
const base::FilePath::CharType kIconDBName[] = FILE_PATH_LITERAL("IconDB");
const base::FilePath::CharType kNotificationDBName[] =
    FILE_PATH_LITERAL("NotificationDB");
}  // namespace

std::unique_ptr<KeyedService> CreateNotificationScheduleService(
    std::unique_ptr<NotificationSchedulerClientRegistrar> client_registrar,
    std::unique_ptr<NotificationBackgroundTaskScheduler>
        background_task_scheduler,
    std::unique_ptr<DisplayAgent> display_agent,
    leveldb_proto::ProtoDatabaseProvider* db_provider,
    const base::FilePath& storage_dir,
    bool off_the_record) {
  if (!base::FeatureList::IsEnabled(features::kNotificationScheduleService) ||
      off_the_record)
    return std::make_unique<NoopNotificationScheduleService>();

  auto config = SchedulerConfig::Create();
  auto task_runner = base::ThreadPool::CreateSequencedTaskRunner(
      {base::MayBlock(), base::TaskPriority::BEST_EFFORT});
  client_registrar->RegisterClient(SchedulerClientType::kWebUI,
                                   std::make_unique<WebUIClient>());

  // Build icon store.
  base::FilePath icon_store_dir = storage_dir.Append(kIconDBName);
  auto icon_db = db_provider->GetDB<proto::Icon, IconEntry>(
      leveldb_proto::ProtoDbType::NOTIFICATION_SCHEDULER_ICON_STORE,
      icon_store_dir, task_runner);
  auto icon_store = std::make_unique<IconProtoDbStore>(
      std::move(icon_db), std::make_unique<PngIconConverterImpl>());

  // Build impression tracker.
  base::FilePath impression_store_dir = storage_dir.Append(kImpressionDBName);
  auto impression_db = db_provider->GetDB<proto::ClientState, ClientState>(
      leveldb_proto::ProtoDbType::NOTIFICATION_SCHEDULER_IMPRESSION_STORE,
      impression_store_dir, task_runner);
  auto impression_store =
      std::make_unique<ImpressionStore>(std::move(impression_db));
  std::vector<SchedulerClientType> registered_clients;
  client_registrar->GetRegisteredClients(&registered_clients);
  auto impression_tracker = std::make_unique<ImpressionHistoryTrackerImpl>(
      *config.get(), registered_clients, std::move(impression_store),
      base::DefaultClock::GetInstance());

  // Build scheduled notification manager.
  base::FilePath notification_store_dir =
      storage_dir.Append(kNotificationDBName);
  auto notification_db = db_provider->GetDB<proto::NotificationEntry,
                                            notifications::NotificationEntry>(
      leveldb_proto::ProtoDbType::NOTIFICATION_SCHEDULER_NOTIFICATION_STORE,
      notification_store_dir, task_runner);
  auto notification_store =
      std::make_unique<NotificationStore>(std::move(notification_db));

  auto notification_manager = ScheduledNotificationManager::Create(
      std::move(notification_store), std::move(icon_store), registered_clients,
      *config.get());

  auto background_task_coordinator = BackgroundTaskCoordinator::Create(
      std::move(background_task_scheduler), config.get(),
      base::DefaultClock::GetInstance());

  auto display_decider = DisplayDecider::Create(
      config.get(), registered_clients, base::DefaultClock::GetInstance());
  auto context = std::make_unique<NotificationSchedulerContext>(
      std::move(client_registrar), std::move(background_task_coordinator),
      std::move(impression_tracker), std::move(notification_manager),
      std::move(display_agent), std::move(display_decider), std::move(config));

  auto scheduler = NotificationScheduler::Create(std::move(context));
  auto init_aware_scheduler =
      std::make_unique<InitAwareNotificationScheduler>(std::move(scheduler));
  return std::make_unique<NotificationScheduleServiceImpl>(
      (std::move(init_aware_scheduler)));
}

}  // namespace notifications