| 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"
|
| +
|
| +@interface WindowedNSNotificationObserver ()
|
| +- (void)observe:(NSNotification*)notification;
|
| +@end
|
| +
|
| +@implementation WindowedNSNotificationObserver
|
| +
|
| +- (id)initForNotification:(NSString*)name {
|
| + if (self = [super init]) {
|
| + [[NSNotificationCenter defaultCenter] addObserver:self
|
| + selector:@selector(observe:)
|
| + name:name
|
| + object:nil];
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +- (id)initForNotification:(NSString*)name
|
| + andBundleId:(NSString*)bundleId {
|
| + if (self = [super init]) {
|
| + bundleId_.reset([[bundleId copy] retain]);
|
| + [[[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);
|
| + runLoop_->Run();
|
| +}
|
| +
|
| +@end
|
|
|