OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/storage_monitor/image_capture_device.h" | 5 #import "components/storage_monitor/image_capture_device.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 namespace storage_monitor { | 10 namespace storage_monitor { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 base::File::Error RenameFile(const base::FilePath& downloaded_filename, | 14 base::File::Error RenameFile(const base::FilePath& downloaded_filename, |
15 const base::FilePath& desired_filename) { | 15 const base::FilePath& desired_filename) { |
16 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 16 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
Cait (Slow)
2015/04/23 00:02:37
content::BrowserThread::FILE?
Mostyn Bramley-Moore
2015/04/23 07:43:16
Done.
| |
17 bool success = base::ReplaceFile(downloaded_filename, desired_filename, NULL); | 17 bool success = base::ReplaceFile(downloaded_filename, desired_filename, NULL); |
18 return success ? base::File::FILE_OK : base::File::FILE_ERROR_NOT_FOUND; | 18 return success ? base::File::FILE_OK : base::File::FILE_ERROR_NOT_FOUND; |
19 } | 19 } |
20 | 20 |
21 void ReturnRenameResultToListener( | 21 void ReturnRenameResultToListener( |
22 base::WeakPtr<ImageCaptureDeviceListener> listener, | 22 base::WeakPtr<ImageCaptureDeviceListener> listener, |
23 const std::string& name, | 23 const std::string& name, |
24 const base::File::Error& result) { | 24 const base::File::Error& result) { |
25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
26 if (listener) | 26 if (listener) |
27 listener->DownloadedFile(name, result); | 27 listener->DownloadedFile(name, result); |
28 } | 28 } |
29 | 29 |
30 base::Time NSDateToBaseTime(NSDate* date) { | 30 base::Time NSDateToBaseTime(NSDate* date) { |
31 return base::Time::FromDoubleT([date timeIntervalSince1970]); | 31 return base::Time::FromDoubleT([date timeIntervalSince1970]); |
32 } | 32 } |
33 | 33 |
34 base::FilePath PathForCameraItem(ICCameraItem* item) { | 34 base::FilePath PathForCameraItem(ICCameraItem* item) { |
35 std::string name = base::SysNSStringToUTF8([item name]); | 35 std::string name = base::SysNSStringToUTF8([item name]); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 - (void)dealloc { | 68 - (void)dealloc { |
69 // Make sure the session was closed and listener set to null | 69 // Make sure the session was closed and listener set to null |
70 // before destruction. | 70 // before destruction. |
71 DCHECK(![camera_ delegate]); | 71 DCHECK(![camera_ delegate]); |
72 DCHECK(!listener_); | 72 DCHECK(!listener_); |
73 [super dealloc]; | 73 [super dealloc]; |
74 } | 74 } |
75 | 75 |
76 - (void)setListener:(base::WeakPtr<storage_monitor::ImageCaptureDeviceListener>) | 76 - (void)setListener:(base::WeakPtr<storage_monitor::ImageCaptureDeviceListener>) |
77 listener { | 77 listener { |
78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
79 listener_ = listener; | 79 listener_ = listener; |
80 } | 80 } |
81 | 81 |
82 - (void)open { | 82 - (void)open { |
83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
84 DCHECK(listener_); | 84 DCHECK(listener_); |
85 [camera_ requestOpenSession]; | 85 [camera_ requestOpenSession]; |
86 } | 86 } |
87 | 87 |
88 - (void)close { | 88 - (void)close { |
89 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
90 closing_ = true; | 90 closing_ = true; |
91 [camera_ cancelDownload]; | 91 [camera_ cancelDownload]; |
92 [camera_ requestCloseSession]; | 92 [camera_ requestCloseSession]; |
93 [camera_ setDelegate:nil]; | 93 [camera_ setDelegate:nil]; |
94 listener_.reset(); | 94 listener_.reset(); |
95 } | 95 } |
96 | 96 |
97 - (void)eject { | 97 - (void)eject { |
98 [camera_ requestEjectOrDisconnect]; | 98 [camera_ requestEjectOrDisconnect]; |
99 } | 99 } |
100 | 100 |
101 - (void)downloadFile:(const std::string&)name | 101 - (void)downloadFile:(const std::string&)name |
102 localPath:(const base::FilePath&)localPath { | 102 localPath:(const base::FilePath&)localPath { |
103 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
104 | 104 |
105 // Find the file with that name and start download. | 105 // Find the file with that name and start download. |
106 for (ICCameraItem* item in [camera_ mediaFiles]) { | 106 for (ICCameraItem* item in [camera_ mediaFiles]) { |
107 std::string itemName = storage_monitor::PathForCameraItem(item).value(); | 107 std::string itemName = storage_monitor::PathForCameraItem(item).value(); |
108 if (itemName == name) { | 108 if (itemName == name) { |
109 // To create save options for ImageCapture, we need to | 109 // To create save options for ImageCapture, we need to |
110 // split the target filename into directory/name | 110 // split the target filename into directory/name |
111 // and encode the directory as a URL. | 111 // and encode the directory as a URL. |
112 NSString* saveDirectory = | 112 NSString* saveDirectory = |
113 base::mac::FilePathToNSString(localPath.DirName()); | 113 base::mac::FilePathToNSString(localPath.DirName()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 // Shared result value from file-copy closure to tell-listener closure. | 219 // Shared result value from file-copy closure to tell-listener closure. |
220 content::BrowserThread::PostTaskAndReplyWithResult( | 220 content::BrowserThread::PostTaskAndReplyWithResult( |
221 content::BrowserThread::FILE, | 221 content::BrowserThread::FILE, |
222 FROM_HERE, | 222 FROM_HERE, |
223 base::Bind(&storage_monitor::RenameFile, savedPath, saveAsPath), | 223 base::Bind(&storage_monitor::RenameFile, savedPath, saveAsPath), |
224 base::Bind( | 224 base::Bind( |
225 &storage_monitor::ReturnRenameResultToListener, listener_, name)); | 225 &storage_monitor::ReturnRenameResultToListener, listener_, name)); |
226 } | 226 } |
227 | 227 |
228 @end // ImageCaptureDevice | 228 @end // ImageCaptureDevice |
OLD | NEW |