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