[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / browser_process_platform_part_chromeos.h
1 // Copyright 2022 The Chromium Authors
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_BROWSER_PROCESS_PLATFORM_PART_CHROMEOS_H_
6 #define CHROME_BROWSER_BROWSER_PROCESS_PLATFORM_PART_CHROMEOS_H_
7
8 #include "base/callback_list.h"
9 #include "base/sequence_checker.h"
10 #include "chrome/browser/browser_process_platform_part_base.h"
11 #include "chrome/browser/ui/browser_list_observer.h"
12
13 class Browser;
14 class Profile;
15
16 class BrowserProcessPlatformPartChromeOS
17     : public BrowserProcessPlatformPartBase {
18  public:
19   BrowserProcessPlatformPartChromeOS();
20
21   BrowserProcessPlatformPartChromeOS(
22       const BrowserProcessPlatformPartChromeOS&) = delete;
23   BrowserProcessPlatformPartChromeOS& operator=(
24       const BrowserProcessPlatformPartChromeOS&) = delete;
25
26   ~BrowserProcessPlatformPartChromeOS() override;
27
28  protected:
29   // Returns true if we can restore URLs for `profile`. Restoring URLs should
30   // only be allowed for regular signed-in users. This is currently virtual as
31   // lacros-chrome and ash-chrome check this in different ways.
32   // TODO(tluk): Have both ash-chrome and lacros-chrome share the same profile
33   // check code.
34   virtual bool CanRestoreUrlsForProfile(const Profile* profile) const;
35
36  private:
37   // An observer that restores urls based on the on startup setting after a new
38   // browser is added to the BrowserList.
39   class BrowserRestoreObserver : public BrowserListObserver {
40    public:
41     explicit BrowserRestoreObserver(const BrowserProcessPlatformPartChromeOS*
42                                         browser_process_platform_part);
43
44     ~BrowserRestoreObserver() override;
45
46    protected:
47     // BrowserListObserver:
48     void OnBrowserAdded(Browser* browser) override;
49
50    private:
51     // Returns true, if the url defined in the on startup setting should be
52     // opened. Otherwise, returns false.
53     bool ShouldRestoreUrls(Browser* browser) const;
54
55     // Returns true, if the url defined in the on startup setting should be
56     // opened in a new browser. Otherwise, returns false.
57     bool ShouldOpenUrlsInNewBrowser(Browser* browser) const;
58
59     // Restores urls based on the on startup setting.
60     void RestoreUrls(Browser* browser);
61
62     // Called when a session is restored.
63     void OnSessionRestoreDone(Profile* profile, int num_tabs_restored);
64
65     const raw_ptr<const BrowserProcessPlatformPartChromeOS>
66         browser_process_platform_part_;
67
68     base::CallbackListSubscription on_session_restored_callback_subscription_;
69   };
70
71   BrowserRestoreObserver browser_restore_observer_;
72 };
73
74 #endif  // CHROME_BROWSER_BROWSER_PROCESS_PLATFORM_PART_CHROMEOS_H_