blob: d4965aac904b8c46018eaed37bad03784a13025b [file] [log] [blame]
Viet-Trung Luu44a822a2015-12-17 13:26:27 -08001// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "services/view_manager/view_manager_app.h"
6
7#include "base/trace_event/trace_event.h"
8#include "mojo/application/application_runner_chromium.h"
9#include "mojo/common/tracing_impl.h"
10#include "mojo/public/c/system/main.h"
11#include "mojo/public/cpp/application/application_connection.h"
12#include "mojo/public/cpp/application/application_impl.h"
13#include "services/view_manager/view_manager_root_connection.h"
14
15using mojo::ApplicationConnection;
16using mojo::ApplicationImpl;
17using mojo::InterfaceRequest;
18using mojo::ViewManagerService;
19using mojo::WindowManagerInternalClient;
20
21namespace view_manager {
22
23ViewManagerApp::ViewManagerApp() : app_impl_(nullptr) {}
24
25ViewManagerApp::~ViewManagerApp() {}
26
27void ViewManagerApp::Initialize(ApplicationImpl* app) {
28 app_impl_ = app;
29 tracing_.Initialize(app);
30 TRACE_EVENT0("view_manager", __func__);
31}
32
33bool ViewManagerApp::ConfigureIncomingConnection(
34 ApplicationConnection* connection) {
35 TRACE_EVENT0("view_manager", __func__);
36 // We keep a raw pointer in active_root_connections_ in order to be able to
37 // close the ViewManagerApp when all outstanding ViewManagerRootConnections
38 // are closed. ViewManagerRootConnection manages its own lifetime.
39 ViewManagerRootConnection* root_connection =
40 new ViewManagerRootConnection(app_impl_, this);
41 if (root_connection->Init(connection)) {
42 active_root_connections_.insert(root_connection);
43 return true;
44 } else {
45 return false;
46 }
47}
48
49void ViewManagerApp::OnCloseViewManagerRootConnection(
50 ViewManagerRootConnection* view_manager_root_connection) {
51 active_root_connections_.erase(view_manager_root_connection);
52
53 if (active_root_connections_.size() == 0) {
54 ApplicationImpl::Terminate();
55 }
56}
57
58} // namespace view_manager