| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 package org.chromium.mojo.application; | |
| 6 | |
| 7 import org.chromium.mojo.bindings.InterfaceRequest; | |
| 8 import org.chromium.mojo.system.Core; | |
| 9 import org.chromium.mojo.system.MessagePipeHandle; | |
| 10 import org.chromium.mojo.system.MojoException; | |
| 11 import org.chromium.mojom.mojo.Application; | |
| 12 import org.chromium.mojom.mojo.ServiceProvider; | |
| 13 import org.chromium.mojom.mojo.Shell; | |
| 14 | |
| 15 import java.util.ArrayList; | |
| 16 | |
| 17 /** | |
| 18 * Utility class for communicating with the Shell, and provide Services to clien
ts. | |
| 19 */ | |
| 20 class ApplicationImpl implements Application { | |
| 21 private final ApplicationDelegate mApplicationDelegate; | |
| 22 private final ArrayList<ApplicationConnection> mIncomingConnections = | |
| 23 new ArrayList<ApplicationConnection>(); | |
| 24 private final Core mCore; | |
| 25 private Shell mShell; | |
| 26 | |
| 27 public ApplicationImpl( | |
| 28 ApplicationDelegate delegate, Core core, MessagePipeHandle applicati
onRequest) { | |
| 29 mApplicationDelegate = delegate; | |
| 30 mCore = core; | |
| 31 ApplicationImpl.MANAGER.bind(this, applicationRequest); | |
| 32 } | |
| 33 | |
| 34 @Override | |
| 35 public void initialize(Shell shell, String[] args, String url) { | |
| 36 mShell = shell; | |
| 37 mApplicationDelegate.initialize(shell, args, url); | |
| 38 } | |
| 39 | |
| 40 @Override | |
| 41 public void acceptConnection(String requestorUrl, InterfaceRequest<ServicePr
ovider> services, | |
| 42 ServiceProvider exposedServices, String connectionUrl) { | |
| 43 ApplicationConnection connection = | |
| 44 new ApplicationConnection(requestorUrl, exposedServices, connect
ionUrl); | |
| 45 if (services != null && mApplicationDelegate.configureIncomingConnection
(connection)) { | |
| 46 ServiceProvider.MANAGER.bind(connection.getLocalServiceProvider(), s
ervices); | |
| 47 mIncomingConnections.add(connection); | |
| 48 } else { | |
| 49 connection.close(); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 @Override | |
| 54 public void requestQuit() { | |
| 55 mApplicationDelegate.quit(); | |
| 56 for (ApplicationConnection connection : mIncomingConnections) { | |
| 57 connection.close(); | |
| 58 } | |
| 59 mCore.getCurrentRunLoop().quit(); | |
| 60 } | |
| 61 | |
| 62 @Override | |
| 63 public void close() { | |
| 64 if (mShell != null) { | |
| 65 mShell.close(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 @Override | |
| 70 public void onConnectionError(MojoException e) {} | |
| 71 } | |
| OLD | NEW |