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

Side by Side Diff: chrome/browser/storage_monitor/image_capture_device.mm

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/storage_monitor/image_capture_device.h" 5 #import "chrome/browser/storage_monitor/image_capture_device.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 9
10 namespace { 10 namespace {
11 11
12 base::PlatformFileError RenameFile(const base::FilePath& downloaded_filename, 12 base::File::Error RenameFile(const base::FilePath& downloaded_filename,
13 const base::FilePath& desired_filename) { 13 const base::FilePath& desired_filename) {
14 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 14 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
15 bool success = base::ReplaceFile(downloaded_filename, desired_filename, NULL); 15 bool success = base::ReplaceFile(downloaded_filename, desired_filename, NULL);
16 return success ? base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_NOT_FOUND; 16 return success ? base::File::FILE_OK : base::File::FILE_ERROR_NOT_FOUND;
17 } 17 }
18 18
19 void ReturnRenameResultToListener( 19 void ReturnRenameResultToListener(
20 base::WeakPtr<ImageCaptureDeviceListener> listener, 20 base::WeakPtr<ImageCaptureDeviceListener> listener,
21 const std::string& name, 21 const std::string& name,
22 const base::PlatformFileError& result) { 22 const base::File::Error& result) {
23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
24 if (listener) 24 if (listener)
25 listener->DownloadedFile(name, result); 25 listener->DownloadedFile(name, result);
26 } 26 }
27 27
28 base::Time NSDateToBaseTime(NSDate* date) { 28 base::Time NSDateToBaseTime(NSDate* date) {
29 return base::Time::FromDoubleT([date timeIntervalSince1970]); 29 return base::Time::FromDoubleT([date timeIntervalSince1970]);
30 } 30 }
31 31
32 base::FilePath PathForCameraItem(ICCameraItem* item) { 32 base::FilePath PathForCameraItem(ICCameraItem* item) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 options:options 120 options:options
121 downloadDelegate:self 121 downloadDelegate:self
122 didDownloadSelector: 122 didDownloadSelector:
123 @selector(didDownloadFile:error:options:contextInfo:) 123 @selector(didDownloadFile:error:options:contextInfo:)
124 contextInfo:NULL]; 124 contextInfo:NULL];
125 return; 125 return;
126 } 126 }
127 } 127 }
128 128
129 if (listener_) 129 if (listener_)
130 listener_->DownloadedFile(name, base::PLATFORM_FILE_ERROR_NOT_FOUND); 130 listener_->DownloadedFile(name, base::File::FILE_ERROR_NOT_FOUND);
131 } 131 }
132 132
133 - (void)cameraDevice:(ICCameraDevice*)camera didAddItem:(ICCameraItem*)item { 133 - (void)cameraDevice:(ICCameraDevice*)camera didAddItem:(ICCameraItem*)item {
134 base::PlatformFileInfo info; 134 base::File::Info info;
135 if ([[item UTI] isEqualToString:base::mac::CFToNSCast(kUTTypeFolder)]) 135 if ([[item UTI] isEqualToString:base::mac::CFToNSCast(kUTTypeFolder)])
136 info.is_directory = true; 136 info.is_directory = true;
137 else 137 else
138 info.size = [base::mac::ObjCCastStrict<ICCameraFile>(item) fileSize]; 138 info.size = [base::mac::ObjCCastStrict<ICCameraFile>(item) fileSize];
139 139
140 base::FilePath path = PathForCameraItem(item); 140 base::FilePath path = PathForCameraItem(item);
141 141
142 info.last_modified = NSDateToBaseTime([item modificationDate]); 142 info.last_modified = NSDateToBaseTime([item modificationDate]);
143 info.creation_time = NSDateToBaseTime([item creationDate]); 143 info.creation_time = NSDateToBaseTime([item creationDate]);
144 info.last_accessed = info.last_modified; 144 info.last_accessed = info.last_modified;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 - (void)didDownloadFile:(ICCameraFile*)file 179 - (void)didDownloadFile:(ICCameraFile*)file
180 error:(NSError*)error 180 error:(NSError*)error
181 options:(NSDictionary*)options 181 options:(NSDictionary*)options
182 contextInfo:(void*)contextInfo { 182 contextInfo:(void*)contextInfo {
183 if (closing_) 183 if (closing_)
184 return; 184 return;
185 185
186 std::string name = PathForCameraItem(file).value(); 186 std::string name = PathForCameraItem(file).value();
187 187
188 if (error) { 188 if (error) {
189 DLOG(INFO) << "error..." 189 DVLOG(1) << "error..."
190 << base::SysNSStringToUTF8([error localizedDescription]); 190 << base::SysNSStringToUTF8([error localizedDescription]);
191 if (listener_) 191 if (listener_)
192 listener_->DownloadedFile(name, base::PLATFORM_FILE_ERROR_FAILED); 192 listener_->DownloadedFile(name, base::File::FILE_ERROR_FAILED);
193 return; 193 return;
194 } 194 }
195 195
196 std::string savedFilename = 196 std::string savedFilename =
197 base::SysNSStringToUTF8([options objectForKey:ICSavedFilename]); 197 base::SysNSStringToUTF8([options objectForKey:ICSavedFilename]);
198 std::string saveAsFilename = 198 std::string saveAsFilename =
199 base::SysNSStringToUTF8([options objectForKey:ICSaveAsFilename]); 199 base::SysNSStringToUTF8([options objectForKey:ICSaveAsFilename]);
200 if (savedFilename == saveAsFilename) { 200 if (savedFilename == saveAsFilename) {
201 if (listener_) 201 if (listener_)
202 listener_->DownloadedFile(name, base::PLATFORM_FILE_OK); 202 listener_->DownloadedFile(name, base::File::FILE_OK);
203 return; 203 return;
204 } 204 }
205 205
206 // ImageCapture did not save the file into the name we gave it in the 206 // ImageCapture did not save the file into the name we gave it in the
207 // options. It picks a new name according to its best lights, so we need 207 // options. It picks a new name according to its best lights, so we need
208 // to rename the file. 208 // to rename the file.
209 base::FilePath saveDir(base::SysNSStringToUTF8( 209 base::FilePath saveDir(base::SysNSStringToUTF8(
210 [[options objectForKey:ICDownloadsDirectoryURL] path])); 210 [[options objectForKey:ICDownloadsDirectoryURL] path]));
211 base::FilePath saveAsPath = saveDir.Append(saveAsFilename); 211 base::FilePath saveAsPath = saveDir.Append(saveAsFilename);
212 base::FilePath savedPath = saveDir.Append(savedFilename); 212 base::FilePath savedPath = saveDir.Append(savedFilename);
213 // Shared result value from file-copy closure to tell-listener closure. 213 // Shared result value from file-copy closure to tell-listener closure.
214 content::BrowserThread::PostTaskAndReplyWithResult( 214 content::BrowserThread::PostTaskAndReplyWithResult(
215 content::BrowserThread::FILE, 215 content::BrowserThread::FILE,
216 FROM_HERE, 216 FROM_HERE,
217 base::Bind(&RenameFile, savedPath, saveAsPath), 217 base::Bind(&RenameFile, savedPath, saveAsPath),
218 base::Bind(&ReturnRenameResultToListener, listener_, name)); 218 base::Bind(&ReturnRenameResultToListener, listener_, name));
219 } 219 }
220 220
221 @end // ImageCaptureDevice 221 @end // ImageCaptureDevice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698