image_capture_device.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // 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. #ifndef COMPONENTS_STORAGE_MONITOR_IMAGE_CAPTURE_DEVICE_H_
  5. #define COMPONENTS_STORAGE_MONITOR_IMAGE_CAPTURE_DEVICE_H_
  6. #import <Foundation/Foundation.h>
  7. #import <ImageCaptureCore/ImageCaptureCore.h>
  8. #include "base/files/file.h"
  9. #include "base/files/file_path.h"
  10. #include "base/mac/foundation_util.h"
  11. #include "base/mac/scoped_nsobject.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "base/memory/weak_ptr.h"
  14. #include "base/strings/string_util.h"
  15. #include "base/strings/sys_string_conversions.h"
  16. #include "base/synchronization/lock.h"
  17. namespace storage_monitor {
  18. // Clients use this listener interface to get notifications about
  19. // events happening as a particular ImageCapture device is interacted with.
  20. // Clients drive the interaction through the ImageCaptureDeviceManager
  21. // and the ImageCaptureDevice classes, and get notifications of
  22. // events through this interface.
  23. class ImageCaptureDeviceListener {
  24. public:
  25. virtual ~ImageCaptureDeviceListener() {}
  26. // Get a notification that a particular item has been found on the device.
  27. // These calls will come automatically after a new device is initialized.
  28. // Names are in relative path form, so subdirectories and files in them will
  29. // be passed as "dir/subdir/filename". These same relative filenames should
  30. // be used as keys to download files.
  31. virtual void ItemAdded(const std::string& name,
  32. const base::File::Info& info) = 0;
  33. // Called when there are no more items to retrieve.
  34. virtual void NoMoreItems() = 0;
  35. // Called upon completion of a file download request.
  36. // Note: in NOT_FOUND error case, may be called inline with the download
  37. // request.
  38. virtual void DownloadedFile(const std::string& name,
  39. base::File::Error error) = 0;
  40. // Called to let the client know the device is removed. The client should
  41. // set the ImageCaptureDevice listener to null upon receiving this call.
  42. virtual void DeviceRemoved() = 0;
  43. };
  44. } // namespace storage_monitor
  45. // Interface to a camera device found by ImageCaptureCore. This class manages a
  46. // session to the camera and provides the backing interactions to present the
  47. // media files on it to the filesystem delegate. FilePaths will be artificial,
  48. // like "/$device_id/" + name.
  49. // Note that all interactions with this class must happen on the UI thread.
  50. @interface ImageCaptureDevice
  51. : NSObject<ICCameraDeviceDelegate, ICCameraDeviceDownloadDelegate> {
  52. @private
  53. base::scoped_nsobject<ICCameraDevice> _camera;
  54. base::WeakPtr<storage_monitor::ImageCaptureDeviceListener> _listener;
  55. bool _closing;
  56. }
  57. - (instancetype)initWithCameraDevice:(ICCameraDevice*)cameraDevice;
  58. - (void)setListener:
  59. (base::WeakPtr<storage_monitor::ImageCaptureDeviceListener>)listener;
  60. - (void)open;
  61. - (void)close;
  62. - (void)eject;
  63. // Download the given file |name| to the provided |local_path|. Completion
  64. // notice will be sent to the listener's DownloadedFile method. The name
  65. // should be of the same form as those sent to the listener's ItemAdded method.
  66. - (void)downloadFile:(const std::string&)name
  67. localPath:(const base::FilePath&)localPath;
  68. @end
  69. #endif // COMPONENTS_STORAGE_MONITOR_IMAGE_CAPTURE_DEVICE_H_