summaryrefslogtreecommitdiffstats
path: root/components/mus/ws/window_manager_factory_service.cc
blob: b42456087b38c57d7c1b740c8fc6041e66780dbb (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
// Copyright 2016 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.

#include "components/mus/ws/window_manager_factory_service.h"

#include "base/bind.h"
#include "components/mus/ws/window_manager_factory_registry.h"
#include "components/mus/ws/window_tree.h"

namespace mus {
namespace ws {

WindowManagerFactoryService::WindowManagerFactoryService(
    WindowManagerFactoryRegistry* registry,
    const UserId& user_id,
    mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request)
    : registry_(registry),
      user_id_(user_id),
      binding_(this, std::move(request)),
      window_manager_factory_(nullptr) {}

WindowManagerFactoryService::~WindowManagerFactoryService() {}

void WindowManagerFactoryService::SetWindowManagerFactory(
    mojom::WindowManagerFactoryPtr factory) {
  window_manager_factory_ptr_ = std::move(factory);
  binding_.set_connection_error_handler(base::Bind(
      &WindowManagerFactoryService::OnConnectionLost, base::Unretained(this)));
  SetWindowManagerFactoryImpl(window_manager_factory_ptr_.get());
}

WindowManagerFactoryService::WindowManagerFactoryService(
    WindowManagerFactoryRegistry* registry,
    const UserId& user_id)
    : registry_(registry),
      user_id_(user_id),
      binding_(this),
      window_manager_factory_(nullptr) {}

void WindowManagerFactoryService::SetWindowManagerFactoryImpl(
    mojom::WindowManagerFactory* factory) {
  DCHECK(!window_manager_factory_);
  window_manager_factory_ = factory;
  registry_->OnWindowManagerFactorySet(this);
}

void WindowManagerFactoryService::OnConnectionLost() {
  registry_->OnWindowManagerFactoryConnectionLost(this);
}

}  // namespace ws
}  // namespace mus