blob: 48f6cab9b6a22c758c5e81f6a70acdd03493dd1c [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2019 The Chromium Authors
Rayan Kanso24f7d412019-07-11 10:09:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_CONTENT_INDEX_CONTENT_INDEX_PROVIDER_IMPL_H_
6#define CHROME_BROWSER_CONTENT_INDEX_CONTENT_INDEX_PROVIDER_IMPL_H_
7
Arthur Sonzognife132ee2024-01-15 11:01:048#include <optional>
Rayan Kansocb31dab82019-07-11 10:27:579#include <string>
10
Keishi Hattori0e45c022021-11-27 09:25:5211#include "base/memory/raw_ptr.h"
Rayan Kansocb31dab82019-07-11 10:27:5712#include "base/memory/weak_ptr.h"
Rayan Kanso011553372019-08-06 18:14:2413#include "chrome/browser/content_index/content_index_metrics.h"
Rayan Kanso24f7d412019-07-11 10:09:3014#include "components/keyed_service/core/keyed_service.h"
Rayan Kansocb31dab82019-07-11 10:27:5715#include "components/offline_items_collection/core/offline_content_provider.h"
16#include "components/offline_items_collection/core/offline_item.h"
Rayan Kanso24f7d412019-07-11 10:09:3017#include "content/public/browser/content_index_provider.h"
Rayan Kanso24f7d412019-07-11 10:09:3018
Rayan Kanso011553372019-08-06 18:14:2419namespace content {
20class WebContents;
21} // namespace content
22
Rayan Kansocb31dab82019-07-11 10:27:5723namespace offline_items_collection {
24class OfflineContentAggregator;
25} // namespace offline_items_collection
Rayan Kanso24f7d412019-07-11 10:09:3026
Evan Stade7a984802020-12-14 19:10:1527namespace site_engagement {
Rayan Kanso650cb6a2019-10-17 20:12:0628class SiteEngagementService;
Evan Stade7a984802020-12-14 19:10:1529}
30
31class Profile;
Rayan Kanso7177f422019-07-16 14:32:1432
Rayan Kansocb31dab82019-07-11 10:27:5733class ContentIndexProviderImpl
34 : public KeyedService,
35 public offline_items_collection::OfflineContentProvider,
36 public content::ContentIndexProvider {
Rayan Kanso24f7d412019-07-11 10:09:3037 public:
Rayan Kanso81965f092021-03-15 16:31:3638 static const char kProviderNamespace[];
39
Rayan Kanso7177f422019-07-16 14:32:1440 explicit ContentIndexProviderImpl(Profile* profile);
Peter Boström53c6c5952021-09-17 09:41:2641
42 ContentIndexProviderImpl(const ContentIndexProviderImpl&) = delete;
43 ContentIndexProviderImpl& operator=(const ContentIndexProviderImpl&) = delete;
44
Rayan Kansocb31dab82019-07-11 10:27:5745 ~ContentIndexProviderImpl() override;
Rayan Kanso24f7d412019-07-11 10:09:3046
47 // KeyedService implementation.
48 void Shutdown() override;
49
50 // ContentIndexProvider implementation.
Rayan Kanso4f753a672019-08-12 17:30:0751 std::vector<gfx::Size> GetIconSizes(
52 blink::mojom::ContentCategory category) override;
Rayan Kansoa42c3caf2019-07-19 17:21:2053 void OnContentAdded(content::ContentIndexEntry entry) override;
Rayan Kanso24f7d412019-07-11 10:09:3054 void OnContentDeleted(int64_t service_worker_registration_id,
Rayan Kansoa42c3caf2019-07-19 17:21:2055 const url::Origin& origin,
Rayan Kanso24f7d412019-07-11 10:09:3056 const std::string& description_id) override;
57
Rayan Kansocb31dab82019-07-11 10:27:5758 // OfflineContentProvider implementation.
Shakti Sahu333ad9eb2020-03-05 00:18:1259 void OpenItem(const offline_items_collection::OpenParams& open_params,
Rayan Kansocb31dab82019-07-11 10:27:5760 const offline_items_collection::ContentId& id) override;
61 void RemoveItem(const offline_items_collection::ContentId& id) override;
62 void CancelDownload(const offline_items_collection::ContentId& id) override;
63 void PauseDownload(const offline_items_collection::ContentId& id) override;
Min Qin196f99d2024-01-12 16:47:2364 void ResumeDownload(const offline_items_collection::ContentId& id) override;
Lily Chen8f6f8ae2025-05-30 02:18:5265 void ValidateDangerousDownload(
66 const offline_items_collection::ContentId& id) override;
Rayan Kansocb31dab82019-07-11 10:27:5767 void GetItemById(const offline_items_collection::ContentId& id,
68 SingleItemCallback callback) override;
69 void GetAllItems(MultipleItemCallback callback) override;
70 void GetVisualsForItem(const offline_items_collection::ContentId& id,
71 GetVisualsOptions options,
72 VisualsCallback callback) override;
73 void GetShareInfoForItem(const offline_items_collection::ContentId& id,
74 ShareCallback callback) override;
75 void RenameItem(const offline_items_collection::ContentId& id,
76 const std::string& name,
77 RenameCallback callback) override;
Rayan Kansocb31dab82019-07-11 10:27:5778
Rayan Kanso4f753a672019-08-12 17:30:0779 void SetIconSizesForTesting(std::vector<gfx::Size> icon_sizes) {
80 icon_sizes_for_testing_ = std::move(icon_sizes);
81 }
Rayan Kansocb31dab82019-07-11 10:27:5782
Rayan Kanso4f753a672019-08-12 17:30:0783 private:
Rayan Kanso650cb6a2019-10-17 20:12:0684 void DidGetItem(SingleItemCallback callback,
Arthur Sonzognife132ee2024-01-15 11:01:0485 std::optional<content::ContentIndexEntry> entry);
Rayan Kanso650cb6a2019-10-17 20:12:0686 void DidGetAllEntriesAcrossStorageParitions(
87 std::unique_ptr<OfflineItemList> item_list,
88 MultipleItemCallback callback);
89 void DidGetAllEntries(base::OnceClosure done_closure,
90 OfflineItemList* item_list,
91 blink::mojom::ContentIndexError error,
92 std::vector<content::ContentIndexEntry> entries);
Rayan Kansob0f54fe2019-08-05 18:59:1493 void DidGetIcons(const offline_items_collection::ContentId& id,
94 VisualsCallback callback,
95 std::vector<SkBitmap> icons);
Arthur Sonzognife132ee2024-01-15 11:01:0496 void DidGetEntryToOpen(std::optional<content::ContentIndexEntry> entry);
Rayan Kanso011553372019-08-06 18:14:2497 void DidOpenTab(content::ContentIndexEntry entry,
98 content::WebContents* web_contents);
Rayan Kanso650cb6a2019-10-17 20:12:0699 offline_items_collection::OfflineItem EntryToOfflineItem(
100 const content::ContentIndexEntry& entry);
Rayan Kansocb31dab82019-07-11 10:27:57101
Keishi Hattori0e45c022021-11-27 09:25:52102 raw_ptr<Profile> profile_;
Rayan Kanso011553372019-08-06 18:14:24103 ContentIndexMetrics metrics_;
Keishi Hattori0e45c022021-11-27 09:25:52104 raw_ptr<offline_items_collection::OfflineContentAggregator> aggregator_;
105 raw_ptr<site_engagement::SiteEngagementService> site_engagement_service_;
Arthur Sonzognife132ee2024-01-15 11:01:04106 std::optional<std::vector<gfx::Size>> icon_sizes_for_testing_;
Jeremy Roman7c5cfabd2019-08-12 15:45:27107 base::WeakPtrFactory<ContentIndexProviderImpl> weak_ptr_factory_{this};
Rayan Kanso24f7d412019-07-11 10:09:30108};
109
110#endif // CHROME_BROWSER_CONTENT_INDEX_CONTENT_INDEX_PROVIDER_IMPL_H_