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_CAMERA_H_ | |
6 #define CHROME_BROWSER_SYSTEM_MONITOR_IMAGE_CAPTURE_CAMERA_H_ | |
7 | |
8 #import <Foundation/Foundation.h> | |
9 #import <ImageCaptureCore/ImageCaptureCore.h> | |
10 | |
11 #include "base/file_path.h" | |
12 #include "base/mac/foundation_util.h" | |
13 #include "base/memory/scoped_nsobject.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/platform_file.h" | |
16 #include "base/string_util.h" | |
17 #include "base/sys_string_conversions.h" | |
18 | |
19 // Client's use this listener interface to get notifications about | |
20 // events happening as a particular ImageCapture device is interacted with. | |
21 // Clients drive the interaction through the ImageCaptureDeviceBrowserMac | |
22 // and the ImageCaptureCameraInterface classes, and get notifications of | |
23 // events through this interface. | |
24 class ImageCaptureDeviceListener { | |
25 public: | |
26 virtual ~ImageCaptureDeviceListener() {} | |
27 | |
28 // Get a notification that a particular item has been found on the device. | |
29 // These calls will come automatically after a new device is initialized. | |
30 virtual void ItemAdded(const std::string& name, | |
31 const base::PlatformFileInfo& info) = 0; | |
32 | |
33 // Called when there are no more items to retrieve. | |
34 virtual void NoMoreItems() = 0; | |
35 | |
36 // Called upon completion of a file download request. The |path| is the | |
37 // requested download file. Note: in NOT_FOUND error case, can be called | |
38 // inline with the download request. | |
39 virtual void DownloadedFile(const std::string& name, | |
40 base::PlatformFileError error) = 0; | |
41 | |
42 // Called to let the client know the device is removed. | |
43 virtual void DeviceRemoved() = 0; | |
44 }; | |
45 | |
46 // Interface to a camera device found by ImageCaptureCore. This class manages a | |
47 // session to the camera and provides the backing interactions to present the | |
48 // media files on it to the filesystem delegate. FilePaths will be artificial, | |
49 // like "/$device_id/" + name. | |
50 // Note on thread-safety. This class ends up involving three different threads. | |
51 // The client is expected to interact with setting up and tearing down the | |
52 // implementation within a single thread context which allows blocking | |
53 // (likely the browser blocking pool). The class is thread-compatible with that | |
54 // usage. It receives events from the ImageCaptureCore library on the UI thread, | |
55 // and will forward callbacks to the listener on that thread. It also uses the | |
56 // File thread for renaming files when necessary. | |
57 // In other words, setup and teardown need to be threaded, and for other | |
58 // interactions the caller needs to be thread-safe. For those reasons, the | |
59 // client supplies a WeakPtr callback interface. | |
sail
2012/12/14 19:27:32
The reference to WeakPtr can be removed. WeakPtr i
Greg Billock
2012/12/14 22:03:56
Oops! Editing here was imperfect. Just removed thi
sail
2012/12/14 22:14:48
WeakPtr is not thread safe. That means you can't p
| |
60 @interface ImageCaptureCameraInterface | |
61 : NSObject<ICCameraDeviceDelegate, ICCameraDeviceDownloadDelegate> { | |
62 @private | |
63 scoped_nsobject<ICCameraDevice> camera_; | |
64 // Weak pointer to this class' client. | |
sail
2012/12/14 19:27:32
don't need this comment anymore
Greg Billock
2012/12/14 22:03:56
Done.
| |
65 base::WeakPtr<ImageCaptureDeviceListener> listener_; | |
66 } | |
67 | |
68 - (id)initWithCameraDevice:(ICCameraDevice*)cameraDevice; | |
69 - (void)open; | |
70 - (void)close; | |
71 - (void)setListener:(base::WeakPtr<ImageCaptureDeviceListener>)listener; | |
72 | |
73 // Download the given |file| to the provided |local_path|. Completion notice | |
74 // will be sent to the listener's DownloadedFile method. | |
75 - (void)downloadFile:(const std::string&)name | |
76 localPath:(const FilePath&)localPath; | |
77 | |
78 @end | |
79 | |
80 #endif // CHROME_BROWSER_SYSTEM_MONITOR_IMAGE_CAPTURE_CAMERA_H_ | |
OLD | NEW |