Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [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_LACROS_BROWSER_SERVICE_LACROS_H_ |
| 6 | #define CHROME_BROWSER_LACROS_BROWSER_SERVICE_LACROS_H_ |
| 7 | |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 8 | #include <memory> |
Antonio Gomes | 8601b5c73 | 2021-10-14 15:41:47 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 11 | #include "base/callback_list.h" |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_list_observer.h" |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 14 | #include "chromeos/crosapi/mojom/crosapi.mojom.h" |
| 15 | #include "components/feedback/system_logs/system_logs_source.h" |
Igor | a4b7a4e9 | 2022-05-04 12:30:19 | [diff] [blame] | 16 | #include "components/policy/core/common/values_util.h" |
Hidehiko Abe | a5b7a3f | 2021-07-02 00:10:37 | [diff] [blame] | 17 | #include "mojo/public/cpp/bindings/receiver.h" |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 18 | |
Hidehiko Abe | 303a7cb | 2021-08-19 06:23:22 | [diff] [blame] | 19 | class GURL; |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 20 | class Profile; |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 21 | class ScopedKeepAlive; |
Hidehiko Abe | 303a7cb | 2021-08-19 06:23:22 | [diff] [blame] | 22 | |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 23 | // BrowserSerivce's Lacros implementation. |
Hidehiko Abe | a5b7a3f | 2021-07-02 00:10:37 | [diff] [blame] | 24 | // This handles the requests from ash-chrome. |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 25 | class BrowserServiceLacros : public crosapi::mojom::BrowserService, |
| 26 | public BrowserListObserver { |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 27 | public: |
| 28 | BrowserServiceLacros(); |
| 29 | BrowserServiceLacros(const BrowserServiceLacros&) = delete; |
| 30 | BrowserServiceLacros& operator=(const BrowserServiceLacros&) = delete; |
| 31 | ~BrowserServiceLacros() override; |
| 32 | |
| 33 | // crosapi::mojom::BrowserService: |
| 34 | void REMOVED_0(REMOVED_0Callback callback) override; |
| 35 | void REMOVED_2(crosapi::mojom::BrowserInitParamsPtr) override; |
Georg Neis | 4fda6e4 | 2023-02-07 02:04:06 | [diff] [blame] | 36 | void REMOVED_7(bool should_trigger_session_restore, |
| 37 | NewTabCallback callback) override; |
Igor | a4b7a4e9 | 2022-05-04 12:30:19 | [diff] [blame] | 38 | void REMOVED_16(base::flat_map<policy::PolicyNamespace, std::vector<uint8_t>> |
| 39 | policy) override; |
Tom Lukaszewicz | 4107270 | 2021-12-10 08:51:35 | [diff] [blame] | 40 | void NewWindow(bool incognito, |
| 41 | bool should_trigger_session_restore, |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 42 | int64_t target_display_id, |
Tom Lukaszewicz | 4107270 | 2021-12-10 08:51:35 | [diff] [blame] | 43 | NewWindowCallback callback) override; |
ananubis | 9193c75 | 2021-08-13 12:51:13 | [diff] [blame] | 44 | void NewFullscreenWindow(const GURL& url, |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 45 | int64_t target_display_id, |
ananubis | 9193c75 | 2021-08-13 12:51:13 | [diff] [blame] | 46 | NewFullscreenWindowCallback callback) override; |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 47 | void NewGuestWindow(int64_t target_display_id, |
| 48 | NewGuestWindowCallback callback) override; |
Antonio Gomes | 8601b5c73 | 2021-10-14 15:41:47 | [diff] [blame] | 49 | void NewWindowForDetachingTab( |
| 50 | const std::u16string& tab_id, |
| 51 | const std::u16string& group_id, |
| 52 | NewWindowForDetachingTabCallback callback) override; |
Georg Neis | 4fda6e4 | 2023-02-07 02:04:06 | [diff] [blame] | 53 | void NewTab(NewTabCallback callback) override; |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 54 | void Launch(int64_t target_display_id, LaunchCallback callback) override; |
Hidehiko Abe | 46742a8 | 2022-01-27 08:03:30 | [diff] [blame] | 55 | void OpenUrl(const GURL& url, |
| 56 | crosapi::mojom::OpenUrlParamsPtr params, |
| 57 | OpenUrlCallback callback) override; |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 58 | void RestoreTab(RestoreTabCallback callback) override; |
Antonio Gomes | bc4799c | 2021-12-10 16:11:15 | [diff] [blame] | 59 | void HandleTabScrubbing(float x_offset) override; |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 60 | void GetFeedbackData(GetFeedbackDataCallback callback) override; |
| 61 | void GetHistograms(GetHistogramsCallback callback) override; |
| 62 | void GetActiveTabUrl(GetActiveTabUrlCallback callback) override; |
| 63 | void UpdateDeviceAccountPolicy(const std::vector<uint8_t>& policy) override; |
Sergiy Belozorov | b4243c3 | 2022-04-22 17:49:54 | [diff] [blame] | 64 | void NotifyPolicyFetchAttempt() override; |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 65 | void UpdateKeepAlive(bool enabled) override; |
Tom Lukaszewicz | f2a3d5b | 2022-06-28 06:38:30 | [diff] [blame] | 66 | void OpenForFullRestore(bool skip_crash_restore) override; |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 67 | |
| 68 | private: |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 69 | struct PendingOpenUrl; |
| 70 | |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 71 | void OnSystemInformationReady( |
| 72 | GetFeedbackDataCallback callback, |
| 73 | std::unique_ptr<system_logs::SystemLogsResponse> sys_info); |
| 74 | |
| 75 | void OnGetCompressedHistograms(GetHistogramsCallback callback, |
| 76 | const std::string& compressed_histogram); |
| 77 | |
Hidehiko Abe | 46742a8 | 2022-01-27 08:03:30 | [diff] [blame] | 78 | void OpenUrlImpl(Profile* profile, |
| 79 | const GURL& url, |
| 80 | crosapi::mojom::OpenUrlParamsPtr params, |
| 81 | OpenUrlCallback callback); |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 82 | |
David Roger | 0d56420 | 2022-01-20 15:44:05 | [diff] [blame] | 83 | // These *WithProfile() methods are called asynchronously by the corresponding |
| 84 | // profile-less function, after loading the profile. |
| 85 | void NewWindowWithProfile(bool incognito, |
| 86 | bool should_trigger_session_restore, |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 87 | int64_t target_display_id, |
David Roger | 0d56420 | 2022-01-20 15:44:05 | [diff] [blame] | 88 | NewWindowCallback callback, |
| 89 | Profile* profile); |
| 90 | void NewFullscreenWindowWithProfile(const GURL& url, |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 91 | int64_t target_display_id, |
David Roger | 0d56420 | 2022-01-20 15:44:05 | [diff] [blame] | 92 | NewFullscreenWindowCallback callback, |
| 93 | Profile* profile); |
| 94 | void NewWindowForDetachingTabWithProfile( |
| 95 | const std::u16string& tab_id, |
| 96 | const std::u16string& group_id, |
| 97 | NewWindowForDetachingTabCallback callback, |
| 98 | Profile* profile); |
Georg Neis | 92b0b27 | 2022-09-22 01:01:10 | [diff] [blame] | 99 | void LaunchOrNewTabWithProfile(bool should_trigger_session_restore, |
Mitsuru Oshima | 2d455aa2c | 2022-10-16 23:29:37 | [diff] [blame] | 100 | int64_t target_display_id, |
Georg Neis | 92b0b27 | 2022-09-22 01:01:10 | [diff] [blame] | 101 | NewTabCallback callback, |
| 102 | bool is_new_tab, |
| 103 | Profile* profile); |
David Roger | 0d56420 | 2022-01-20 15:44:05 | [diff] [blame] | 104 | void OpenUrlWithProfile(const GURL& url, |
Hidehiko Abe | 46742a8 | 2022-01-27 08:03:30 | [diff] [blame] | 105 | crosapi::mojom::OpenUrlParamsPtr params, |
David Roger | 0d56420 | 2022-01-20 15:44:05 | [diff] [blame] | 106 | OpenUrlCallback callback, |
| 107 | Profile* profile); |
| 108 | void RestoreTabWithProfile(RestoreTabCallback callback, Profile* profile); |
Tom Lukaszewicz | f2a3d5b | 2022-06-28 06:38:30 | [diff] [blame] | 109 | void OpenForFullRestoreWithProfile(bool skip_crash_restore, Profile* profile); |
Igor | a4b7a4e9 | 2022-05-04 12:30:19 | [diff] [blame] | 110 | void UpdateComponentPolicy(policy::ComponentPolicyMap policy) override; |
David Roger | 0d56420 | 2022-01-20 15:44:05 | [diff] [blame] | 111 | |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 112 | // Called when a session is restored. |
| 113 | void OnSessionRestored(Profile* profile, int num_tabs_restored); |
| 114 | |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 115 | // BrowserListObserver: |
| 116 | void OnBrowserAdded(Browser* browser) override; |
| 117 | |
| 118 | // Keeps the Lacros browser alive in the background. This is destroyed once |
| 119 | // any browser window is opened. |
| 120 | std::unique_ptr<ScopedKeepAlive> keep_alive_; |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 121 | std::vector<PendingOpenUrl> pending_open_urls_; |
Hidehiko Abe | 791e0cd | 2021-10-19 03:49:14 | [diff] [blame] | 122 | |
Hidehiko Abe | ffd96c3 | 2022-01-12 05:21:16 | [diff] [blame] | 123 | base::CallbackListSubscription session_restored_subscription_; |
Hidehiko Abe | a5b7a3f | 2021-07-02 00:10:37 | [diff] [blame] | 124 | mojo::Receiver<crosapi::mojom::BrowserService> receiver_{this}; |
Hidehiko Abe | 481a0b5f | 2021-06-30 08:59:39 | [diff] [blame] | 125 | base::WeakPtrFactory<BrowserServiceLacros> weak_ptr_factory_{this}; |
| 126 | }; |
| 127 | |
| 128 | #endif // CHROME_BROWSER_LACROS_BROWSER_SERVICE_LACROS_H_ |