Mac: modernize objc in rlz/
Via tools/mac/rewrite_modern_objc.py Bug: 324079 Change-Id: I36ca3b1597ac9a3eecb8f6fc1b2f6e3f1056e01d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2893024 Auto-Submit: Leonard Grey <lgrey@chromium.org> Commit-Queue: Leonard Grey <lgrey@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Cr-Commit-Position: refs/heads/master@{#883594}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
252ea10dbd
commit
487d565bfe
@ -42,10 +42,10 @@ NSString* GetNSAccessPointName(AccessPoint p) {
|
||||
// dictionary, that object is replaced with an empty mutable dictinary.
|
||||
NSMutableDictionary* GetOrCreateDict(
|
||||
NSMutableDictionary* p, NSString* k) {
|
||||
NSMutableDictionary* d = ObjCCast<NSMutableDictionary>([p objectForKey:k]);
|
||||
NSMutableDictionary* d = ObjCCast<NSMutableDictionary>(p[k]);
|
||||
if (!d) {
|
||||
d = [NSMutableDictionary dictionaryWithCapacity:0];
|
||||
[p setObject:d forKey:k];
|
||||
d = [NSMutableDictionary dictionary];
|
||||
p[k] = d;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@ -69,14 +69,12 @@ bool RlzValueStoreMac::HasAccess(AccessType type) {
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::WritePingTime(Product product, int64_t time) {
|
||||
NSNumber* n = [NSNumber numberWithLongLong:time];
|
||||
[ProductDict(product) setObject:n forKey:kPingTimeKey];
|
||||
ProductDict(product)[kPingTimeKey] = @(time);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::ReadPingTime(Product product, int64_t* time) {
|
||||
if (NSNumber* n =
|
||||
ObjCCast<NSNumber>([ProductDict(product) objectForKey:kPingTimeKey])) {
|
||||
if (NSNumber* n = ObjCCast<NSNumber>(ProductDict(product)[kPingTimeKey])) {
|
||||
*time = [n longLongValue];
|
||||
return true;
|
||||
}
|
||||
@ -92,8 +90,7 @@ bool RlzValueStoreMac::ClearPingTime(Product product) {
|
||||
bool RlzValueStoreMac::WriteAccessPointRlz(AccessPoint access_point,
|
||||
const char* new_rlz) {
|
||||
NSMutableDictionary* d = GetOrCreateDict(WorkingDict(), kAccessPointKey);
|
||||
[d setObject:base::SysUTF8ToNSString(new_rlz)
|
||||
forKey:GetNSAccessPointName(access_point)];
|
||||
d[GetNSAccessPointName(access_point)] = base::SysUTF8ToNSString(new_rlz);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -101,10 +98,9 @@ bool RlzValueStoreMac::ReadAccessPointRlz(AccessPoint access_point,
|
||||
char* rlz,
|
||||
size_t rlz_size) {
|
||||
// Reading a non-existent access point counts as success.
|
||||
if (NSDictionary* d = ObjCCast<NSDictionary>(
|
||||
[WorkingDict() objectForKey:kAccessPointKey])) {
|
||||
NSString* val = ObjCCast<NSString>(
|
||||
[d objectForKey:GetNSAccessPointName(access_point)]);
|
||||
if (NSDictionary* d =
|
||||
ObjCCast<NSDictionary>(WorkingDict()[kAccessPointKey])) {
|
||||
NSString* val = ObjCCast<NSString>(d[GetNSAccessPointName(access_point)]);
|
||||
if (!val) {
|
||||
if (rlz_size > 0)
|
||||
rlz[0] = '\0';
|
||||
@ -126,8 +122,8 @@ bool RlzValueStoreMac::ReadAccessPointRlz(AccessPoint access_point,
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::ClearAccessPointRlz(AccessPoint access_point) {
|
||||
if (NSMutableDictionary* d = ObjCCast<NSMutableDictionary>(
|
||||
[WorkingDict() objectForKey:kAccessPointKey])) {
|
||||
if (NSMutableDictionary* d =
|
||||
ObjCCast<NSMutableDictionary>(WorkingDict()[kAccessPointKey])) {
|
||||
[d removeObjectForKey:GetNSAccessPointName(access_point)];
|
||||
}
|
||||
return true;
|
||||
@ -139,16 +135,15 @@ bool RlzValueStoreMac::UpdateExistingAccessPointRlz(const std::string& brand) {
|
||||
|
||||
bool RlzValueStoreMac::AddProductEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
[GetOrCreateDict(ProductDict(product), kProductEventKey)
|
||||
setObject:[NSNumber numberWithBool:YES]
|
||||
forKey:base::SysUTF8ToNSString(event_rlz)];
|
||||
GetOrCreateDict(ProductDict(product),
|
||||
kProductEventKey)[base::SysUTF8ToNSString(event_rlz)] = @YES;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::ReadProductEvents(Product product,
|
||||
std::vector<std::string>* events) {
|
||||
if (NSDictionary* d = ObjCCast<NSDictionary>(
|
||||
[ProductDict(product) objectForKey:kProductEventKey])) {
|
||||
if (NSDictionary* d =
|
||||
ObjCCast<NSDictionary>(ProductDict(product)[kProductEventKey])) {
|
||||
for (NSString* s in d)
|
||||
events->push_back(base::SysNSStringToUTF8(s));
|
||||
return true;
|
||||
@ -159,7 +154,7 @@ bool RlzValueStoreMac::ReadProductEvents(Product product,
|
||||
bool RlzValueStoreMac::ClearProductEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
if (NSMutableDictionary* d = ObjCCast<NSMutableDictionary>(
|
||||
[ProductDict(product) objectForKey:kProductEventKey])) {
|
||||
ProductDict(product)[kProductEventKey])) {
|
||||
[d removeObjectForKey:base::SysUTF8ToNSString(event_rlz)];
|
||||
return true;
|
||||
}
|
||||
@ -174,17 +169,16 @@ bool RlzValueStoreMac::ClearAllProductEvents(Product product) {
|
||||
|
||||
bool RlzValueStoreMac::AddStatefulEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
[GetOrCreateDict(ProductDict(product), kStatefulEventKey)
|
||||
setObject:[NSNumber numberWithBool:YES]
|
||||
forKey:base::SysUTF8ToNSString(event_rlz)];
|
||||
GetOrCreateDict(ProductDict(product),
|
||||
kStatefulEventKey)[base::SysUTF8ToNSString(event_rlz)] = @YES;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::IsStatefulEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
if (NSDictionary* d = ObjCCast<NSDictionary>(
|
||||
[ProductDict(product) objectForKey:kStatefulEventKey])) {
|
||||
return [d objectForKey:base::SysUTF8ToNSString(event_rlz)] != nil;
|
||||
if (NSDictionary* d =
|
||||
ObjCCast<NSDictionary>(ProductDict(product)[kStatefulEventKey])) {
|
||||
return d[base::SysUTF8ToNSString(event_rlz)] != nil;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -246,7 +240,7 @@ NSString* CreateRlzDirectory() {
|
||||
NSApplicationSupportDirectory, NSUserDomainMask, /*expandTilde=*/YES);
|
||||
NSString* folder = nil;
|
||||
if ([paths count] > 0)
|
||||
folder = ObjCCast<NSString>([paths objectAtIndex:0]);
|
||||
folder = ObjCCast<NSString>(paths[0]);
|
||||
if (!folder)
|
||||
folder = [@"~/Library/Application Support" stringByStandardizingPath];
|
||||
folder = [folder stringByAppendingPathComponent:@"Google/RLZ"];
|
||||
|
Reference in New Issue
Block a user