Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: ios/chrome/browser/ui/qr_scanner/camera_controller.mm

Issue 2912373002: [iOS] Stop swizzling the |init| method of CameraController. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/qr_scanner/camera_controller.h" 5 #import "ios/chrome/browser/ui/qr_scanner/camera_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "ios/chrome/common/ios_app_bundle_id_prefix.h" 10 #include "ios/chrome/common/ios_app_bundle_id_prefix.h"
(...skipping 16 matching lines...) Expand all
27 27
28 // The current state of the camera. The state is set to CAMERA_NOT_LOADED before 28 // The current state of the camera. The state is set to CAMERA_NOT_LOADED before
29 // the camera is first loaded, and afterwards it is never CAMERA_NOT_LOADED. 29 // the camera is first loaded, and afterwards it is never CAMERA_NOT_LOADED.
30 @property(nonatomic, readwrite, assign) qr_scanner::CameraState cameraState; 30 @property(nonatomic, readwrite, assign) qr_scanner::CameraState cameraState;
31 // Redeclaration of |torchActive| to make the setter private. 31 // Redeclaration of |torchActive| to make the setter private.
32 @property(nonatomic, readwrite, assign, getter=isTorchActive) BOOL torchActive; 32 @property(nonatomic, readwrite, assign, getter=isTorchActive) BOOL torchActive;
33 // The current availability of the torch. 33 // The current availability of the torch.
34 @property(nonatomic, readwrite, assign, getter=isTorchAvailable) 34 @property(nonatomic, readwrite, assign, getter=isTorchAvailable)
35 BOOL torchAvailable; 35 BOOL torchAvailable;
36 36
37 // Initializes the controller with the |delegate|.
38 - (instancetype)initWithDelegate:(id<CameraControllerDelegate>)delegate
39 NS_DESIGNATED_INITIALIZER;
40
37 // YES if |cameraState| is CAMERA_AVAILABLE. 41 // YES if |cameraState| is CAMERA_AVAILABLE.
38 - (BOOL)isCameraAvailable; 42 - (BOOL)isCameraAvailable;
39 // Starts receiving notfications about changes to the capture session and to the 43 // Starts receiving notfications about changes to the capture session and to the
40 // torch properties. 44 // torch properties.
41 - (void)startReceivingNotifications; 45 - (void)startReceivingNotifications;
42 // Stops receiving all notifications. 46 // Stops receiving all notifications.
43 - (void)stopReceivingNotifications; 47 - (void)stopReceivingNotifications;
44 // Returns the camera attached to |_captureSession|. 48 // Returns the camera attached to |_captureSession|.
45 - (AVCaptureDevice*)getCamera; 49 - (AVCaptureDevice*)getCamera;
46 // Returns the AVCaptureVideoOrientation to compensate for the current 50 // Returns the AVCaptureVideoOrientation to compensate for the current
47 // UIInterfaceOrientation. Defaults to AVCaptureVideoOrientationPortrait. 51 // UIInterfaceOrientation. Defaults to AVCaptureVideoOrientationPortrait.
48 - (AVCaptureVideoOrientation)videoOrientationForCurrentInterfaceOrientation; 52 - (AVCaptureVideoOrientation)videoOrientationForCurrentInterfaceOrientation;
49 53
50 @end 54 @end
51 55
52 @implementation CameraController { 56 @implementation CameraController {
53 qr_scanner::CameraState _cameraState; 57 qr_scanner::CameraState _cameraState;
54 BOOL _torchActive; 58 BOOL _torchActive;
55 BOOL _torchAvailable; 59 BOOL _torchAvailable;
56 CGRect _viewportRect; 60 CGRect _viewportRect;
57 } 61 }
58 62
59 #pragma mark lifecycle 63 #pragma mark lifecycle
60 64
65 + (instancetype)cameraControllerWithDelegate:
66 (id<CameraControllerDelegate>)delegate {
67 CameraController* cameraController =
68 [[CameraController alloc] initWithDelegate:delegate];
69 return cameraController;
70 }
71
61 - (instancetype)initWithDelegate:(id<CameraControllerDelegate>)delegate { 72 - (instancetype)initWithDelegate:(id<CameraControllerDelegate>)delegate {
62 self = [super init]; 73 self = [super init];
63 if (self) { 74 if (self) {
64 DCHECK(delegate); 75 DCHECK(delegate);
65 _cameraState = qr_scanner::CAMERA_NOT_LOADED; 76 _cameraState = qr_scanner::CAMERA_NOT_LOADED;
66 _delegate = delegate; 77 _delegate = delegate;
67 std::string queueName = 78 std::string queueName =
68 base::StringPrintf("%s.chrome.ios.QRScannerCaptureSessionQueue", 79 base::StringPrintf("%s.chrome.ios.QRScannerCaptureSessionQueue",
69 BUILDFLAG(IOS_APP_BUNDLE_ID_PREFIX)); 80 BUILDFLAG(IOS_APP_BUNDLE_ID_PREFIX));
70 _sessionQueue = 81 _sessionQueue =
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 [resultType isEqualToString:AVMetadataObjectTypeEAN13Code] || 463 [resultType isEqualToString:AVMetadataObjectTypeEAN13Code] ||
453 [resultType isEqualToString:AVMetadataObjectTypeInterleaved2of5Code] || 464 [resultType isEqualToString:AVMetadataObjectTypeInterleaved2of5Code] ||
454 [resultType isEqualToString:AVMetadataObjectTypeITF14Code]; 465 [resultType isEqualToString:AVMetadataObjectTypeITF14Code];
455 466
456 // Note: |captureOutput| is called on the main queue. This is specified by 467 // Note: |captureOutput| is called on the main queue. This is specified by
457 // |setMetadataObjectsDelegate:queue:|. 468 // |setMetadataObjectsDelegate:queue:|.
458 [_delegate receiveQRScannerResult:resultString loadImmediately:isAllDigits]; 469 [_delegate receiveQRScannerResult:resultString loadImmediately:isAllDigits];
459 } 470 }
460 471
461 @end 472 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/qr_scanner/camera_controller.h ('k') | ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698