image_writer.mojom 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright 2021 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. module crosapi.mojom;
  5. import "mojo/public/mojom/base/file_path.mojom";
  6. import "mojo/public/mojom/base/unguessable_token.mojom";
  7. import "url/mojom/url.mojom";
  8. // A struct representing a removable storage device.
  9. [Stable]
  10. struct RemovableStorageDevice {
  11. // Identifier for the storage unit.
  12. string storage_unit_id@0;
  13. // Capacity of the device in bytes.
  14. double capacity@1;
  15. // Vendor of the device.
  16. string vendor@2;
  17. // Model of the device.
  18. string model@3;
  19. // True if the device is removable.
  20. bool removable@4;
  21. };
  22. // The different stages of a write call.
  23. [Stable, Extensible]
  24. enum Stage {
  25. [Default] kUnknown = 0,
  26. kConfirmation = 1, /* prompting the user for confirmation */
  27. kDownload = 2, /* downloading image if a remote image was requested */
  28. kVerifyDownload = 3, /* verifying download matches image hash, if provided */
  29. kUnzip = 4, /* extracting image from the downloaded zip file */
  30. kWrite = 5, /* writing image to disk */
  31. kVerifyWrite = 6, /* verifying written image matches the downloaded one */
  32. };
  33. // Interface for image writer client. Implemented by lacros-chrome. Used by
  34. // ash-chrome to dispatch the extension events about the progress of writing
  35. // to the Lacros extension that initiates the remote writing in ash.
  36. [Stable, Uuid="18f14c56-9dea-480a-a7d1-9ef94c223f2e"]
  37. interface ImageWriterClient {
  38. // Dispatches OnWriteProgress event to the Lacros extension which initiates
  39. // the write request.
  40. DispatchOnWriteProgressEvent@0(
  41. Stage stage, uint32 percent_complete);
  42. // Dispatches OnWriteComplete event to the Lacros extension which initiates
  43. // the write request.
  44. DispatchOnWriteCompleteEvent@1();
  45. // Dispatches OnWriteError event to the Lacros extension which initiates
  46. // the write request. This reports the error occurred during the writing
  47. // operation to the removable device.
  48. DispatchOnWriteErrorEvent@2(
  49. Stage stage, uint32 percent_complete, string error);
  50. };
  51. // Interface for image writer. Implemented by ash-chrome. Used by lacros-chrome
  52. // to forward the removable disk operations to ash to support the image writer
  53. // private extension API in Lacros.
  54. [Stable, Uuid="13df62d0-b72c-46ed-9024-e8ee4a30590c"]
  55. interface ImageWriter {
  56. // Lists all the removable storage devices currently attached to the system.
  57. // Returns removable devices if the operation succeeds.
  58. ListRemovableStorageDevices@0()
  59. => (array<RemovableStorageDevice>? devices);
  60. // Destroys the partition table of a removable disk specified by
  61. // |storage_unit_id| from the request of a remote extension running in Lacros.
  62. // |remote_client| will be used to dispatch writing progress events back
  63. // to the remote extension which initiates DestroyPartitions.
  64. // Returns an error defined by extensions::image_writer::error
  65. // (see chrome/browser/extensions/api/image_writer_private/error_messages.cc)
  66. // such as error::kOperationAlreadyInProgress or error::kDeviceWriteError,
  67. // which are caught before performing writing operation on the removable
  68. // device.
  69. // |error| should be returned to the caller of the extension API
  70. // imageWriterPrivate.destroyPartitions.
  71. // Errors that occur while writing to the removable device are reported by
  72. // ImageWriterClient::DispatchOnWriteErrorEvent api.
  73. DestroyPartitions@1(string storage_unit_id,
  74. pending_remote<ImageWriterClient> remote_client)
  75. => (string? error);
  76. // Write an image downloaded from |image_url| to the disk specified by
  77. // |storage_unit_id|. Compare the download with |image_hash| if the optional
  78. // parameter is provided.
  79. // |remote_client| will be used to dispatch writing progress events back
  80. // to the remote extension which initiates WriteFromUrl.
  81. // Returns an error defined by extensions::image_writer::error
  82. // (see chrome/browser/extensions/api/image_writer_private/error_messages.cc)
  83. // such as error::kOperationAlreadyInProgress or error::kDeviceWriteError,
  84. // which are caught before performing writing operation on the removable
  85. // device.
  86. // |error| should be returned to the caller of the extension API
  87. // imageWriterPrivate.writeFromUrl.
  88. // Errors that occur while writing to the removable device are reported by
  89. // ImageWriterClient::DispatchOnWriteErrorEvent api.
  90. [MinVersion=1]
  91. WriteFromUrl@2(string storage_unit_id, url.mojom.Url image_url,
  92. string? image_hash, pending_remote<ImageWriterClient> remote_client)
  93. => (string? error);
  94. // Write an image supplied by a local file with |image_path| to the
  95. // disk specified by |storage_unit_id|.
  96. // |remote_client| will be used to dispatch writing progress events back
  97. // to the remote extension which initiates WriteFromFile.
  98. // Returns an error defined by extensions::image_writer::error
  99. // (see chrome/browser/extensions/api/image_writer_private/error_messages.cc)
  100. // such as error::kOperationAlreadyInProgress or error::kDeviceWriteError,
  101. // which are caught before performing writing operation on the removable
  102. // device.
  103. // |error| should be returned to the caller of the extension API
  104. // imageWriterPrivate.writeFromFile.
  105. // Errors that occur while writing to the removable device are reported by
  106. // ImageWriterClient::DispatchOnWriteErrorEvent api.
  107. [MinVersion=1]
  108. WriteFromFile@3(string storage_unit_id, mojo_base.mojom.FilePath image_path,
  109. pending_remote<ImageWriterClient> remote_client)
  110. => (string? error);
  111. };