File: app_shim_host_bootstrap_mac.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 (114 lines) | stat: -rw-r--r-- 4,708 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
// Copyright 2018 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_APPS_APP_SHIM_APP_SHIM_HOST_BOOTSTRAP_MAC_H_
#define CHROME_BROWSER_APPS_APP_SHIM_APP_SHIM_HOST_BOOTSTRAP_MAC_H_

#include <memory>
#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/process/process_handle.h"
#include "base/threading/thread_checker.h"
#include "chrome/browser/apps/app_shim/app_shim_host_mac.h"
#include "chrome/common/mac/app_shim.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/system/isolated_connection.h"
#include "url/gurl.h"

class AppShimHostBootstrap : public chrome::mojom::AppShimHostBootstrap {
 public:
  // The interface through which the AppShimHostBootstrap registers itself
  // with the AppShimManager.
  class Client {
   public:
    // Invoked by the AppShimHostBootstrap when a shim process has connected to
    // the browser process. This will connect to (creating, if needed) an
    // AppShimHost. |bootstrap| must have OnConnectedToHost or
    // OnFailedToConnectToHost called on it to inform the shim of the result.
    virtual void OnShimProcessConnected(
        std::unique_ptr<AppShimHostBootstrap> bootstrap) = 0;
  };

  // Set the client interface that all objects of this class will use.
  static void SetClient(Client* client);

  // Creates a new server-side mojo channel at |endpoint|, which contains a
  // a Mach port for a channel created by an MachBootstrapAcceptor, and
  // begins listening for messages on it. The audit token of the sender of
  // |endpoint| is stored in |audit_token|.
  static void CreateForChannelAndPeerAuditToken(
      mojo::PlatformChannelEndpoint endpoint,
      audit_token_t audit_token);

  AppShimHostBootstrap(const AppShimHostBootstrap&) = delete;
  AppShimHostBootstrap& operator=(const AppShimHostBootstrap&) = delete;
  ~AppShimHostBootstrap() override;

  // Called in response to connecting (or failing to connect to) an
  // AppShimHost.
  void OnConnectedToHost(
      mojo::PendingReceiver<chrome::mojom::AppShim> app_shim_receiver);
  void OnFailedToConnectToHost(chrome::mojom::AppShimLaunchResult result);

  base::ProcessId GetAppShimPid() const;
  audit_token_t GetAppShimAuditToken() const { return audit_token_; }

  mojo::PendingReceiver<chrome::mojom::AppShimHost> GetAppShimHostReceiver();
  const std::string& GetAppId() const;
  const GURL& GetAppURL();
  const base::FilePath& GetProfilePath();

  // Indicates the type of launch (by Chrome or from the app).
  chrome::mojom::AppShimLaunchType GetLaunchType() const;

  // If non-empty, holds an array of file paths given as arguments, or dragged
  // onto the app bundle or dock icon.
  const std::vector<base::FilePath>& GetLaunchFiles() const;

  // Indicates if the app launched during OS login.
  chrome::mojom::AppShimLoginItemRestoreState GetLoginItemRestoreState() const;

  // If non-empty, holds an array of urls given as arguments.
  const std::vector<GURL>& GetLaunchUrls() const;

  // Returns the notification action handler receiver (if any) that was passed
  // by the app shim on launch.
  mojo::PendingReceiver<mac_notifications::mojom::MacNotificationActionHandler>
  TakeNotificationActionHandler();

  // Returns true if this app supports multiple profiles. If so, it will not be
  // required that GetProfilePath be a valid profile path.
  bool IsMultiProfile() const;

 protected:
  explicit AppShimHostBootstrap(audit_token_t audit_token);
  void ServeChannel(mojo::PlatformChannelEndpoint endpoint);
  void ChannelError(uint32_t custom_reason, const std::string& description);

  // chrome::mojom::AppShimHostBootstrap.
  void OnShimConnected(
      mojo::PendingReceiver<chrome::mojom::AppShimHost> app_shim_host_receiver,
      chrome::mojom::AppShimInfoPtr app_shim_info,
      OnShimConnectedCallback callback) override;

  mojo::IsolatedConnection bootstrap_mojo_connection_;
  mojo::Receiver<chrome::mojom::AppShimHostBootstrap> host_bootstrap_receiver_{
      this};

  // The arguments from the OnShimConnected call, and whether or not it has
  // happened yet. The |app_shim_info_| is non-null if and only if a shim has
  // connected.
  audit_token_t audit_token_;
  mojo::PendingReceiver<chrome::mojom::AppShimHost> app_shim_host_receiver_;
  chrome::mojom::AppShimInfoPtr app_shim_info_;
  OnShimConnectedCallback shim_connected_callback_;

  THREAD_CHECKER(thread_checker_);
};

#endif  // CHROME_BROWSER_APPS_APP_SHIM_APP_SHIM_HOST_BOOTSTRAP_MAC_H_