Use scoped_nsobject to ensure our intermediate objects get cleaned up.

This commit is contained in:
Charlie Hess 2016-05-04 11:28:49 -07:00
parent 7b207aa1b6
commit b2fb95f857
4 changed files with 10 additions and 9 deletions

View file

@ -91,16 +91,16 @@ void Browser::SetUserActivity(const std::string& type, const std::map<std::strin
NSString* type_ns = [NSString stringWithUTF8String:type.c_str()];
NSUserActivity* user_activity = [[NSUserActivity alloc] initWithActivityType:type_ns];
NSMutableDictionary* user_info_args = [[NSMutableDictionary alloc] init];
base::scoped_nsobject<NSMutableDictionary> user_info_args([[NSMutableDictionary alloc] init]);
for (auto const &pair : user_info) {
NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()];
NSString* key_ns = [NSString stringWithUTF8String:pair.first.c_str()];
[user_info_args setObject:value_ns
forKey:key_ns];
[user_info_args.get() setObject:value_ns
forKey:key_ns];
}
user_activity.userInfo = user_info_args;
user_activity.userInfo = user_info_args.get();
[user_activity becomeCurrent];
[[AtomApplication sharedApplication] setCurrentActivity:user_activity];

View file

@ -3,12 +3,13 @@
// found in the LICENSE file.
#import "base/mac/scoped_sending_event.h"
#import "base/mac/scoped_nsobject.h"
@interface AtomApplication : NSApplication<CrAppProtocol,
CrAppControlProtocol> {
@private
BOOL handlingSendEvent_;
NSUserActivity* currentActivity_;
base::scoped_nsobject<NSUserActivity> currentActivity_;
}
+ (AtomApplication*)sharedApplication;

View file

@ -29,11 +29,11 @@
}
- (void)setCurrentActivity:(NSUserActivity*)userActivity {
currentActivity_ = userActivity;
currentActivity_ = base::scoped_nsobject<NSUserActivity>(userActivity);
}
- (NSUserActivity*)getCurrentActivity {
return currentActivity_;
return currentActivity_.get();
}
- (void)awakeFromNib {

View file

@ -65,9 +65,9 @@ continueUserActivity:(NSUserActivity *)userActivity
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
std::map<std::string, std::string> user_info;
base::scoped_nsobject<NSArray> keys([userActivity.userInfo allKeys]);
NSArray* keys = [userActivity.userInfo allKeys];
for (NSString* key in keys) {
for (NSString* key in keys.get()) {
NSString* value = [userActivity.userInfo objectForKey:key];
std::string key_str(base::SysNSStringToUTF8(key));
std::string value_str(base::SysNSStringToUTF8(value));