Chromium Code Reviews| Index: ui/base/test/windowed_nsnotification_observer.mm |
| diff --git a/ui/base/test/windowed_nsnotification_observer.mm b/ui/base/test/windowed_nsnotification_observer.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..67818c605771e7b7cf7c2f51d2bded332993afaf |
| --- /dev/null |
| +++ b/ui/base/test/windowed_nsnotification_observer.mm |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ui/base/test/windowed_nsnotification_observer.h" |
| + |
| +#import "base/mac/sdk_forward_declarations.h" |
|
tapted
2015/06/03 07:04:49
is this needed?
jackhou1
2015/06/03 08:13:51
Done.
|
| + |
| +@interface WindowedNSNotificationObserver () |
| +- (void)observe:(NSNotification*)notification; |
|
tapted
2015/06/03 07:04:49
maybe observe -> onNotificationMessage? or onNotif
jackhou1
2015/06/03 08:13:51
Done.
|
| +@end |
| + |
| +@implementation WindowedNSNotificationObserver |
| + |
| +- (id)initForNotification:(NSString*)name { |
| + if (self = [super init]) { |
|
tapted
2015/06/03 07:04:49
double brackets around assignment in an `if` .. us
jackhou1
2015/06/03 08:13:51
Done.
|
| + [[NSNotificationCenter defaultCenter] addObserver:self |
| + selector:@selector(observe:) |
| + name:name |
| + object:nil]; |
| + } |
| + return self; |
| +} |
| + |
| +- (id)initForNotification:(NSString*)name |
| + andBundleId:(NSString*)bundleId { |
| + if (self = [super init]) { |
|
tapted
2015/06/03 07:04:49
if ((self = ..
jackhou1
2015/06/03 08:13:51
Done.
|
| + bundleId_.reset([[bundleId copy] retain]); |
|
tapted
2015/06/03 07:04:49
I don't think the retain is needed -- it's causing
jackhou1
2015/06/03 08:13:51
Done.
|
| + [[[NSWorkspace sharedWorkspace] notificationCenter] |
| + addObserver:self |
| + selector:@selector(observe:) |
| + name:name |
| + object:nil]; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)observe:(NSNotification*)notification { |
| + if (bundleId_) { |
| + NSRunningApplication* application = |
| + [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; |
| + if (![[application bundleIdentifier] isEqualToString:bundleId_]) |
| + return; |
| + |
| + [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; |
| + } else { |
| + [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| + } |
| + |
| + notificationReceived_ = YES; |
| + if (runLoop_.get()) |
| + runLoop_->Quit(); |
| +} |
| + |
| +- (void)wait { |
| + if (notificationReceived_) |
| + return; |
| + |
| + runLoop_.reset(new base::RunLoop); |
|
tapted
2015/06/03 07:04:49
The run loop can go on the stack here. i.e. these
jackhou1
2015/06/03 08:13:51
Done.
|
| + runLoop_->Run(); |
| +} |
| + |
| +@end |