Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 2 | // 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 Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 8 | #include <optional> |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 11 | #include "base/memory/raw_ptr.h" |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
Rayan Kanso | 01155337 | 2019-08-06 18:14:24 | [diff] [blame] | 13 | #include "chrome/browser/content_index/content_index_metrics.h" |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 14 | #include "components/keyed_service/core/keyed_service.h" |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 15 | #include "components/offline_items_collection/core/offline_content_provider.h" |
| 16 | #include "components/offline_items_collection/core/offline_item.h" |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 17 | #include "content/public/browser/content_index_provider.h" |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 18 | |
Rayan Kanso | 01155337 | 2019-08-06 18:14:24 | [diff] [blame] | 19 | namespace content { |
| 20 | class WebContents; |
| 21 | } // namespace content |
| 22 | |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 23 | namespace offline_items_collection { |
| 24 | class OfflineContentAggregator; |
| 25 | } // namespace offline_items_collection |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 26 | |
Evan Stade | 7a98480 | 2020-12-14 19:10:15 | [diff] [blame] | 27 | namespace site_engagement { |
Rayan Kanso | 650cb6a | 2019-10-17 20:12:06 | [diff] [blame] | 28 | class SiteEngagementService; |
Evan Stade | 7a98480 | 2020-12-14 19:10:15 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | class Profile; |
Rayan Kanso | 7177f42 | 2019-07-16 14:32:14 | [diff] [blame] | 32 | |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 33 | class ContentIndexProviderImpl |
| 34 | : public KeyedService, |
| 35 | public offline_items_collection::OfflineContentProvider, |
| 36 | public content::ContentIndexProvider { |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 37 | public: |
Rayan Kanso | 81965f09 | 2021-03-15 16:31:36 | [diff] [blame] | 38 | static const char kProviderNamespace[]; |
| 39 | |
Rayan Kanso | 7177f42 | 2019-07-16 14:32:14 | [diff] [blame] | 40 | explicit ContentIndexProviderImpl(Profile* profile); |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 41 | |
| 42 | ContentIndexProviderImpl(const ContentIndexProviderImpl&) = delete; |
| 43 | ContentIndexProviderImpl& operator=(const ContentIndexProviderImpl&) = delete; |
| 44 | |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 45 | ~ContentIndexProviderImpl() override; |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 46 | |
| 47 | // KeyedService implementation. |
| 48 | void Shutdown() override; |
| 49 | |
| 50 | // ContentIndexProvider implementation. |
Rayan Kanso | 4f753a67 | 2019-08-12 17:30:07 | [diff] [blame] | 51 | std::vector<gfx::Size> GetIconSizes( |
| 52 | blink::mojom::ContentCategory category) override; |
Rayan Kanso | a42c3caf | 2019-07-19 17:21:20 | [diff] [blame] | 53 | void OnContentAdded(content::ContentIndexEntry entry) override; |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 54 | void OnContentDeleted(int64_t service_worker_registration_id, |
Rayan Kanso | a42c3caf | 2019-07-19 17:21:20 | [diff] [blame] | 55 | const url::Origin& origin, |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 56 | const std::string& description_id) override; |
| 57 | |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 58 | // OfflineContentProvider implementation. |
Shakti Sahu | 333ad9eb | 2020-03-05 00:18:12 | [diff] [blame] | 59 | void OpenItem(const offline_items_collection::OpenParams& open_params, |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 60 | 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 Qin | 196f99d | 2024-01-12 16:47:23 | [diff] [blame] | 64 | void ResumeDownload(const offline_items_collection::ContentId& id) override; |
Lily Chen | 8f6f8ae | 2025-05-30 02:18:52 | [diff] [blame] | 65 | void ValidateDangerousDownload( |
| 66 | const offline_items_collection::ContentId& id) override; |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 67 | 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 Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 78 | |
Rayan Kanso | 4f753a67 | 2019-08-12 17:30:07 | [diff] [blame] | 79 | void SetIconSizesForTesting(std::vector<gfx::Size> icon_sizes) { |
| 80 | icon_sizes_for_testing_ = std::move(icon_sizes); |
| 81 | } |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 82 | |
Rayan Kanso | 4f753a67 | 2019-08-12 17:30:07 | [diff] [blame] | 83 | private: |
Rayan Kanso | 650cb6a | 2019-10-17 20:12:06 | [diff] [blame] | 84 | void DidGetItem(SingleItemCallback callback, |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 85 | std::optional<content::ContentIndexEntry> entry); |
Rayan Kanso | 650cb6a | 2019-10-17 20:12:06 | [diff] [blame] | 86 | 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 Kanso | b0f54fe | 2019-08-05 18:59:14 | [diff] [blame] | 93 | void DidGetIcons(const offline_items_collection::ContentId& id, |
| 94 | VisualsCallback callback, |
| 95 | std::vector<SkBitmap> icons); |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 96 | void DidGetEntryToOpen(std::optional<content::ContentIndexEntry> entry); |
Rayan Kanso | 01155337 | 2019-08-06 18:14:24 | [diff] [blame] | 97 | void DidOpenTab(content::ContentIndexEntry entry, |
| 98 | content::WebContents* web_contents); |
Rayan Kanso | 650cb6a | 2019-10-17 20:12:06 | [diff] [blame] | 99 | offline_items_collection::OfflineItem EntryToOfflineItem( |
| 100 | const content::ContentIndexEntry& entry); |
Rayan Kanso | cb31dab8 | 2019-07-11 10:27:57 | [diff] [blame] | 101 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 102 | raw_ptr<Profile> profile_; |
Rayan Kanso | 01155337 | 2019-08-06 18:14:24 | [diff] [blame] | 103 | ContentIndexMetrics metrics_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 104 | raw_ptr<offline_items_collection::OfflineContentAggregator> aggregator_; |
| 105 | raw_ptr<site_engagement::SiteEngagementService> site_engagement_service_; |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 106 | std::optional<std::vector<gfx::Size>> icon_sizes_for_testing_; |
Jeremy Roman | 7c5cfabd | 2019-08-12 15:45:27 | [diff] [blame] | 107 | base::WeakPtrFactory<ContentIndexProviderImpl> weak_ptr_factory_{this}; |
Rayan Kanso | 24f7d41 | 2019-07-11 10:09:30 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #endif // CHROME_BROWSER_CONTENT_INDEX_CONTENT_INDEX_PROVIDER_IMPL_H_ |