• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5// Use the <code>chrome.image_writer</code> API to write images to
6// removable media.
7//
8// See the design doc for a detailed description of this API.
9// https://goto.google.com/image-writer-private-designdoc
10[nodoc] namespace imageWriterPrivate {
11  // The different stages of a write call.
12  //
13  // <dl>
14  //    <dt>confirmation</dt>
15  //    <dd>The process starts by prompting the user for confirmation.</dd>
16  //    <dt>download</dt>
17  //    <dd>The image file is being download if a remote image was
18  //    requested.</dd>
19  //    <dt>verifyDownload</dt>
20  //    <dd>The download is being verified to match the image hash, if
21  //    provided</dd>
22  //    <dt>unzip</dt>
23  //    <dd>The image is being extracted from the downloaded zip file</dd>
24  //    <dt>write</dt>
25  //    <dd>The image is being written to disk.</dd>
26  //    <dt>verifyWrite</dt>
27  //    <dt>The system is verifying that the written image matches the
28  //    downloaded image.</dd>
29  // <dl>
30  enum Stage {
31    confirmation,
32    download,
33    verifyDownload,
34    unzip,
35    write,
36    verifyWrite,
37    unknown
38  };
39
40  // Options for writing an image.
41  dictionary UrlWriteOptions {
42    // If present, verify that the downloaded image matches this hash.
43    DOMString? imageHash;
44    // If true, save the downloaded image as a file using the user's downloads
45    // preferences.
46    boolean? saveAsDownload;
47  };
48
49  dictionary ProgressInfo {
50    // The $(ref:Stage) that the write process is currently in.
51    Stage stage;
52    // Current progress within the stage.
53    long percentComplete;
54  };
55
56  dictionary RemovableStorageDevice {
57    DOMString storageUnitId;
58    double capacity;
59    DOMString vendor;
60    DOMString model;
61    boolean removable;
62  };
63
64  callback WriteImageCallback = void ();
65  callback WriteCancelCallback = void ();
66  callback ListRemovableStorageDevicesCallback = void (RemovableStorageDevice[] devices);
67  callback DestroyPartitionsCallback = void ();
68
69  interface Functions {
70    // Write an image to the disk downloaded from the provided URL.  The
71    // callback will be called when the entire operation completes, either
72    // successfully or on error.
73    //
74    // |storageUnitId|: The identifier for the storage unit
75    // |imageUrl|: The url of the image to download which will be written
76    // to the storage unit identified by |storageUnitId|
77    // |options|: Optional parameters if comparing the download with a given
78    // hash or saving the download to the users Downloads folder instead of a
79    // temporary directory is desired
80    // |callback|: The callback which signifies that the write operation has
81    // been started by the system and provides a unique ID for this operation.
82    static void writeFromUrl(DOMString storageUnitId,
83                             DOMString imageUrl,
84                             optional UrlWriteOptions options,
85                             WriteImageCallback callback);
86
87    // Write an image to the disk, prompting the user to supply the image from
88    // a local file.  The callback will be called when the entire operation
89    // completes, either successfully or on error.
90    //
91    // |storageUnitId|: The identifier for the storage unit
92    // |fileEntry|: The FileEntry object of the image to be burned.
93    // |callback|: The callback which signifies that the write operation has
94    // been started by the system and provides a unique ID for this operation.
95    static void writeFromFile(DOMString storageUnitId,
96                              [instanceOf=FileEntry] object fileEntry,
97                              WriteImageCallback callback);
98
99    // Cancel a current write operation.
100    //
101    // |callback|: The callback which is triggered with the write is
102    // successfully cancelled, passing the $(ref:ProgressInfo) of the operation at
103    // the time it was cancelled.
104    static boolean cancelWrite(WriteCancelCallback callback);
105
106    // Destroys the partition table of a disk, effectively erasing it.  This is
107    // a fairly quick operation and so it does not have complex stages or
108    // progress information, just a write phase.
109    //
110    // |storageUnitId|: The identifier of the storage unit to wipe
111    // |callback|: A callback that triggers when the operation has been
112    // successfully started.
113    static void destroyPartitions(DOMString storageUnitId,
114                                  DestroyPartitionsCallback callback);
115
116    // List all the removable block devices currently attached to the system.
117    // |callback|: A callback called with a list of removable storage devices
118    static void listRemovableStorageDevices(
119        ListRemovableStorageDevicesCallback callback);
120  };
121
122  interface Events {
123    // Fires periodically throughout the writing operation and at least once per
124    // stage.
125    static void onWriteProgress(ProgressInfo info);
126
127    // Fires when the write operation has completely finished, such as all
128    // devices being finalized and resources released.
129    static void onWriteComplete();
130
131    // Fires when an error occured during writing, passing the $(ref:ProgressInfo)
132    // of the operation at the time the error occured.
133    static void onWriteError(ProgressInfo info, DOMString error);
134
135    // Fires when a removable storage device is inserted.
136    static void onDeviceInserted(RemovableStorageDevice device);
137
138    // Fires when a removable storage device is removed.
139    static void onDeviceRemoved(RemovableStorageDevice device);
140  };
141
142};
143
144