[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 7 | |
Friedrich Horschig | 9e8749f0 | 2017-08-10 09:17:31 | [diff] [blame] | 8 | #include <map> |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 9 | #include <memory> |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 10 | #include <set> |
[email protected] | ab01dd75 | 2013-06-08 05:13:36 | [diff] [blame] | 11 | #include <vector> |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 12 | |
[email protected] | c4b2af2 | 2014-05-11 19:48:53 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 14 | #include "base/macros.h" |
treib | bb0c5af5 | 2016-12-09 17:34:15 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
[email protected] | 280be99 | 2013-06-04 03:19:51 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 17 | #include "base/observer_list.h" |
Kristi Park | 999db91 | 2018-12-05 23:46:42 | [diff] [blame] | 18 | #include "base/optional.h" |
brettw | 9b0866f | 2016-12-11 02:34:06 | [diff] [blame] | 19 | #include "build/build_config.h" |
sdefresne | bc766ef | 2014-09-25 09:28:13 | [diff] [blame] | 20 | #include "components/history/core/browser/history_types.h" |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 21 | #include "components/image_fetcher/core/image_fetcher_impl.h" |
[email protected] | 540380fc | 2014-03-14 10:10:34 | [diff] [blame] | 22 | #include "components/keyed_service/core/keyed_service.h" |
treib | bb0c5af5 | 2016-12-09 17:34:15 | [diff] [blame] | 23 | #include "components/ntp_tiles/most_visited_sites.h" |
| 24 | #include "components/ntp_tiles/ntp_tile.h" |
Kyle Milka | 66bb07a | 2018-09-17 17:55:56 | [diff] [blame] | 25 | #include "components/prefs/pref_change_registrar.h" |
Kyle Milka | 64e205c | 2018-06-07 17:27:31 | [diff] [blame] | 26 | #include "components/prefs/pref_registry_simple.h" |
[email protected] | 54e0ee6 | 2013-02-01 17:25:03 | [diff] [blame] | 27 | #include "content/public/browser/notification_observer.h" |
| 28 | #include "content/public/browser/notification_registrar.h" |
Kristi Park | ff3cf95 | 2019-01-28 23:00:59 | [diff] [blame] | 29 | #include "ui/native_theme/native_theme.h" |
Kyle Milka | 35af9bd4 | 2019-06-28 21:57:46 | [diff] [blame] | 30 | #include "ui/native_theme/native_theme_observer.h" |
[email protected] | c4b2af2 | 2014-05-11 19:48:53 | [diff] [blame] | 31 | #include "url/gurl.h" |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 32 | |
Marc Treib | 9028a6a | 2017-12-06 16:21:51 | [diff] [blame] | 33 | #if defined(OS_ANDROID) |
| 34 | #error "Instant is only used on desktop"; |
| 35 | #endif |
| 36 | |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 37 | class InstantIOContext; |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 38 | class InstantServiceObserver; |
Kyle Milka | 31a76c6d | 2018-10-19 17:37:27 | [diff] [blame] | 39 | class NtpBackgroundService; |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 40 | class Profile; |
Kristi Park | e6893152 | 2019-06-08 00:17:18 | [diff] [blame] | 41 | struct InstantMostVisitedInfo; |
[email protected] | c4b2af2 | 2014-05-11 19:48:53 | [diff] [blame] | 42 | struct ThemeBackgroundInfo; |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 43 | |
[email protected] | 4ff347e | 2013-07-22 19:39:00 | [diff] [blame] | 44 | namespace content { |
[email protected] | 77759005 | 2014-01-17 22:11:54 | [diff] [blame] | 45 | class RenderProcessHost; |
Kristi Park | a5141b9 | 2018-10-10 01:23:57 | [diff] [blame] | 46 | } // namespace content |
[email protected] | 4ff347e | 2013-07-22 19:39:00 | [diff] [blame] | 47 | |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 48 | extern const char kNtpCustomBackgroundMainColor[]; |
| 49 | |
Marc Treib | be5f3feb | 2017-09-04 09:53:16 | [diff] [blame] | 50 | // Tracks render process host IDs that are associated with Instant, i.e. |
| 51 | // processes that are used to render an NTP. Also responsible for keeping |
| 52 | // necessary information (most visited tiles and theme info) updated in those |
| 53 | // renderer processes. |
[email protected] | 540380fc | 2014-03-14 10:10:34 | [diff] [blame] | 54 | class InstantService : public KeyedService, |
[email protected] | c4b2af2 | 2014-05-11 19:48:53 | [diff] [blame] | 55 | public content::NotificationObserver, |
Kyle Milka | 35af9bd4 | 2019-06-28 21:57:46 | [diff] [blame] | 56 | public ntp_tiles::MostVisitedSites::Observer, |
| 57 | public ui::NativeThemeObserver { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 58 | public: |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 59 | explicit InstantService(Profile* profile); |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 60 | ~InstantService() override; |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 61 | |
| 62 | // Add, remove, and query RenderProcessHost IDs that are associated with |
| 63 | // Instant processes. |
| 64 | void AddInstantProcess(int process_id); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 65 | bool IsInstantProcess(int process_id) const; |
| 66 | |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 67 | // Adds/Removes InstantService observers. |
| 68 | void AddObserver(InstantServiceObserver* observer); |
| 69 | void RemoveObserver(InstantServiceObserver* observer); |
| 70 | |
Kyle Milka | 64e205c | 2018-06-07 17:27:31 | [diff] [blame] | 71 | // Register prefs associated with the NTP. |
| 72 | static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 73 | |
[email protected] | d572bfd | 2013-02-14 06:14:20 | [diff] [blame] | 74 | #if defined(UNIT_TEST) |
| 75 | int GetInstantProcessCount() const { |
| 76 | return process_ids_.size(); |
| 77 | } |
| 78 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 79 | |
treib | 2df1b7d | 2016-11-23 09:16:32 | [diff] [blame] | 80 | // Invoked whenever an NTP is opened. Causes an async refresh of Most Visited |
| 81 | // items. |
| 82 | void OnNewTabPageOpened(); |
| 83 | |
Xi Cheng | 72db9c0c | 2017-08-30 17:05:40 | [diff] [blame] | 84 | // Most visited item APIs. |
| 85 | // |
treib | 2df1b7d | 2016-11-23 09:16:32 | [diff] [blame] | 86 | // Invoked when the Instant page wants to delete a Most Visited item. |
[email protected] | 280be99 | 2013-06-04 03:19:51 | [diff] [blame] | 87 | void DeleteMostVisitedItem(const GURL& url); |
treib | 2df1b7d | 2016-11-23 09:16:32 | [diff] [blame] | 88 | // Invoked when the Instant page wants to undo the deletion. |
[email protected] | 280be99 | 2013-06-04 03:19:51 | [diff] [blame] | 89 | void UndoMostVisitedDeletion(const GURL& url); |
treib | 2df1b7d | 2016-11-23 09:16:32 | [diff] [blame] | 90 | // Invoked when the Instant page wants to undo all Most Visited deletions. |
[email protected] | 280be99 | 2013-06-04 03:19:51 | [diff] [blame] | 91 | void UndoAllMostVisitedDeletions(); |
kristipark | a52a389 | 2018-07-24 18:46:44 | [diff] [blame] | 92 | // Invoked when the Instant page wants to add a custom link. |
kristipark | be00c656 | 2018-08-01 21:30:27 | [diff] [blame] | 93 | bool AddCustomLink(const GURL& url, const std::string& title); |
kristipark | 940dc20 | 2018-07-30 18:29:55 | [diff] [blame] | 94 | // Invoked when the Instant page wants to update a custom link. |
kristipark | be00c656 | 2018-08-01 21:30:27 | [diff] [blame] | 95 | bool UpdateCustomLink(const GURL& url, |
kristipark | 940dc20 | 2018-07-30 18:29:55 | [diff] [blame] | 96 | const GURL& new_url, |
| 97 | const std::string& new_title); |
Kristi Park | a49acec | 2018-11-07 22:56:50 | [diff] [blame] | 98 | // Invoked when the Instant page wants to reorder a custom link. |
| 99 | bool ReorderCustomLink(const GURL& url, int new_pos); |
kristipark | a52a389 | 2018-07-24 18:46:44 | [diff] [blame] | 100 | // Invoked when the Instant page wants to delete a custom link. |
kristipark | be00c656 | 2018-08-01 21:30:27 | [diff] [blame] | 101 | bool DeleteCustomLink(const GURL& url); |
| 102 | // Invoked when the Instant page wants to undo the previous custom link |
Kristi Park | b8aec55 | 2019-04-18 21:08:56 | [diff] [blame] | 103 | // action. Returns false and does nothing if the profile is using a third- |
| 104 | // party NTP. |
Ramya Nagarajan | 7673f05 | 2018-08-13 22:53:29 | [diff] [blame] | 105 | bool UndoCustomLinkAction(); |
kristipark | a52a389 | 2018-07-24 18:46:44 | [diff] [blame] | 106 | // Invoked when the Instant page wants to delete all custom links and use Most |
Ramya Nagarajan | 7673f05 | 2018-08-13 22:53:29 | [diff] [blame] | 107 | // Visited sites instead. Returns false and does nothing if the profile is |
Kristi Park | b8aec55 | 2019-04-18 21:08:56 | [diff] [blame] | 108 | // using a third-party NTP. Marked virtual for mocking in tests. |
Gayane Petrosyan | 9929610 | 2019-03-06 19:07:49 | [diff] [blame] | 109 | virtual bool ResetCustomLinks(); |
Kristi Park | 30aa634 | 2019-06-11 22:43:27 | [diff] [blame] | 110 | // Invoked when the Instant page wants to switch between custom links and Most |
| 111 | // Visited. Toggles between the two options each time it's called. Returns |
| 112 | // false and does nothing if the profile is using a third-party NTP. |
| 113 | bool ToggleMostVisitedOrCustomLinks(); |
| 114 | // Invoked when the Instant page wants to toggle visibility of the tiles. |
Kristi Park | 955ad55 | 2019-07-02 21:50:33 | [diff] [blame] | 115 | // Notifies observers only if |do_notify| is true, which is usually the case |
| 116 | // if |ToggleMostVisitedOrCustomLinks| will not be called immediately after. |
Kristi Park | 30aa634 | 2019-06-11 22:43:27 | [diff] [blame] | 117 | // Returns false and does nothing if the profile is using a third-party NTP. |
Kristi Park | 955ad55 | 2019-07-02 21:50:33 | [diff] [blame] | 118 | bool ToggleShortcutsVisibility(bool do_notify); |
[email protected] | 280be99 | 2013-06-04 03:19:51 | [diff] [blame] | 119 | |
Kyle Milka | 5c0166d | 2019-04-03 23:57:14 | [diff] [blame] | 120 | // Invoked to update theme information for the NTP. |
Kyle Milka | fb37a77 | 2018-06-25 16:09:19 | [diff] [blame] | 121 | void UpdateThemeInfo(); |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 122 | |
Kyle Milka | 0d1b376e | 2019-01-28 19:34:10 | [diff] [blame] | 123 | // Invoked when a background pref update is received via sync, triggering |
| 124 | // an update of theme info. |
| 125 | void UpdateBackgroundFromSync(); |
| 126 | |
[email protected] | ed68ae3 | 2013-06-29 20:46:48 | [diff] [blame] | 127 | // Invoked by the InstantController to update most visited items details for |
| 128 | // NTP. |
Kristi Park | 6424e60 | 2019-06-11 18:01:43 | [diff] [blame] | 129 | void UpdateMostVisitedInfo(); |
[email protected] | ed68ae3 | 2013-06-29 20:46:48 | [diff] [blame] | 130 | |
Marc Treib | c9c3500 | 2017-10-16 10:09:33 | [diff] [blame] | 131 | // Sends the current NTP URL to a renderer process. |
| 132 | void SendNewTabPageURLToRenderer(content::RenderProcessHost* rph); |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 133 | |
Kyle Milka | 64e205c | 2018-06-07 17:27:31 | [diff] [blame] | 134 | // Invoked when a custom background is selected on the NTP. |
| 135 | void SetCustomBackgroundURL(const GURL& url); |
| 136 | |
Kyle Milka | 6986ede | 2018-07-19 02:16:24 | [diff] [blame] | 137 | // Invoked when a custom background with attributions is selected on the NTP. |
| 138 | void SetCustomBackgroundURLWithAttributions( |
| 139 | const GURL& background_url, |
| 140 | const std::string& attribution_line_1, |
| 141 | const std::string& attribution_line_2, |
| 142 | const GURL& action_url); |
| 143 | |
Kyle Milka | 3626a7d | 2018-07-03 06:23:55 | [diff] [blame] | 144 | // Invoked when a user selected the "Upload an image" option on the NTP. |
| 145 | void SelectLocalBackgroundImage(const base::FilePath& path); |
| 146 | |
Gayane Petrosyan | e85debf | 2019-03-06 06:19:13 | [diff] [blame] | 147 | // Getter for |theme_info_| that will also initialize it if necessary. |
| 148 | ThemeBackgroundInfo* GetInitializedThemeInfo(); |
Kyle Milka | 6986ede | 2018-07-19 02:16:24 | [diff] [blame] | 149 | |
Kristi Park | ff3cf95 | 2019-01-28 23:00:59 | [diff] [blame] | 150 | // Used for testing. |
Kyle Milka | 35af9bd4 | 2019-06-28 21:57:46 | [diff] [blame] | 151 | void SetNativeThemeForTesting(ui::NativeTheme* theme); |
Kristi Park | ff3cf95 | 2019-01-28 23:00:59 | [diff] [blame] | 152 | |
| 153 | // Used for testing. |
Kyle Milka | 31a76c6d | 2018-10-19 17:37:27 | [diff] [blame] | 154 | void AddValidBackdropUrlForTesting(const GURL& url) const; |
| 155 | |
Kyle Milka | 427c8da | 2018-11-26 21:59:05 | [diff] [blame] | 156 | // Check if a custom background has been set by the user. |
| 157 | bool IsCustomBackgroundSet(); |
| 158 | |
Gayane Petrosyan | 9929610 | 2019-03-06 19:07:49 | [diff] [blame] | 159 | // Reset all NTP customizations to default. Marked virtual for mocking in |
| 160 | // tests. |
| 161 | virtual void ResetToDefault(); |
| 162 | |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 163 | // Calculates the most frequent color of the image and stores it in prefs. |
| 164 | void UpdateCustomBackgroundColorAsync( |
Kyle Milka | c3d1a530 | 2019-07-10 19:04:02 | [diff] [blame] | 165 | base::TimeTicks timestamp, |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 166 | const gfx::Image& fetched_image, |
| 167 | const image_fetcher::RequestMetadata& metadata); |
| 168 | |
| 169 | // Fetches the image for the given |fetch_url|. |
Kyle Milka | c3d1a530 | 2019-07-10 19:04:02 | [diff] [blame] | 170 | void FetchCustomBackground(base::TimeTicks timestamp, const GURL& fetch_url); |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 171 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 172 | private: |
kristipark | f8fa413 | 2018-09-13 18:07:29 | [diff] [blame] | 173 | class SearchProviderObserver; |
| 174 | |
[email protected] | 4ff347e | 2013-07-22 19:39:00 | [diff] [blame] | 175 | friend class InstantExtendedTest; |
[email protected] | c8a118e | 2013-09-24 21:33:40 | [diff] [blame] | 176 | friend class InstantUnitTestBase; |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 177 | friend class LocalNTPBackgroundsAndDarkModeTest; |
| 178 | friend class TestInstantService; |
[email protected] | 4ff347e | 2013-07-22 19:39:00 | [diff] [blame] | 179 | |
[email protected] | df113a1 | 2013-07-24 04:56:08 | [diff] [blame] | 180 | FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); |
Marc Treib | 7b3985e | 2017-09-18 11:22:16 | [diff] [blame] | 181 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, GetNTPTileSuggestion); |
Kristi Park | e6893152 | 2019-06-08 00:17:18 | [diff] [blame] | 182 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, |
| 183 | DoesToggleMostVisitedOrCustomLinks); |
Kristi Park | 30aa634 | 2019-06-11 22:43:27 | [diff] [blame] | 184 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DoesToggleShortcutsVisibility); |
Kristi Park | b8aec55 | 2019-04-18 21:08:56 | [diff] [blame] | 185 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, IsCustomLinksEnabled); |
Gayane Petrosyan | e85debf | 2019-03-06 06:19:13 | [diff] [blame] | 186 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, TestNoThemeInfo); |
Kyle Milka | c3d1a530 | 2019-07-10 19:04:02 | [diff] [blame] | 187 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, TestUpdateCustomBackgroundColor); |
| 188 | FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, |
| 189 | LocalImageDoesNotUpdateCustomBackgroundColor); |
[email protected] | 4ff347e | 2013-07-22 19:39:00 | [diff] [blame] | 190 | |
[email protected] | c4b2af2 | 2014-05-11 19:48:53 | [diff] [blame] | 191 | // KeyedService: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 192 | void Shutdown() override; |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 193 | |
[email protected] | c4b2af2 | 2014-05-11 19:48:53 | [diff] [blame] | 194 | // content::NotificationObserver: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 195 | void Observe(int type, |
| 196 | const content::NotificationSource& source, |
| 197 | const content::NotificationDetails& details) override; |
[email protected] | 54e0ee6 | 2013-02-01 17:25:03 | [diff] [blame] | 198 | |
[email protected] | 2309e91 | 2013-10-01 01:33:30 | [diff] [blame] | 199 | // Called when a renderer process is terminated. |
| 200 | void OnRendererProcessTerminated(int process_id); |
| 201 | |
Kyle Milka | 35af9bd4 | 2019-06-28 21:57:46 | [diff] [blame] | 202 | // ui::NativeThemeObserver: |
| 203 | void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override; |
| 204 | |
kristipark | f8fa413 | 2018-09-13 18:07:29 | [diff] [blame] | 205 | // Called when the search provider changes. Disables custom links if the |
| 206 | // search provider is not Google. |
Kristi Park | b8aec55 | 2019-04-18 21:08:56 | [diff] [blame] | 207 | void OnSearchProviderChanged(); |
kristipark | f8fa413 | 2018-09-13 18:07:29 | [diff] [blame] | 208 | |
treib | bb0c5af5 | 2016-12-09 17:34:15 | [diff] [blame] | 209 | // ntp_tiles::MostVisitedSites::Observer implementation. |
Friedrich Horschig | 9e8749f0 | 2017-08-10 09:17:31 | [diff] [blame] | 210 | void OnURLsAvailable( |
| 211 | const std::map<ntp_tiles::SectionType, ntp_tiles::NTPTilesVector>& |
| 212 | sections) override; |
treib | bb0c5af5 | 2016-12-09 17:34:15 | [diff] [blame] | 213 | void OnIconMadeAvailable(const GURL& site_url) override; |
[email protected] | 280be99 | 2013-06-04 03:19:51 | [diff] [blame] | 214 | |
Kristi Park | 6424e60 | 2019-06-11 18:01:43 | [diff] [blame] | 215 | void NotifyAboutMostVisitedInfo(); |
Marc Treib | 5891b28 | 2017-08-22 09:44:30 | [diff] [blame] | 216 | void NotifyAboutThemeInfo(); |
[email protected] | ed68ae3 | 2013-06-29 20:46:48 | [diff] [blame] | 217 | |
Kristi Park | b8aec55 | 2019-04-18 21:08:56 | [diff] [blame] | 218 | // Returns true if this is a Google NTP and the user has chosen to show custom |
| 219 | // links. |
| 220 | bool IsCustomLinksEnabled(); |
| 221 | |
Marc Treib | 5891b28 | 2017-08-22 09:44:30 | [diff] [blame] | 222 | void BuildThemeInfo(); |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 223 | |
Kyle Milka | 6986ede | 2018-07-19 02:16:24 | [diff] [blame] | 224 | void ApplyOrResetCustomBackgroundThemeInfo(); |
| 225 | |
Kyle Milka | 66bb07a | 2018-09-17 17:55:56 | [diff] [blame] | 226 | void ApplyCustomBackgroundThemeInfo(); |
Kyle Milka | 66bb07a | 2018-09-17 17:55:56 | [diff] [blame] | 227 | |
Gayane Petrosyan | 9929610 | 2019-03-06 19:07:49 | [diff] [blame] | 228 | // Marked virtual for mocking in tests. |
| 229 | virtual void ResetCustomBackgroundThemeInfo(); |
Kyle Milka | fb37a77 | 2018-06-25 16:09:19 | [diff] [blame] | 230 | |
Kyle Milka | 66bb07a | 2018-09-17 17:55:56 | [diff] [blame] | 231 | void FallbackToDefaultThemeInfo(); |
| 232 | |
Kyle Milka | 31a76c6d | 2018-10-19 17:37:27 | [diff] [blame] | 233 | void RemoveLocalBackgroundImageCopy(); |
| 234 | |
Kyle Milka | 427c8da | 2018-11-26 21:59:05 | [diff] [blame] | 235 | // Returns false if the custom background pref cannot be parsed, otherwise |
| 236 | // returns true and sets custom_background_url to the value in the pref. |
| 237 | bool IsCustomBackgroundPrefValid(GURL& custom_background_url); |
| 238 | |
Kyle Milka | 3626a7d | 2018-07-03 06:23:55 | [diff] [blame] | 239 | // Update the background pref to point to |
| 240 | // chrome-search://local-ntp/background.jpg |
| 241 | void SetBackgroundToLocalResource(); |
| 242 | |
Kyle Milka | c3d1a530 | 2019-07-10 19:04:02 | [diff] [blame] | 243 | // Updates custom background prefs with color if the background hasn't changed |
| 244 | // since the calculation started. |
| 245 | void UpdateCustomBackgroundPrefsWithColor(base::TimeTicks timestamp, |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 246 | SkColor color); |
| 247 | |
| 248 | void SetImageFetcherForTesting(image_fetcher::ImageFetcher* image_fetcher); |
| 249 | |
Kyle Milka | c3d1a530 | 2019-07-10 19:04:02 | [diff] [blame] | 250 | base::TimeTicks GetBackgroundUpdatedTimestampForTesting() { |
| 251 | return background_updated_timestamp_; |
| 252 | } |
| 253 | |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 254 | Profile* const profile_; |
| 255 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 256 | // The process ids associated with Instant processes. |
| 257 | std::set<int> process_ids_; |
| 258 | |
Kristi Park | e6893152 | 2019-06-08 00:17:18 | [diff] [blame] | 259 | // Contains InstantMostVisitedItems received from |most_visited_sites_| and |
| 260 | // information required to display NTP tiles. |
| 261 | std::unique_ptr<InstantMostVisitedInfo> most_visited_info_; |
[email protected] | e7868c8 | 2013-03-12 03:55:56 | [diff] [blame] | 262 | |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 263 | // Theme-related data for NTP overlay to adopt themes. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 264 | std::unique_ptr<ThemeBackgroundInfo> theme_info_; |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 265 | |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 266 | base::ObserverList<InstantServiceObserver>::Unchecked observers_; |
[email protected] | 6af4178 | 2013-06-22 13:49:11 | [diff] [blame] | 267 | |
[email protected] | 54e0ee6 | 2013-02-01 17:25:03 | [diff] [blame] | 268 | content::NotificationRegistrar registrar_; |
| 269 | |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 270 | scoped_refptr<InstantIOContext> instant_io_context_; |
| 271 | |
Marc Treib | 7b3985e | 2017-09-18 11:22:16 | [diff] [blame] | 272 | // Data source for NTP tiles (aka Most Visited tiles). May be null. |
treib | bb0c5af5 | 2016-12-09 17:34:15 | [diff] [blame] | 273 | std::unique_ptr<ntp_tiles::MostVisitedSites> most_visited_sites_; |
mohan.reddy | 7459536 | 2014-09-23 20:35:34 | [diff] [blame] | 274 | |
kristipark | f8fa413 | 2018-09-13 18:07:29 | [diff] [blame] | 275 | // Keeps track of any changes in search engine provider. May be null. |
| 276 | std::unique_ptr<SearchProviderObserver> search_provider_observer_; |
| 277 | |
Kyle Milka | 66bb07a | 2018-09-17 17:55:56 | [diff] [blame] | 278 | PrefChangeRegistrar pref_change_registrar_; |
| 279 | |
| 280 | PrefService* pref_service_; |
| 281 | |
Kyle Milka | 35af9bd4 | 2019-06-28 21:57:46 | [diff] [blame] | 282 | ScopedObserver<ui::NativeTheme, InstantService> theme_observer_; |
| 283 | |
| 284 | ui::NativeTheme* native_theme_; |
Dan Beam | 6877cef4 | 2019-01-30 21:19:03 | [diff] [blame] | 285 | |
Kyle Milka | 31a76c6d | 2018-10-19 17:37:27 | [diff] [blame] | 286 | NtpBackgroundService* background_service_; |
| 287 | |
Gayane Petrosyan | d257e720 | 2019-05-21 03:43:38 | [diff] [blame] | 288 | std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
| 289 | |
Kyle Milka | c3d1a530 | 2019-07-10 19:04:02 | [diff] [blame] | 290 | base::TimeTicks background_updated_timestamp_; |
| 291 | |
Kyle Milka | 3626a7d | 2018-07-03 06:23:55 | [diff] [blame] | 292 | base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
| 293 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 294 | DISALLOW_COPY_AND_ASSIGN(InstantService); |
| 295 | }; |
| 296 | |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 297 | #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |