Use scoped_nsobject to ensure our intermediate objects get cleaned up.
This commit is contained in:
parent
7b207aa1b6
commit
b2fb95f857
4 changed files with 10 additions and 9 deletions
|
@ -91,16 +91,16 @@ void Browser::SetUserActivity(const std::string& type, const std::map<std::strin
|
||||||
NSString* type_ns = [NSString stringWithUTF8String:type.c_str()];
|
NSString* type_ns = [NSString stringWithUTF8String:type.c_str()];
|
||||||
NSUserActivity* user_activity = [[NSUserActivity alloc] initWithActivityType:type_ns];
|
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) {
|
for (auto const &pair : user_info) {
|
||||||
NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()];
|
NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()];
|
||||||
NSString* key_ns = [NSString stringWithUTF8String:pair.first.c_str()];
|
NSString* key_ns = [NSString stringWithUTF8String:pair.first.c_str()];
|
||||||
|
|
||||||
[user_info_args setObject:value_ns
|
[user_info_args.get() setObject:value_ns
|
||||||
forKey:key_ns];
|
forKey:key_ns];
|
||||||
}
|
}
|
||||||
|
|
||||||
user_activity.userInfo = user_info_args;
|
user_activity.userInfo = user_info_args.get();
|
||||||
[user_activity becomeCurrent];
|
[user_activity becomeCurrent];
|
||||||
|
|
||||||
[[AtomApplication sharedApplication] setCurrentActivity:user_activity];
|
[[AtomApplication sharedApplication] setCurrentActivity:user_activity];
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#import "base/mac/scoped_sending_event.h"
|
#import "base/mac/scoped_sending_event.h"
|
||||||
|
#import "base/mac/scoped_nsobject.h"
|
||||||
|
|
||||||
@interface AtomApplication : NSApplication<CrAppProtocol,
|
@interface AtomApplication : NSApplication<CrAppProtocol,
|
||||||
CrAppControlProtocol> {
|
CrAppControlProtocol> {
|
||||||
@private
|
@private
|
||||||
BOOL handlingSendEvent_;
|
BOOL handlingSendEvent_;
|
||||||
NSUserActivity* currentActivity_;
|
base::scoped_nsobject<NSUserActivity> currentActivity_;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (AtomApplication*)sharedApplication;
|
+ (AtomApplication*)sharedApplication;
|
||||||
|
|
|
@ -29,11 +29,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCurrentActivity:(NSUserActivity*)userActivity {
|
- (void)setCurrentActivity:(NSUserActivity*)userActivity {
|
||||||
currentActivity_ = userActivity;
|
currentActivity_ = base::scoped_nsobject<NSUserActivity>(userActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUserActivity*)getCurrentActivity {
|
- (NSUserActivity*)getCurrentActivity {
|
||||||
return currentActivity_;
|
return currentActivity_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib {
|
- (void)awakeFromNib {
|
||||||
|
|
|
@ -65,9 +65,9 @@ continueUserActivity:(NSUserActivity *)userActivity
|
||||||
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
|
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
|
||||||
|
|
||||||
std::map<std::string, std::string> user_info;
|
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.get()) {
|
||||||
for (NSString* key in keys) {
|
|
||||||
NSString* value = [userActivity.userInfo objectForKey:key];
|
NSString* value = [userActivity.userInfo objectForKey:key];
|
||||||
std::string key_str(base::SysNSStringToUTF8(key));
|
std::string key_str(base::SysNSStringToUTF8(key));
|
||||||
std::string value_str(base::SysNSStringToUTF8(value));
|
std::string value_str(base::SysNSStringToUTF8(value));
|
||||||
|
|
Loading…
Reference in a new issue