blob: 9c044212e1268f2fd9921c1e96efe60d5716352c [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Hidehiko Abe481a0b5f2021-06-30 08:59:392// 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 Abe791e0cd2021-10-19 03:49:148#include <memory>
Antonio Gomes8601b5c732021-10-14 15:41:479#include <string>
10
Hidehiko Abeffd96c32022-01-12 05:21:1611#include "base/callback_list.h"
Hidehiko Abe481a0b5f2021-06-30 08:59:3912#include "base/memory/weak_ptr.h"
Hidehiko Abe791e0cd2021-10-19 03:49:1413#include "chrome/browser/ui/browser_list_observer.h"
Hidehiko Abe481a0b5f2021-06-30 08:59:3914#include "chromeos/crosapi/mojom/crosapi.mojom.h"
15#include "components/feedback/system_logs/system_logs_source.h"
Igora4b7a4e92022-05-04 12:30:1916#include "components/policy/core/common/values_util.h"
Hidehiko Abea5b7a3f2021-07-02 00:10:3717#include "mojo/public/cpp/bindings/receiver.h"
Hidehiko Abe481a0b5f2021-06-30 08:59:3918
Hidehiko Abe303a7cb2021-08-19 06:23:2219class GURL;
Hidehiko Abeffd96c32022-01-12 05:21:1620class Profile;
Hidehiko Abe791e0cd2021-10-19 03:49:1421class ScopedKeepAlive;
Hidehiko Abe303a7cb2021-08-19 06:23:2222
Hidehiko Abe481a0b5f2021-06-30 08:59:3923// BrowserSerivce's Lacros implementation.
Hidehiko Abea5b7a3f2021-07-02 00:10:3724// This handles the requests from ash-chrome.
Hidehiko Abe791e0cd2021-10-19 03:49:1425class BrowserServiceLacros : public crosapi::mojom::BrowserService,
26 public BrowserListObserver {
Hidehiko Abe481a0b5f2021-06-30 08:59:3927 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 Neis4fda6e42023-02-07 02:04:0636 void REMOVED_7(bool should_trigger_session_restore,
37 NewTabCallback callback) override;
Igora4b7a4e92022-05-04 12:30:1938 void REMOVED_16(base::flat_map<policy::PolicyNamespace, std::vector<uint8_t>>
39 policy) override;
Tom Lukaszewicz41072702021-12-10 08:51:3540 void NewWindow(bool incognito,
41 bool should_trigger_session_restore,
Mitsuru Oshima2d455aa2c2022-10-16 23:29:3742 int64_t target_display_id,
Tom Lukaszewicz41072702021-12-10 08:51:3543 NewWindowCallback callback) override;
ananubis9193c752021-08-13 12:51:1344 void NewFullscreenWindow(const GURL& url,
Mitsuru Oshima2d455aa2c2022-10-16 23:29:3745 int64_t target_display_id,
ananubis9193c752021-08-13 12:51:1346 NewFullscreenWindowCallback callback) override;
Mitsuru Oshima2d455aa2c2022-10-16 23:29:3747 void NewGuestWindow(int64_t target_display_id,
48 NewGuestWindowCallback callback) override;
Antonio Gomes8601b5c732021-10-14 15:41:4749 void NewWindowForDetachingTab(
50 const std::u16string& tab_id,
51 const std::u16string& group_id,
52 NewWindowForDetachingTabCallback callback) override;
Georg Neis4fda6e42023-02-07 02:04:0653 void NewTab(NewTabCallback callback) override;
Mitsuru Oshima2d455aa2c2022-10-16 23:29:3754 void Launch(int64_t target_display_id, LaunchCallback callback) override;
Hidehiko Abe46742a82022-01-27 08:03:3055 void OpenUrl(const GURL& url,
56 crosapi::mojom::OpenUrlParamsPtr params,
57 OpenUrlCallback callback) override;
Hidehiko Abe481a0b5f2021-06-30 08:59:3958 void RestoreTab(RestoreTabCallback callback) override;
Antonio Gomesbc4799c2021-12-10 16:11:1559 void HandleTabScrubbing(float x_offset) override;
Hidehiko Abe481a0b5f2021-06-30 08:59:3960 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 Belozorovb4243c32022-04-22 17:49:5464 void NotifyPolicyFetchAttempt() override;
Hidehiko Abe791e0cd2021-10-19 03:49:1465 void UpdateKeepAlive(bool enabled) override;
Tom Lukaszewiczf2a3d5b2022-06-28 06:38:3066 void OpenForFullRestore(bool skip_crash_restore) override;
Hidehiko Abe481a0b5f2021-06-30 08:59:3967
68 private:
Hidehiko Abeffd96c32022-01-12 05:21:1669 struct PendingOpenUrl;
70
Hidehiko Abe481a0b5f2021-06-30 08:59:3971 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 Abe46742a82022-01-27 08:03:3078 void OpenUrlImpl(Profile* profile,
79 const GURL& url,
80 crosapi::mojom::OpenUrlParamsPtr params,
81 OpenUrlCallback callback);
Hidehiko Abeffd96c32022-01-12 05:21:1682
David Roger0d564202022-01-20 15:44:0583 // 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 Oshima2d455aa2c2022-10-16 23:29:3787 int64_t target_display_id,
David Roger0d564202022-01-20 15:44:0588 NewWindowCallback callback,
89 Profile* profile);
90 void NewFullscreenWindowWithProfile(const GURL& url,
Mitsuru Oshima2d455aa2c2022-10-16 23:29:3791 int64_t target_display_id,
David Roger0d564202022-01-20 15:44:0592 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 Neis92b0b272022-09-22 01:01:1099 void LaunchOrNewTabWithProfile(bool should_trigger_session_restore,
Mitsuru Oshima2d455aa2c2022-10-16 23:29:37100 int64_t target_display_id,
Georg Neis92b0b272022-09-22 01:01:10101 NewTabCallback callback,
102 bool is_new_tab,
103 Profile* profile);
David Roger0d564202022-01-20 15:44:05104 void OpenUrlWithProfile(const GURL& url,
Hidehiko Abe46742a82022-01-27 08:03:30105 crosapi::mojom::OpenUrlParamsPtr params,
David Roger0d564202022-01-20 15:44:05106 OpenUrlCallback callback,
107 Profile* profile);
108 void RestoreTabWithProfile(RestoreTabCallback callback, Profile* profile);
Tom Lukaszewiczf2a3d5b2022-06-28 06:38:30109 void OpenForFullRestoreWithProfile(bool skip_crash_restore, Profile* profile);
Igora4b7a4e92022-05-04 12:30:19110 void UpdateComponentPolicy(policy::ComponentPolicyMap policy) override;
David Roger0d564202022-01-20 15:44:05111
Hidehiko Abeffd96c32022-01-12 05:21:16112 // Called when a session is restored.
113 void OnSessionRestored(Profile* profile, int num_tabs_restored);
114
Hidehiko Abe791e0cd2021-10-19 03:49:14115 // 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 Abeffd96c32022-01-12 05:21:16121 std::vector<PendingOpenUrl> pending_open_urls_;
Hidehiko Abe791e0cd2021-10-19 03:49:14122
Hidehiko Abeffd96c32022-01-12 05:21:16123 base::CallbackListSubscription session_restored_subscription_;
Hidehiko Abea5b7a3f2021-07-02 00:10:37124 mojo::Receiver<crosapi::mojom::BrowserService> receiver_{this};
Hidehiko Abe481a0b5f2021-06-30 08:59:39125 base::WeakPtrFactory<BrowserServiceLacros> weak_ptr_factory_{this};
126};
127
128#endif // CHROME_BROWSER_LACROS_BROWSER_SERVICE_LACROS_H_