summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/people_page/import_data_browser_proxy.js
blob: 47c80a28a9d4cf0b7bd519fc0c3fe848752c6660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview A helper object used from the the Import Data dialog to allow
 * users to import data (like bookmarks) from other web browsers.
 */
cr.exportPath('settings');

/**
 * An object describing a source browser profile that may be imported.
 * The structure of this data must be kept in sync with C++ ImportDataHandler.
 * @typedef {{
 *   name: string,
 *   index: number,
 *   history: boolean,
 *   favorites: boolean,
 *   passwords: boolean,
 *   search: boolean,
 *   autofillFormData: boolean,
 * }}
 */
settings.BrowserProfile;

/**
 * @enum {string}
 * These string values must be kept in sync with the C++ ImportDataHandler.
 */
settings.ImportDataStatus = {
  INITIAL: 'initial',
  IN_PROGRESS: 'inProgress',
  SUCCEEDED: 'succeeded',
  FAILED: 'failed',
};

cr.define('settings', function() {
  /** @interface */
  class ImportDataBrowserProxy {
    /**
     * Returns the source profiles available for importing from other browsers.
     * @return {!Promise<!Array<!settings.BrowserProfile>>}
     */
    initializeImportDialog() {}

    /**
     * Starts importing data for the specified source browser profile. The C++
     * responds with the 'import-data-status-changed' WebUIListener event.
     * @param {number} sourceBrowserProfileIndex
     */
    importData(sourceBrowserProfileIndex) {}

    /**
     * Prompts the user to choose a bookmarks file to import bookmarks from.
     */
    importFromBookmarksFile() {}
  }

  /**
   * @implements {settings.ImportDataBrowserProxy}
   */
  class ImportDataBrowserProxyImpl {
    /** @override */
    initializeImportDialog() {
      return cr.sendWithPromise('initializeImportDialog');
    }

    /** @override */
    importData(sourceBrowserProfileIndex) {
      chrome.send('importData', [sourceBrowserProfileIndex]);
    }

    /** @override */
    importFromBookmarksFile() {
      chrome.send('importFromBookmarksFile');
    }
  }

  // The singleton instance_ is replaced with a test version of this wrapper
  // during testing.
  cr.addSingletonGetter(ImportDataBrowserProxyImpl);

  return {
    ImportDataBrowserProxy: ImportDataBrowserProxy,
    ImportDataBrowserProxyImpl: ImportDataBrowserProxyImpl,
  };
});