summaryrefslogtreecommitdiffstats
path: root/components/mus/mus_app.h
blob: c058c5fe2d47f7b6d2647bea9bbe63155fca4246 (plain)
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_MUS_MUS_APP_H_
#define COMPONENTS_MUS_MUS_APP_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/mus/public/interfaces/display.mojom.h"
#include "components/mus/public/interfaces/gpu.mojom.h"
#include "components/mus/public/interfaces/window_manager_factory.mojom.h"
#include "components/mus/public/interfaces/window_tree.mojom.h"
#include "components/mus/public/interfaces/window_tree_host.mojom.h"
#include "components/mus/ws/connection_manager_delegate.h"
#include "mojo/public/cpp/bindings/weak_binding_set.h"
#include "mojo/services/tracing/public/cpp/tracing_impl.h"
#include "mojo/shell/public/cpp/interface_factory.h"
#include "mojo/shell/public/cpp/shell_client.h"

namespace mojo {
class Shell;
}

namespace ui {
class PlatformEventSource;
}

namespace mus {

class GpuState;
class SurfacesState;

namespace ws {
class ConnectionManager;
class ForwardingWindowManager;
class WindowTreeFactory;
}

class MandolineUIServicesApp
    : public mojo::ShellClient,
      public ws::ConnectionManagerDelegate,
      public mojo::InterfaceFactory<mojom::DisplayManager>,
      public mojo::InterfaceFactory<mojom::WindowManagerFactoryService>,
      public mojo::InterfaceFactory<mojom::WindowTreeFactory>,
      public mojo::InterfaceFactory<mojom::WindowTreeHostFactory>,
      public mojo::InterfaceFactory<mojom::Gpu>,
      public mojom::WindowTreeHostFactory {
 public:
  MandolineUIServicesApp();
  ~MandolineUIServicesApp() override;

 private:
  // Holds InterfaceRequests received before the first WindowTreeHost Display
  // has been established.
  struct PendingRequest;

  void InitializeResources(mojo::Shell* shell);

  // mojo::ShellClient:
  void Initialize(mojo::Shell* shell, const std::string& url,
                  uint32_t id, uint32_t user_id) override;
  bool AcceptConnection(mojo::Connection* connection) override;

  // ConnectionManagerDelegate:
  void OnFirstRootConnectionCreated() override;
  void OnNoMoreRootConnections() override;
  ws::ClientConnection* CreateClientConnectionForEmbedAtWindow(
      ws::ConnectionManager* connection_manager,
      mojo::InterfaceRequest<mojom::WindowTree> tree_request,
      ws::ServerWindow* root,
      uint32_t policy_bitmask,
      mojom::WindowTreeClientPtr client) override;

  // mojo::InterfaceFactory<mojom::DisplayManager> implementation.
  void Create(mojo::Connection* connection,
              mojo::InterfaceRequest<mojom::DisplayManager> request) override;

  // mojo::InterfaceFactory<mojom::WindowManagerFactoryService> implementation.
  void Create(mojo::Connection* connection,
              mojo::InterfaceRequest<mojom::WindowManagerFactoryService>
                  request) override;

  // mojo::InterfaceFactory<mojom::WindowTreeFactory>:
  void Create(
      mojo::Connection* connection,
      mojo::InterfaceRequest<mojom::WindowTreeFactory> request) override;

  // mojo::InterfaceFactory<mojom::WindowTreeHostFactory>:
  void Create(
      mojo::Connection* connection,
      mojo::InterfaceRequest<mojom::WindowTreeHostFactory> request) override;

  // mojo::InterfaceFactory<mojom::Gpu> implementation.
  void Create(mojo::Connection* connection,
              mojo::InterfaceRequest<mojom::Gpu> request) override;

  // mojom::WindowTreeHostFactory implementation.
  void CreateWindowTreeHost(mojo::InterfaceRequest<mojom::WindowTreeHost> host,
                            mojom::WindowTreeClientPtr tree_client) override;

  mojo::WeakBindingSet<mojom::WindowTreeHostFactory> factory_bindings_;
  mojo::Shell* shell_;
  scoped_ptr<ws::ConnectionManager> connection_manager_;
  scoped_refptr<GpuState> gpu_state_;
  scoped_ptr<ui::PlatformEventSource> event_source_;
  mojo::TracingImpl tracing_;
  using PendingRequests = std::vector<scoped_ptr<PendingRequest>>;
  PendingRequests pending_requests_;
  scoped_ptr<ws::WindowTreeFactory> window_tree_factory_;

  // Surfaces
  scoped_refptr<SurfacesState> surfaces_state_;

  DISALLOW_COPY_AND_ASSIGN(MandolineUIServicesApp);
};

}  // namespace mus

#endif  // COMPONENTS_MUS_MUS_APP_H_