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
3 // found in the LICENSE file.
8 * Manage the installation of apps.
10 * @param {string} itemId Item id to be installed.
12 * @extends {cr.EventType}
14 function AppInstaller(itemId) {
15 this.itemId_ = itemId;
16 this.callback_ = null;
21 AppInstaller.prototype = {
30 AppInstaller.Result = {
31 SUCCESS: 'AppInstaller.success',
32 CANCELLED: 'AppInstaller.cancelled',
33 ERROR: 'AppInstaller.error'
35 Object.freeze(AppInstaller.Result);
38 * Error message for user cancellation. This must be match with the constant
39 * 'kUserCancelledError' in C/B/extensions/webstore_standalone_installer.cc.
44 AppInstaller.USER_CANCELLED_ERROR_STR_ = 'User cancelled install';
47 * Start an installation.
48 * @param {function(boolean, string)} callback Called when the installation is
51 AppInstaller.prototype.install = function(callback) {
52 this.callback_ = callback;
53 chrome.fileBrowserPrivate.installWebstoreItem(
56 this.onInstallCompleted_(chrome.runtime.lastError);
61 * Called when the installation is completed.
63 * @param {{message: string}?} error Null if the installation is success,
64 * otherwise an object which contains error message.
67 AppInstaller.prototype.onInstallCompleted_ = function(error) {
68 var installerResult = AppInstaller.Result.SUCCESS;
69 var errorMessage = '';
72 error.message == AppInstaller.USER_CANCELLED_ERROR_STR_ ?
73 AppInstaller.Result.CANCELLED :
74 AppInstaller.Result.ERROR;
75 errorMessage = error.message;
77 this.callback_(installerResult, errorMessage);
78 this.callback_ = null;