OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_IMAGE_CAPTURE_DEVICE_H_ | |
6 #define CHROME_BROWSER_SYSTEM_MONITOR_IMAGE_CAPTURE_DEVICE_H_ | |
7 | |
8 #import <Foundation/Foundation.h> | |
9 #import <ImageCaptureCore/ImageCaptureCore.h> | |
10 | |
11 #include "base/file_path.h" | |
12 #include "base/mac/cocoa_protocols.h" | |
13 #include "base/mac/foundation_util.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/scoped_nsobject.h" | |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/platform_file.h" | |
18 #include "base/string_util.h" | |
19 #include "base/synchronization/lock.h" | |
20 #include "base/sys_string_conversions.h" | |
21 #include "base/task_runner.h" | |
22 | |
23 // Client's use this listener interface to get notifications about | |
24 // events happening as a particular ImageCapture device is interacted with. | |
25 // Clients drive the interaction through the ImageCaptureDeviceBrowserMac | |
26 // and the ImageCaptureCameraInterface classes, and get notifications of | |
27 // events through this interface. | |
28 class ImageCaptureDeviceListener { | |
29 public: | |
30 virtual ~ImageCaptureDeviceListener() {} | |
31 | |
32 // Get a notification that a particular item has been found on the device. | |
33 // These calls will come automatically after a new device is initialized. | |
34 virtual void ItemAdded(const std::string& name, | |
35 const base::PlatformFileInfo& info) = 0; | |
36 | |
37 // Called when there are no more items to retrieve. | |
38 virtual void NoMoreItems() = 0; | |
39 | |
40 // Called upon completion of a file download request. The |path| is the | |
41 // requested download file. Note: in NOT_FOUND error case, can be called | |
42 // inline with the download request. | |
43 virtual void DownloadedFile(const std::string& name, | |
44 base::PlatformFileError error) = 0; | |
45 | |
46 // Called to let the client know the device is removed. The client should | |
47 // set the ImageCaptureDevice listener to null upon receiving this call. | |
48 virtual void DeviceRemoved() = 0; | |
49 }; | |
50 | |
51 // Interface to a camera device found by ImageCaptureCore. This class manages a | |
52 // session to the camera and provides the backing interactions to present the | |
53 // media files on it to the filesystem delegate. FilePaths will be artificial, | |
54 // like "/$device_id/" + name. | |
55 // Note on thread-safety. This class ends up involving three different threads. | |
sail
2012/12/19 20:41:39
rest of this comment should be removed
| |
56 // The client is expected to interact with setting up and tearing down the | |
57 // implementation within a single thread context which allows blocking | |
58 // (likely the browser blocking pool). The TaskRunner on this thread is | |
59 // passed in and will be used in callbacks to the listener interface provided. | |
60 // The device object receives events from the ImageCaptureCore library on the | |
61 // UI thread, but also uses the File thread for renaming files when necessary. | |
62 @interface ImageCaptureDevice | |
63 : NSObject<ICCameraDeviceDelegate, ICCameraDeviceDownloadDelegate> { | |
64 @private | |
65 scoped_nsobject<ICCameraDevice> camera_; | |
66 base::WeakPtr<ImageCaptureDeviceListener> listener_; | |
67 scoped_refptr<base::TaskRunner> pool_; | |
68 } | |
69 | |
70 - (id)initWithCameraDevice:(ICCameraDevice*)cameraDevice; | |
71 - (void)setListener:(base::WeakPtr<ImageCaptureDeviceListener>)listener | |
72 taskRunner:(base::TaskRunner*)pool; | |
73 - (void)open; | |
74 - (void)close; | |
75 | |
76 // Download the given |file| to the provided |local_path|. Completion notice | |
77 // will be sent to the listener's DownloadedFile method. | |
78 - (void)downloadFile:(const std::string&)name | |
79 localPath:(const FilePath&)localPath; | |
80 | |
81 - (void)renamedFile:(const std::string&)name | |
82 result:(base::PlatformFileError)errorCode; | |
83 | |
84 @end | |
85 | |
86 #endif // CHROME_BROWSER_SYSTEM_MONITOR_IMAGE_CAPTURE_DEVICE_H_ | |
OLD | NEW |