| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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.sdk.internal; | |
| 6 | |
| 7 import java.net.SocketAddress; | |
| 8 | |
| 9 import org.chromium.sdk.BrowserFactory; | |
| 10 import org.chromium.sdk.ConnectionLogger; | |
| 11 import org.chromium.sdk.StandaloneVm; | |
| 12 import org.chromium.sdk.internal.standalonev8.StandaloneVmImpl; | |
| 13 import org.chromium.sdk.internal.transport.Connection; | |
| 14 import org.chromium.sdk.internal.transport.Handshaker; | |
| 15 import org.chromium.sdk.internal.transport.SocketConnection; | |
| 16 | |
| 17 /** | |
| 18 * A default implementation of the BrowserFactory interface. | |
| 19 * TODO: rename it somehow. It's not only a browser factory. | |
| 20 */ | |
| 21 public class BrowserFactoryImpl extends BrowserFactory { | |
| 22 | |
| 23 public static final BrowserFactoryImpl INSTANCE = new BrowserFactoryImpl(); | |
| 24 | |
| 25 private static final int DEFAULT_CONNECTION_TIMEOUT_MS = 1000; | |
| 26 | |
| 27 @Override | |
| 28 public StandaloneVm createStandalone(SocketAddress socketAddress, | |
| 29 ConnectionLogger connectionLogger) { | |
| 30 Handshaker.StandaloneV8 handshaker = new Handshaker.StandaloneV8Impl(); | |
| 31 SocketConnection connection = | |
| 32 new SocketConnection(socketAddress, getTimeout(), connectionLogger, hand
shaker); | |
| 33 return createStandalone(connection, handshaker); | |
| 34 } | |
| 35 | |
| 36 // Debug entry (no logger by definition) | |
| 37 StandaloneVmImpl createStandalone(Connection connection, Handshaker.Standalone
V8 handshaker) { | |
| 38 return new StandaloneVmImpl(connection, handshaker); | |
| 39 } | |
| 40 | |
| 41 private int getTimeout() { | |
| 42 String timeoutString = System.getProperty( | |
| 43 "org.chromium.sdk.client.connection.timeoutMs", | |
| 44 String.valueOf(DEFAULT_CONNECTION_TIMEOUT_MS)); | |
| 45 int timeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS; | |
| 46 try { | |
| 47 timeoutMs = Integer.parseInt(timeoutString); | |
| 48 } catch (NumberFormatException e) { | |
| 49 // fall through and use the default value | |
| 50 } | |
| 51 return timeoutMs; | |
| 52 } | |
| 53 | |
| 54 } | |
| OLD | NEW |