Commit 6124b1c5 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

Run "tools/mac/rewrite_modern_objc.py out/gn ../../components"

Bug: 324079
Change-Id: I6a98e713094a8a158d7ef227efd77e75a79be810
Reviewed-on: https://chromium-review.googlesource.com/c/1296681Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602284}
parent 8172a917
...@@ -66,8 +66,8 @@ NSDictionary* DictionaryFromBookmarkMetaInfo( ...@@ -66,8 +66,8 @@ NSDictionary* DictionaryFromBookmarkMetaInfo(
NSMutableDictionary* dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
for (const auto& item : meta_info_map) { for (const auto& item : meta_info_map) {
[dictionary setObject:base::SysUTF8ToNSString(item.second) dictionary[base::SysUTF8ToNSString(item.first)] =
forKey:base::SysUTF8ToNSString(item.first)]; base::SysUTF8ToNSString(item.second);
} }
return dictionary; return dictionary;
...@@ -79,22 +79,21 @@ void ConvertNSArrayToElements( ...@@ -79,22 +79,21 @@ void ConvertNSArrayToElements(
for (NSDictionary* bookmark_dict in input) { for (NSDictionary* bookmark_dict in input) {
auto new_node = std::make_unique<BookmarkNode>(GURL()); auto new_node = std::make_unique<BookmarkNode>(GURL());
NSNumber* node_id = base::mac::ObjCCast<NSNumber>( NSNumber* node_id =
[bookmark_dict objectForKey:kChromiumBookmarkIdKey]); base::mac::ObjCCast<NSNumber>(bookmark_dict[kChromiumBookmarkIdKey]);
if (node_id) if (node_id)
new_node->set_id([node_id longLongValue]); new_node->set_id([node_id longLongValue]);
NSDictionary* meta_info = base::mac::ObjCCast<NSDictionary>( NSDictionary* meta_info = base::mac::ObjCCast<NSDictionary>(
[bookmark_dict objectForKey:kChromiumBookmarkMetaInfoKey]); bookmark_dict[kChromiumBookmarkMetaInfoKey]);
if (meta_info) if (meta_info)
new_node->SetMetaInfoMap(MetaInfoMapFromDictionary(meta_info)); new_node->SetMetaInfoMap(MetaInfoMapFromDictionary(meta_info));
NSString* title = NSString* title = base::mac::ObjCCast<NSString>(bookmark_dict[kTitleKey]);
base::mac::ObjCCast<NSString>([bookmark_dict objectForKey:kTitleKey]);
new_node->SetTitle(base::SysNSStringToUTF16(title)); new_node->SetTitle(base::SysNSStringToUTF16(title));
NSString* type = base::mac::ObjCCast<NSString>( NSString* type =
[bookmark_dict objectForKey:kWebBookmarkTypeKey]); base::mac::ObjCCast<NSString>(bookmark_dict[kWebBookmarkTypeKey]);
if (!type) if (!type)
continue; continue;
...@@ -103,8 +102,8 @@ void ConvertNSArrayToElements( ...@@ -103,8 +102,8 @@ void ConvertNSArrayToElements(
new_node->set_type(BookmarkNode::FOLDER); new_node->set_type(BookmarkNode::FOLDER);
} else { } else {
new_node->set_type(BookmarkNode::URL); new_node->set_type(BookmarkNode::URL);
NSString* url_string = base::mac::ObjCCast<NSString>( NSString* url_string =
[bookmark_dict objectForKey:kURLStringKey]); base::mac::ObjCCast<NSString>(bookmark_dict[kURLStringKey]);
if (!url_string) if (!url_string)
continue; continue;
new_node->set_url(GURL(base::SysNSStringToUTF8(url_string))); new_node->set_url(GURL(base::SysNSStringToUTF8(url_string)));
...@@ -119,8 +118,7 @@ void ConvertNSArrayToElements( ...@@ -119,8 +118,7 @@ void ConvertNSArrayToElements(
e.date_folder_modified = base::Time(); e.date_folder_modified = base::Time();
if (is_folder) { if (is_folder) {
ConvertNSArrayToElements([bookmark_dict objectForKey:kChildrenKey], ConvertNSArrayToElements(bookmark_dict[kChildrenKey], &e.children);
&e.children);
} }
elements->push_back(e); elements->push_back(e);
...@@ -151,8 +149,8 @@ bool ReadWebURLsWithTitlesPboardType( ...@@ -151,8 +149,8 @@ bool ReadWebURLsWithTitlesPboardType(
NSUInteger len = [titles count]; NSUInteger len = [titles count];
for (NSUInteger i = 0; i < len; ++i) { for (NSUInteger i = 0; i < len; ++i) {
base::string16 title = base::SysNSStringToUTF16([titles objectAtIndex:i]); base::string16 title = base::SysNSStringToUTF16(titles[i]);
std::string url = base::SysNSStringToUTF8([urls objectAtIndex:i]); std::string url = base::SysNSStringToUTF8(urls[i]);
if (!url.empty()) { if (!url.empty()) {
BookmarkNodeData::Element element; BookmarkNodeData::Element element;
element.is_url = true; element.is_url = true;
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
{ {
base::scoped_nsobject<id> aRef_; base::scoped_nsobject<id> aRef_;
} }
- (id)initWith:(id)anObject; - (instancetype)initWith:(id)anObject;
@end @end
@implementation ZombieCxxDestructTest @implementation ZombieCxxDestructTest
- (id)initWith:(id)anObject { - (instancetype)initWith:(id)anObject {
self = [super init]; self = [super init];
if (self) { if (self) {
aRef_.reset([anObject retain]); aRef_.reset([anObject retain]);
...@@ -29,12 +29,12 @@ ...@@ -29,12 +29,12 @@
@end @end
@interface ZombieAssociatedObjectTest : NSObject @interface ZombieAssociatedObjectTest : NSObject
- (id)initWithAssociatedObject:(id)anObject; - (instancetype)initWithAssociatedObject:(id)anObject;
@end @end
@implementation ZombieAssociatedObjectTest @implementation ZombieAssociatedObjectTest
- (id)initWithAssociatedObject:(id)anObject { - (instancetype)initWithAssociatedObject:(id)anObject {
if ((self = [super init])) { if ((self = [super init])) {
// The address of the variable itself is the unique key, the // The address of the variable itself is the unique key, the
// contents don't matter. // contents don't matter.
......
...@@ -128,7 +128,7 @@ bool AddOriginMetadataToFile(const base::FilePath& file, ...@@ -128,7 +128,7 @@ bool AddOriginMetadataToFile(const base::FilePath& file,
if (!md_item_set_attribute_func) if (!md_item_set_attribute_func)
return false; return false;
NSString* file_path = [NSString stringWithUTF8String:file.value().c_str()]; NSString* file_path = base::mac::FilePathToNSString(file);
if (!file_path) if (!file_path)
return false; return false;
...@@ -144,11 +144,10 @@ bool AddOriginMetadataToFile(const base::FilePath& file, ...@@ -144,11 +144,10 @@ bool AddOriginMetadataToFile(const base::FilePath& file,
// Follow Safari's lead: the first item in the list is the source URL of // Follow Safari's lead: the first item in the list is the source URL of
// the downloaded file. If the referrer is known, store that, too. // the downloaded file. If the referrer is known, store that, too.
NSString* origin_url = [NSString stringWithUTF8String:source.spec().c_str()]; NSString* origin_url = base::SysUTF8ToNSString(source.spec());
if (origin_url) if (origin_url)
[list addObject:origin_url]; [list addObject:origin_url];
NSString* referrer_url = NSString* referrer_url = base::SysUTF8ToNSString(referrer.spec());
[NSString stringWithUTF8String:referrer.spec().c_str()];
if (referrer_url) if (referrer_url)
[list addObject:referrer_url]; [list addObject:referrer_url];
...@@ -203,16 +202,14 @@ bool AddQuarantineMetadataToFile(const base::FilePath& file, ...@@ -203,16 +202,14 @@ bool AddQuarantineMetadataToFile(const base::FilePath& file,
if (![properties valueForKey:(NSString*)kLSQuarantineOriginURLKey] && if (![properties valueForKey:(NSString*)kLSQuarantineOriginURLKey] &&
referrer.is_valid()) { referrer.is_valid()) {
NSString* referrer_url = NSString* referrer_url = base::SysUTF8ToNSString(referrer.spec());
[NSString stringWithUTF8String:referrer.spec().c_str()];
[properties setValue:referrer_url [properties setValue:referrer_url
forKey:(NSString*)kLSQuarantineOriginURLKey]; forKey:(NSString*)kLSQuarantineOriginURLKey];
} }
if (![properties valueForKey:(NSString*)kLSQuarantineDataURLKey] && if (![properties valueForKey:(NSString*)kLSQuarantineDataURLKey] &&
source.is_valid()) { source.is_valid()) {
NSString* origin_url = NSString* origin_url = base::SysUTF8ToNSString(source.spec());
[NSString stringWithUTF8String:source.spec().c_str()];
[properties setValue:origin_url forKey:(NSString*)kLSQuarantineDataURLKey]; [properties setValue:origin_url forKey:(NSString*)kLSQuarantineDataURLKey];
} }
......
...@@ -66,7 +66,7 @@ class ImageCaptureDeviceListener { ...@@ -66,7 +66,7 @@ class ImageCaptureDeviceListener {
bool closing_; bool closing_;
} }
- (id)initWithCameraDevice:(ICCameraDevice*)cameraDevice; - (instancetype)initWithCameraDevice:(ICCameraDevice*)cameraDevice;
- (void)setListener: - (void)setListener:
(base::WeakPtr<storage_monitor::ImageCaptureDeviceListener>)listener; (base::WeakPtr<storage_monitor::ImageCaptureDeviceListener>)listener;
- (void)open; - (void)open;
......
...@@ -57,7 +57,7 @@ base::FilePath PathForCameraItem(ICCameraItem* item) { ...@@ -57,7 +57,7 @@ base::FilePath PathForCameraItem(ICCameraItem* item) {
@implementation ImageCaptureDevice @implementation ImageCaptureDevice
- (id)initWithCameraDevice:(ICCameraDevice*)cameraDevice { - (instancetype)initWithCameraDevice:(ICCameraDevice*)cameraDevice {
if ((self = [super init])) { if ((self = [super init])) {
camera_.reset([cameraDevice retain]); camera_.reset([cameraDevice retain]);
[camera_ setDelegate:self]; [camera_ setDelegate:self];
...@@ -117,10 +117,10 @@ base::FilePath PathForCameraItem(ICCameraItem* item) { ...@@ -117,10 +117,10 @@ base::FilePath PathForCameraItem(ICCameraItem* item) {
NSMutableDictionary* options = NSMutableDictionary* options =
[NSMutableDictionary dictionaryWithCapacity:3]; [NSMutableDictionary dictionaryWithCapacity:3];
[options setObject:[NSURL fileURLWithPath:saveDirectory isDirectory:YES] options[ICDownloadsDirectoryURL] =
forKey:ICDownloadsDirectoryURL]; [NSURL fileURLWithPath:saveDirectory isDirectory:YES];
[options setObject:saveFilename forKey:ICSaveAsFilename]; options[ICSaveAsFilename] = saveFilename;
[options setObject:[NSNumber numberWithBool:YES] forKey:ICOverwrite]; options[ICOverwrite] = @YES;
[camera_ requestDownloadFile:base::mac::ObjCCastStrict<ICCameraFile>(item) [camera_ requestDownloadFile:base::mac::ObjCCastStrict<ICCameraFile>(item)
options:options options:options
...@@ -200,10 +200,9 @@ base::FilePath PathForCameraItem(ICCameraItem* item) { ...@@ -200,10 +200,9 @@ base::FilePath PathForCameraItem(ICCameraItem* item) {
return; return;
} }
std::string savedFilename = std::string savedFilename = base::SysNSStringToUTF8(options[ICSavedFilename]);
base::SysNSStringToUTF8([options objectForKey:ICSavedFilename]);
std::string saveAsFilename = std::string saveAsFilename =
base::SysNSStringToUTF8([options objectForKey:ICSaveAsFilename]); base::SysNSStringToUTF8(options[ICSaveAsFilename]);
if (savedFilename == saveAsFilename) { if (savedFilename == saveAsFilename) {
if (listener_) if (listener_)
listener_->DownloadedFile(name, base::File::FILE_OK); listener_->DownloadedFile(name, base::File::FILE_OK);
...@@ -213,8 +212,8 @@ base::FilePath PathForCameraItem(ICCameraItem* item) { ...@@ -213,8 +212,8 @@ base::FilePath PathForCameraItem(ICCameraItem* item) {
// ImageCapture did not save the file into the name we gave it in the // ImageCapture did not save the file into the name we gave it in the
// options. It picks a new name according to its best lights, so we need // options. It picks a new name according to its best lights, so we need
// to rename the file. // to rename the file.
base::FilePath saveDir(base::SysNSStringToUTF8( base::FilePath saveDir(
[[options objectForKey:ICDownloadsDirectoryURL] path])); base::SysNSStringToUTF8([options[ICDownloadsDirectoryURL] path]));
base::FilePath saveAsPath = saveDir.Append(saveAsFilename); base::FilePath saveAsPath = saveDir.Append(saveAsFilename);
base::FilePath savedPath = saveDir.Append(savedFilename); base::FilePath savedPath = saveDir.Append(savedFilename);
// Shared result value from file-copy closure to tell-listener closure. // Shared result value from file-copy closure to tell-listener closure.
......
...@@ -48,7 +48,7 @@ storage_monitor::ImageCaptureDeviceManager* g_image_capture_device_manager = ...@@ -48,7 +48,7 @@ storage_monitor::ImageCaptureDeviceManager* g_image_capture_device_manager =
@implementation ImageCaptureDeviceManagerImpl @implementation ImageCaptureDeviceManagerImpl
- (id)init { - (instancetype)init {
if ((self = [super init])) { if ((self = [super init])) {
cameras_.reset([[NSMutableArray alloc] init]); cameras_.reset([[NSMutableArray alloc] init]);
notifications_ = NULL; notifications_ = NULL;
......
...@@ -42,8 +42,8 @@ const char kTestFileContents[] = "test"; ...@@ -42,8 +42,8 @@ const char kTestFileContents[] = "test";
@implementation MockICCameraDevice @implementation MockICCameraDevice
- (id)init { - (instancetype)init {
if ((self = [super initWithDictionary:[NSDictionary dictionary]])) { if ((self = [super initWithDictionary:@{}])) {
} }
return self; return self;
} }
...@@ -89,10 +89,10 @@ const char kTestFileContents[] = "test"; ...@@ -89,10 +89,10 @@ const char kTestFileContents[] = "test";
downloadDelegate:(id<ICCameraDeviceDownloadDelegate>)downloadDelegate downloadDelegate:(id<ICCameraDeviceDownloadDelegate>)downloadDelegate
didDownloadSelector:(SEL)selector didDownloadSelector:(SEL)selector
contextInfo:(void*)contextInfo { contextInfo:(void*)contextInfo {
base::FilePath saveDir(base::SysNSStringToUTF8( base::FilePath saveDir(
[[options objectForKey:ICDownloadsDirectoryURL] path])); base::SysNSStringToUTF8([options[ICDownloadsDirectoryURL] path]));
std::string saveAsFilename = std::string saveAsFilename =
base::SysNSStringToUTF8([options objectForKey:ICSaveAsFilename]); base::SysNSStringToUTF8(options[ICSaveAsFilename]);
// It appears that the ImageCapture library adds an extension to the requested // It appears that the ImageCapture library adds an extension to the requested
// filename. Do that here to require a rename. // filename. Do that here to require a rename.
saveAsFilename += ".jpg"; saveAsFilename += ".jpg";
...@@ -103,8 +103,7 @@ const char kTestFileContents[] = "test"; ...@@ -103,8 +103,7 @@ const char kTestFileContents[] = "test";
NSMutableDictionary* returnOptions = NSMutableDictionary* returnOptions =
[NSMutableDictionary dictionaryWithDictionary:options]; [NSMutableDictionary dictionaryWithDictionary:options];
[returnOptions setObject:base::SysUTF8ToNSString(saveAsFilename) returnOptions[ICSavedFilename] = base::SysUTF8ToNSString(saveAsFilename);
forKey:ICSavedFilename];
[static_cast<NSObject<ICCameraDeviceDownloadDelegate>*>(downloadDelegate) [static_cast<NSObject<ICCameraDeviceDownloadDelegate>*>(downloadDelegate)
didDownloadFile:file didDownloadFile:file
...@@ -120,13 +119,13 @@ const char kTestFileContents[] = "test"; ...@@ -120,13 +119,13 @@ const char kTestFileContents[] = "test";
base::scoped_nsobject<NSString> name_; base::scoped_nsobject<NSString> name_;
} }
- (id)initWithName:(NSString*)name; - (instancetype)initWithName:(NSString*)name;
@end @end
@implementation MockICCameraFolder @implementation MockICCameraFolder
- (id)initWithName:(NSString*)name { - (instancetype)initWithName:(NSString*)name {
if ((self = [super init])) { if ((self = [super init])) {
name_.reset([name retain]); name_.reset([name retain]);
} }
...@@ -150,14 +149,14 @@ const char kTestFileContents[] = "test"; ...@@ -150,14 +149,14 @@ const char kTestFileContents[] = "test";
base::scoped_nsobject<MockICCameraFolder> parent_; base::scoped_nsobject<MockICCameraFolder> parent_;
} }
- (id)init:(NSString*)name; - (instancetype)init:(NSString*)name;
- (void)setParent:(NSString*)parent; - (void)setParent:(NSString*)parent;
@end @end
@implementation MockICCameraFile @implementation MockICCameraFile
- (id)init:(NSString*)name { - (instancetype)init:(NSString*)name {
if ((self = [super init])) { if ((self = [super init])) {
name_.reset([name retain]); name_.reset([name retain]);
date_.reset([[NSDate dateWithNaturalLanguageString:@"12/12/12"] retain]); date_.reset([[NSDate dateWithNaturalLanguageString:@"12/12/12"] retain]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment