Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * Channel to the background script. | 6 * Channel to the background script. |
| 7 */ | 7 */ |
| 8 function Channel() { | 8 function Channel() { |
| 9 // Message port to use to communicate with background script. | |
| 10 this.port_ = null; | |
| 11 | |
| 12 // Registered message callbacks. | |
| 13 this.messageCallbacks_ = {}; | |
| 14 | |
| 15 // Internal request id to track pending requests. | |
| 16 this.nextInternalRequestId_ = 0; | |
|
dzhioev (left Google)
2015/06/10 20:04:19
This initialized with primitive type, so you can l
xiyuan
2015/06/10 20:21:12
Yes, we can leave it where it was. But do you thin
| |
| 17 | |
| 18 // Pending internal request callbacks. | |
| 19 this.internalRequestCallbacks_ = {}; | |
| 9 } | 20 } |
| 10 | 21 |
| 11 /** @const */ | 22 /** @const */ |
| 12 Channel.INTERNAL_REQUEST_MESSAGE = 'internal-request-message'; | 23 Channel.INTERNAL_REQUEST_MESSAGE = 'internal-request-message'; |
| 13 | 24 |
| 14 /** @const */ | 25 /** @const */ |
| 15 Channel.INTERNAL_REPLY_MESSAGE = 'internal-reply-message'; | 26 Channel.INTERNAL_REPLY_MESSAGE = 'internal-reply-message'; |
| 16 | 27 |
| 17 Channel.prototype = { | 28 Channel.prototype = { |
| 18 // Message port to use to communicate with background script. | |
| 19 port_: null, | |
| 20 | |
| 21 // Registered message callbacks. | |
| 22 messageCallbacks_: {}, | |
| 23 | |
| 24 // Internal request id to track pending requests. | |
| 25 nextInternalRequestId_: 0, | |
| 26 | |
| 27 // Pending internal request callbacks. | |
| 28 internalRequestCallbacks_: {}, | |
|
dzhioev (left Google)
2015/06/10 20:04:19
Same here
| |
| 29 | |
| 30 /** | 29 /** |
| 31 * Initialize the channel with given port for the background script. | 30 * Initialize the channel with given port for the background script. |
| 32 */ | 31 */ |
| 33 init: function(port) { | 32 init: function(port) { |
| 34 this.port_ = port; | 33 this.port_ = port; |
| 35 this.port_.onMessage.addListener(this.onMessage_.bind(this)); | 34 this.port_.onMessage.addListener(this.onMessage_.bind(this)); |
| 36 }, | 35 }, |
| 37 | 36 |
| 38 /** | 37 /** |
| 39 * Connects to the background script with the given name. | 38 * Connects to the background script with the given name. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 } | 109 } |
| 111 }; | 110 }; |
| 112 | 111 |
| 113 /** | 112 /** |
| 114 * Class factory. | 113 * Class factory. |
| 115 * @return {Channel} | 114 * @return {Channel} |
| 116 */ | 115 */ |
| 117 Channel.create = function() { | 116 Channel.create = function() { |
| 118 return new Channel(); | 117 return new Channel(); |
| 119 }; | 118 }; |
| OLD | NEW |