Viet-Trung Luu | 44a822a | 2015-12-17 13:26:27 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | using mojo::ApplicationConnection; |
| 16 | using mojo::ApplicationImpl; |
| 17 | using mojo::InterfaceRequest; |
| 18 | using mojo::ViewManagerService; |
| 19 | using mojo::WindowManagerInternalClient; |
| 20 | |
| 21 | namespace view_manager { |
| 22 | |
| 23 | ViewManagerApp::ViewManagerApp() : app_impl_(nullptr) {} |
| 24 | |
| 25 | ViewManagerApp::~ViewManagerApp() {} |
| 26 | |
| 27 | void ViewManagerApp::Initialize(ApplicationImpl* app) { |
| 28 | app_impl_ = app; |
| 29 | tracing_.Initialize(app); |
| 30 | TRACE_EVENT0("view_manager", __func__); |
| 31 | } |
| 32 | |
| 33 | bool 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 | |
| 49 | void 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 |