OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Javascript for Mojo interface helpers and global variables, served from | 6 * Javascript for Mojo interface helpers and global variables, served from |
7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('interfaces', function() { | 10 cr.define('interfaces', function() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 adapter = interfaces.Connection.bindHandleToProxy( | 57 adapter = interfaces.Connection.bindHandleToProxy( |
58 response.adapter, | 58 response.adapter, |
59 interfaces.BluetoothAdapter.Adapter); | 59 interfaces.BluetoothAdapter.Adapter); |
60 | 60 |
61 Object.assign(interfaces, { | 61 Object.assign(interfaces, { |
62 DefaultAdapter: adapter, | 62 DefaultAdapter: adapter, |
63 }); | 63 }); |
64 }); | 64 }); |
65 } | 65 } |
66 | 66 |
67 var initialized = false; | 67 /** |
68 var initializePromise = null; | 68 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy |
| 69 * before any other code executes. |
| 70 * @return {!Promise} A promise firing once necessary setup has been completed. |
| 71 */ |
| 72 var setupFn = window.setupFn || function() { return Promise.resolve(); }; |
69 | 73 |
70 function initialize() { | 74 function initialize() { |
71 if (initialized) { | 75 return setupFn().then(initializeProxies); |
72 return Promise.resolve(); | |
73 } | |
74 | |
75 if (initializePromise) { | |
76 return initializePromise; | |
77 } | |
78 | |
79 initializePromise = initializeProxies().then(function() { | |
80 initialized = true; | |
81 }); | |
82 | |
83 return initializePromise; | |
84 } | 76 } |
85 | 77 |
86 return { | 78 return { |
87 initialize: initialize, | 79 initialize: initialize, |
88 }; | 80 }; |
89 }); | 81 }); |
OLD | NEW |