summaryrefslogtreecommitdiffstats
path: root/src/core/favicon_service_factory_qt.cpp
blob: dd2a1979acb74b157cbe99476aac9ce79fb43c8f (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "favicon_service_factory_qt.h"

#include "base/files/file_util.h"
#include "components/favicon/core/favicon_service_impl.h"
#include "components/history/content/browser/content_visit_delegate.h"
#include "components/history/content/browser/history_database_helper.h"
#include "components/history/core/browser/history_backend_client.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_context.h"
#include "url/gurl.h"

namespace QtWebEngineCore {

void HistoryClientQt::OnHistoryServiceCreated(history::HistoryService *history_service)
{
    Q_UNUSED(history_service);
}

void HistoryClientQt::Shutdown() { }

static bool CanAddURL(const GURL &url)
{
    Q_UNUSED(url);
    return true;
}

history::CanAddURLCallback HistoryClientQt::GetThreadSafeCanAddURLCallback() const
{
    return base::BindRepeating(&CanAddURL);
}

void HistoryClientQt::NotifyProfileError(sql::InitStatus init_status,
                                         const std::string &diagnostics)
{
    Q_UNUSED(init_status);
    Q_UNUSED(diagnostics);
}

std::unique_ptr<history::HistoryBackendClient> HistoryClientQt::CreateBackendClient()
{
    return nullptr;
}

void HistoryClientQt::UpdateBookmarkLastUsedTime(const base::Uuid &, base::Time /*time*/)
{
}

// static
history::HistoryService *
HistoryServiceFactoryQt::GetForBrowserContext(content::BrowserContext *context)
{
    if (context->IsOffTheRecord())
        return nullptr;


    return static_cast<history::HistoryService *>(
            GetInstance()->GetServiceForBrowserContext(context, true));
}

// static
HistoryServiceFactoryQt *HistoryServiceFactoryQt::GetInstance()
{
    return base::Singleton<HistoryServiceFactoryQt>::get();
}

HistoryServiceFactoryQt::HistoryServiceFactoryQt()
    : BrowserContextKeyedServiceFactory("HistoryService",
                                        BrowserContextDependencyManager::GetInstance())
{
}

HistoryServiceFactoryQt::~HistoryServiceFactoryQt() { }

content::BrowserContext *
HistoryServiceFactoryQt::GetBrowserContextToUse(content::BrowserContext *context) const
{
    return context;
}

KeyedService *
HistoryServiceFactoryQt::BuildServiceInstanceFor(content::BrowserContext *context) const
{
    Q_ASSERT(!context->IsOffTheRecord());

    std::unique_ptr<history::HistoryService> historyService(
            new history::HistoryService(std::make_unique<HistoryClientQt>(), nullptr));
    if (!historyService->Init(history::HistoryDatabaseParamsForPath(context->GetPath(), version_info::Channel::DEFAULT))) {
        return nullptr;
    }
    return historyService.release();
}

bool FaviconClientQt::IsNativeApplicationURL(const GURL &url)
{
    Q_UNUSED(url);
    return false;
}

bool FaviconClientQt::IsReaderModeURL(const GURL &url)
{
    Q_UNUSED(url)
    return false;
}

const GURL FaviconClientQt::GetOriginalUrlFromReaderModeUrl(const GURL &url)
{
    return url;
}

base::CancelableTaskTracker::TaskId FaviconClientQt::GetFaviconForNativeApplicationURL(
        const GURL &url, const std::vector<int> &desired_sizes_in_pixel,
        favicon_base::FaviconResultsCallback callback, base::CancelableTaskTracker *tracker)
{
    Q_UNUSED(url);
    Q_UNUSED(desired_sizes_in_pixel);
    Q_UNUSED(callback);
    Q_UNUSED(tracker);

    return base::CancelableTaskTracker::kBadTaskId;
}

// static
favicon::FaviconService *
FaviconServiceFactoryQt::GetForBrowserContext(content::BrowserContext *context)
{
    return static_cast<favicon::FaviconService *>(
            GetInstance()->GetServiceForBrowserContext(context, true));
}

// static
FaviconServiceFactoryQt *FaviconServiceFactoryQt::GetInstance()
{
    return base::Singleton<FaviconServiceFactoryQt>::get();
}

FaviconServiceFactoryQt::FaviconServiceFactoryQt()
    : BrowserContextKeyedServiceFactory("FaviconService",
                                        BrowserContextDependencyManager::GetInstance())
{
}

FaviconServiceFactoryQt::~FaviconServiceFactoryQt() { }

content::BrowserContext *
FaviconServiceFactoryQt::GetBrowserContextToUse(content::BrowserContext *context) const
{
    return context;
}

KeyedService *
FaviconServiceFactoryQt::BuildServiceInstanceFor(content::BrowserContext *context) const
{
    history::HistoryService *historyService = static_cast<history::HistoryService *>(
            HistoryServiceFactoryQt::GetInstance()->GetForBrowserContext(context));
    return new favicon::FaviconServiceImpl(std::make_unique<FaviconClientQt>(), historyService);
}

} // namespace QtWebEngineCore