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, String connectionUrl, | |
42 InterfaceRequest<ServiceProvider> services) { | |
43 ApplicationConnection connection = new ApplicationConnection(requestorUr
l, connectionUrl); | |
44 if (services != null && mApplicationDelegate.configureIncomingConnection
(connection)) { | |
45 ServiceProvider.MANAGER.bind(connection.getLocalServiceProvider(), s
ervices); | |
46 mIncomingConnections.add(connection); | |
47 } else { | |
48 connection.close(); | |
49 } | |
50 } | |
51 | |
52 @Override | |
53 public void requestQuit() { | |
54 mApplicationDelegate.quit(); | |
55 for (ApplicationConnection connection : mIncomingConnections) { | |
56 connection.close(); | |
57 } | |
58 mCore.getCurrentRunLoop().quit(); | |
59 } | |
60 | |
61 @Override | |
62 public void close() { | |
63 if (mShell != null) { | |
64 mShell.close(); | |
65 } | |
66 } | |
67 | |
68 @Override | |
69 public void onConnectionError(MojoException e) {} | |
70 } | |
OLD | NEW |