148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner// Copyright 2014 The Chromium Authors. All rights reserved.
29769ab22265b313171d201b5928688524a01bd87Misha Brukman// Use of this source code is governed by a BSD-style license that can be
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// found in the LICENSE file.
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner#ifndef COMPONENTS_STORAGE_MONITOR_IMAGE_CAPTURE_DEVICE_H_
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner#define COMPONENTS_STORAGE_MONITOR_IMAGE_CAPTURE_DEVICE_H_
79769ab22265b313171d201b5928688524a01bd87Misha Brukman
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell#import <Foundation/Foundation.h>
9d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner#import <ImageCaptureCore/ImageCaptureCore.h>
1049837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth
1149837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/files/file.h"
1249837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/files/file_path.h"
1349837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/mac/cocoa_protocols.h"
1449837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/mac/foundation_util.h"
1549837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/mac/scoped_nsobject.h"
1649837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/memory/ref_counted.h"
1749837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/memory/weak_ptr.h"
1849837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/strings/string_util.h"
1949837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/strings/sys_string_conversions.h"
2049837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth#include "base/synchronization/lock.h"
21d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner
22d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattnernamespace storage_monitor {
23d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner
24d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner// Clients use this listener interface to get notifications about
25d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner// events happening as a particular ImageCapture device is interacted with.
26d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner// Clients drive the interaction through the ImageCaptureDeviceManager
2749837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth// and the ImageCaptureDevice classes, and get notifications of
28076124ef26ff67f88663bd11f3b4d6b3d3bb3a9dDouglas Gregor// events through this interface.
29d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekeclass ImageCaptureDeviceListener {
30d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke public:
3149837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth  virtual ~ImageCaptureDeviceListener() {}
3249837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth
3349837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth  // Get a notification that a particular item has been found on the device.
3449837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth  // These calls will come automatically after a new device is initialized.
3549837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth  // Names are in relative path form, so subdirectories and files in them will
3640be1e85665d10f5444186f0e7106e368dd735b8Filip Pizlo  // be passed as "dir/subdir/filename". These same relative filenames should
3749837ef8111fbeace7ae6379ca733c8f8fa94cfeChandler Carruth  // be used as keys to download files.
38d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke  virtual void ItemAdded(const std::string& name,
39d30efaf56ed1e374240b4c2fe2ea7054cbd7cb52Chris Lattner                         const base::File::Info& info) = 0;
40
41  // Called when there are no more items to retrieve.
42  virtual void NoMoreItems() = 0;
43
44  // Called upon completion of a file download request.
45  // Note: in NOT_FOUND error case, may be called inline with the download
46  // request.
47  virtual void DownloadedFile(const std::string& name,
48                              base::File::Error error) = 0;
49
50  // Called to let the client know the device is removed. The client should
51  // set the ImageCaptureDevice listener to null upon receiving this call.
52  virtual void DeviceRemoved() = 0;
53};
54
55}  // namespace storage_monitor
56
57// Interface to a camera device found by ImageCaptureCore. This class manages a
58// session to the camera and provides the backing interactions to present the
59// media files on it to the filesystem delegate. FilePaths will be artificial,
60// like "/$device_id/" + name.
61// Note that all interactions with this class must happen on the UI thread.
62@interface ImageCaptureDevice
63    : NSObject<ICCameraDeviceDelegate, ICCameraDeviceDownloadDelegate> {
64 @private
65  base::scoped_nsobject<ICCameraDevice> camera_;
66  base::WeakPtr<storage_monitor::ImageCaptureDeviceListener> listener_;
67  bool closing_;
68}
69
70- (id)initWithCameraDevice:(ICCameraDevice*)cameraDevice;
71- (void)setListener:
72        (base::WeakPtr<storage_monitor::ImageCaptureDeviceListener>)listener;
73- (void)open;
74- (void)close;
75
76- (void)eject;
77
78// Download the given file |name| to the provided |local_path|. Completion
79// notice will be sent to the listener's DownloadedFile method. The name
80// should be of the same form as those sent to the listener's ItemAdded method.
81- (void)downloadFile:(const std::string&)name
82           localPath:(const base::FilePath&)localPath;
83
84@end
85
86#endif  // COMPONENTS_STORAGE_MONITOR_IMAGE_CAPTURE_DEVICE_H_
87