|
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.Browser; |
|
10 import org.chromium.sdk.BrowserFactory; |
|
11 import org.chromium.sdk.ConnectionLogger; |
|
12 import org.chromium.sdk.StandaloneVm; |
|
13 import org.chromium.sdk.internal.transport.Handshaker; |
|
14 import org.chromium.sdk.internal.transport.SocketConnection; |
|
15 |
|
16 /** |
|
17 * A default implementation of the BrowserFactory interface. |
|
18 */ |
|
19 public class BrowserFactoryImpl extends BrowserFactory { |
|
20 |
|
21 private static final int DEFAULT_CONNECTION_TIMEOUT_MS = 1000; |
|
22 |
|
23 @Override |
|
24 public Browser create(SocketAddress socketAddress, |
|
25 ConnectionLogger.Factory connectionLoggerFactory) { |
|
26 SocketConnectionFactory socketConnectionFactory = new SocketConnectionFactory(socketAddress, |
|
27 getTimeout(), connectionLoggerFactory, Handshaker.CHROMIUM); |
|
28 return new BrowserImpl(socketConnectionFactory); |
|
29 } |
|
30 |
|
31 // Debug entry (no logger by definition) |
|
32 Browser create(ConnectionFactory connectionFactory) { |
|
33 return new BrowserImpl(connectionFactory); |
|
34 } |
|
35 |
|
36 @Override |
|
37 public StandaloneVm createStandalone(SocketAddress socketAddress, |
|
38 ConnectionLogger connectionLogger) { |
|
39 Handshaker.StandaloneV8 handshaker = new Handshaker.StandaloneV8(); |
|
40 SocketConnection connection = |
|
41 new SocketConnection(socketAddress, getTimeout(), connectionLogger, handshaker); |
|
42 return new StandaloneVmImpl(connection, handshaker); |
|
43 } |
|
44 |
|
45 private int getTimeout() { |
|
46 String timeoutString = System.getProperty( |
|
47 "org.chromium.sdk.client.connection.timeoutMs", |
|
48 String.valueOf(DEFAULT_CONNECTION_TIMEOUT_MS)); |
|
49 int timeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS; |
|
50 try { |
|
51 timeoutMs = Integer.parseInt(timeoutString); |
|
52 } catch (NumberFormatException e) { |
|
53 // fall through and use the default value |
|
54 } |
|
55 return timeoutMs; |
|
56 } |
|
57 |
|
58 } |