File: app_launch_handler.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 3,661 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_APP_RESTORE_APP_LAUNCH_HANDLER_H_
#define CHROME_BROWSER_ASH_APP_RESTORE_APP_LAUNCH_HANDLER_H_

#include <utility>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "components/app_restore/restore_data.h"
#include "components/services/app_service/public/cpp/app_registry_cache.h"
#include "components/services/app_service/public/cpp/app_types.h"

namespace apps {
class AppUpdate;
enum class AppTypeName;
}  // namespace apps

class Profile;

namespace ash {

// The AppLaunchHandler class launches apps from `restore_data_` as well as
// observes app updates.
class AppLaunchHandler : public apps::AppRegistryCache::Observer {
 public:
  explicit AppLaunchHandler(Profile* profile);
  AppLaunchHandler(const AppLaunchHandler&) = delete;
  AppLaunchHandler& operator=(const AppLaunchHandler&) = delete;
  ~AppLaunchHandler() override;

  // Returns true if there are some restore data. Otherwise, returns false.
  bool HasRestoreData() const;

  // Called when an app has launched. Overriders can use this to record
  // histograms based on `app_type_name`.
  virtual void RecordRestoredAppLaunch(apps::AppTypeName app_type_name) = 0;

  // apps::AppRegistryCache::Observer:
  void OnAppUpdate(const apps::AppUpdate& update) override;
  void OnAppTypeInitialized(apps::AppType app_type) override;
  void OnAppRegistryCacheWillBeDestroyed(
      apps::AppRegistryCache* cache) override;

  Profile* profile() { return profile_; }
  const Profile* profile() const { return profile_; }

  ::app_restore::RestoreData* restore_data() {
    return const_cast<::app_restore::RestoreData*>(
        std::as_const(*this).restore_data());
  }
  const ::app_restore::RestoreData* restore_data() const {
    return restore_data_.get();
  }

 protected:
  // Note: LaunchApps does not launch browser windows, this is handled
  // separately.
  void LaunchApps();

  // Protected for descendants.
  void ObserveCache(apps::AppRegistryCache* source);

  // Called before a system web app or chrome app is launched. Lets
  // subclasses decide if they want to move an existing window associated
  // with `app_id`, or continue with trying to launch the app. Optional
  // launch parameters may be present in `launch_list`.
  virtual bool ShouldLaunchSystemWebAppOrChromeApp(
      const std::string& app_id,
      const ::app_restore::RestoreData::LaunchList& launch_list);

  // Called before an extension type app is launched. Allows subclasses to
  // perform some setup prior to launching an extension type app.
  virtual void OnExtensionLaunching(const std::string& app_id) {}

  virtual base::WeakPtr<AppLaunchHandler> GetWeakPtrAppLaunchHandler() = 0;

  void set_restore_data(
      std::unique_ptr<::app_restore::RestoreData> restore_data) {
    restore_data_ = std::move(restore_data);
  }

 private:
  void LaunchApp(apps::AppType app_type, const std::string& app_id);

  virtual void LaunchSystemWebAppOrChromeApp(
      apps::AppType app_type,
      const std::string& app_id,
      const ::app_restore::RestoreData::LaunchList& launch_list);

  const raw_ptr<Profile, DanglingUntriaged> profile_;
  std::unique_ptr<::app_restore::RestoreData> restore_data_;

  base::ScopedObservation<apps::AppRegistryCache,
                          apps::AppRegistryCache::Observer>
      app_registry_cache_observer_{this};
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_APP_RESTORE_APP_LAUNCH_HANDLER_H_