File: eche_app_manager_factory.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 (165 lines) | stat: -rw-r--r-- 5,626 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// 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_ECHE_APP_ECHE_APP_MANAGER_FACTORY_H_
#define CHROME_BROWSER_ASH_ECHE_APP_ECHE_APP_MANAGER_FACTORY_H_

#include <optional>

#include "ash/webui/eche_app_ui/launch_app_helper.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "ui/gfx/image/image.h"

class Profile;

namespace ash {
namespace eche_app {

class EcheAppManager;
class EcheAppNotificationController;
class SystemInfo;
class AppsLaunchInfoProvider;

class LaunchedAppInfo {
 public:
  class Builder {
   public:
    Builder();
    ~Builder();

    std::unique_ptr<LaunchedAppInfo> Build() {
      return base::WrapUnique(new LaunchedAppInfo(package_name_, visible_name_,
                                                  user_id_, icon_, phone_name_,
                                                  apps_launch_info_provider_));
    }
    Builder& SetPackageName(const std::string& package_name) {
      package_name_ = package_name;
      return *this;
    }

    Builder& SetVisibleName(const std::u16string& visible_name) {
      visible_name_ = visible_name;
      return *this;
    }

    Builder& SetUserId(const std::optional<int64_t>& user_id) {
      user_id_ = user_id;
      return *this;
    }

    Builder& SetIcon(const gfx::Image& icon) {
      icon_ = icon;
      return *this;
    }

    Builder& SetPhoneName(const std::u16string& phone_name) {
      phone_name_ = phone_name;
      return *this;
    }

    Builder& SetAppsLaunchInfoProvider(
        AppsLaunchInfoProvider* apps_launch_info_provider) {
      apps_launch_info_provider_ = apps_launch_info_provider;
      return *this;
    }

   private:
    std::string package_name_;
    std::u16string visible_name_;
    std::optional<int64_t> user_id_;
    gfx::Image icon_;
    std::u16string phone_name_;
    raw_ptr<AppsLaunchInfoProvider> apps_launch_info_provider_;
  };

  LaunchedAppInfo() = delete;
  LaunchedAppInfo(const LaunchedAppInfo&) = delete;
  LaunchedAppInfo& operator=(const LaunchedAppInfo&) = delete;
  ~LaunchedAppInfo();

  std::string package_name() const { return package_name_; }
  std::u16string visible_name() const { return visible_name_; }
  std::optional<int64_t> user_id() const { return user_id_; }
  gfx::Image icon() const { return icon_; }
  std::u16string phone_name() const { return phone_name_; }
  AppsLaunchInfoProvider* apps_launch_info_provider() {
    return apps_launch_info_provider_;
  }

 protected:
  LaunchedAppInfo(const std::string& package_name,
                  const std::u16string& visible_name,
                  const std::optional<int64_t>& user_id,
                  const gfx::Image& icon,
                  const std::u16string& phone_name,
                  AppsLaunchInfoProvider* apps_launch_info_provider);

 private:
  std::string package_name_;
  std::u16string visible_name_;
  std::optional<int64_t> user_id_;
  gfx::Image icon_;
  std::u16string phone_name_;
  raw_ptr<AppsLaunchInfoProvider, DanglingUntriaged> apps_launch_info_provider_;
};

// Factory to create a single EcheAppManager.
class EcheAppManagerFactory : public ProfileKeyedServiceFactory {
 public:
  static EcheAppManager* GetForProfile(Profile* profile);
  static EcheAppManagerFactory* GetInstance();
  static void ShowNotification(
      base::WeakPtr<EcheAppManagerFactory> weak_ptr,
      Profile* profile,
      const std::optional<std::u16string>& title,
      const std::optional<std::u16string>& message,
      std::unique_ptr<LaunchAppHelper::NotificationInfo> info);
  static void CloseNotification(base::WeakPtr<EcheAppManagerFactory> weak_ptr,
                                Profile* profile,
                                const std::string& notification_id);
  static void LaunchEcheApp(Profile* profile,
                            const std::optional<int64_t>& notification_id,
                            const std::string& package_name,
                            const std::u16string& visible_name,
                            const std::optional<int64_t>& user_id,
                            const gfx::Image& icon,
                            const std::u16string& phone_name,
                            AppsLaunchInfoProvider* apps_launch_info_provider);

  void SetLastLaunchedAppInfo(
      std::unique_ptr<LaunchedAppInfo> last_launched_app_info);
  std::unique_ptr<LaunchedAppInfo> GetLastLaunchedAppInfo();
  void CloseConnectionOrLaunchErrorNotifications();

  EcheAppManagerFactory(const EcheAppManagerFactory&) = delete;
  EcheAppManagerFactory& operator=(const EcheAppManagerFactory&) = delete;

  std::unique_ptr<SystemInfo> GetSystemInfo(Profile* profile) const;

 private:
  friend base::NoDestructor<EcheAppManagerFactory>;
  friend class EcheAppManagerFactoryTest;

  EcheAppManagerFactory();
  ~EcheAppManagerFactory() override;

  // BrowserContextKeyedServiceFactory:
  std::unique_ptr<KeyedService> BuildServiceInstanceForBrowserContext(
      content::BrowserContext* context) const override;
  void RegisterProfilePrefs(
      user_prefs::PrefRegistrySyncable* registry) override;

  std::unique_ptr<LaunchedAppInfo> last_launched_app_info_;

  std::unique_ptr<EcheAppNotificationController> notification_controller_;
  base::WeakPtrFactory<EcheAppManagerFactory> weak_ptr_factory_{this};
};

}  // namespace eche_app
}  // namespace ash

#endif  // CHROME_BROWSER_ASH_ECHE_APP_ECHE_APP_MANAGER_FACTORY_H_