blob: 71b4d4c4051416eaa343c71de50943012b2027d3 [file] [log] [blame]
sammcd9fddbc2014-10-28 01:07:001// Copyright 2014 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
Yuzhu Shend91c0f12017-11-20 22:51:175if ((typeof mojo === 'undefined') || !mojo.bindingsLibraryInitialized) {
6 loadScript('mojo_bindings');
7}
8loadScript('extensions/common/mojo/keep_alive.mojom');
sammcd9fddbc2014-10-28 01:07:009
Yuzhu Shend91c0f12017-11-20 22:51:1710/**
11 * An object that keeps the background page alive until closed.
12 * @constructor
13 * @alias module:keep_alive~KeepAlive
14 */
15function KeepAlive() {
16 var pipe = Mojo.createMessagePipe();
sammcd9fddbc2014-10-28 01:07:0017 /**
Yuzhu Shend91c0f12017-11-20 22:51:1718 * The handle to the keep-alive object in the browser.
19 * @type {!MojoHandle}
20 * @private
sammcd9fddbc2014-10-28 01:07:0021 */
Yuzhu Shend91c0f12017-11-20 22:51:1722 this.handle_ = pipe.handle0;
23 Mojo.bindInterface(extensions.KeepAlive.name, pipe.handle1);
24}
sammcd9fddbc2014-10-28 01:07:0025
Yuzhu Shend91c0f12017-11-20 22:51:1726/**
27 * Removes this keep-alive.
28 */
29KeepAlive.prototype.close = function() {
30 this.handle_.close();
31};
sammcd9fddbc2014-10-28 01:07:0032
Yuzhu Shend91c0f12017-11-20 22:51:1733/**
34 * Creates a keep-alive.
35 * @return {!module:keep_alive~KeepAlive} A new keep-alive.
36 */
37exports.$set('createKeepAlive', function() { return new KeepAlive(); });