Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: ui/base/test/windowed_nsnotification_observer.mm

Issue 1186803003: Mac: Give packaged app windows their own window cycle list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase (overlap with r335812 and I want a fresh CQ run) Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/test/windowed_nsnotification_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/base/test/windowed_nsnotification_observer.h" 5 #import "ui/base/test/windowed_nsnotification_observer.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h"
10 11
11 @interface WindowedNSNotificationObserver () 12 @interface WindowedNSNotificationObserver ()
12 - (void)onNotification:(NSNotification*)notification; 13 - (void)onNotification:(NSNotification*)notification;
13 @end 14 @end
14 15
15 @implementation WindowedNSNotificationObserver 16 @implementation WindowedNSNotificationObserver
16 17
17 - (id)initForNotification:(NSString*)name { 18 - (id)initForNotification:(NSString*)name {
18 return [self initForNotification:name object:nil]; 19 return [self initForNotification:name object:nil];
19 } 20 }
(...skipping 14 matching lines...) Expand all
34 bundleId_.reset([bundleId copy]); 35 bundleId_.reset([bundleId copy]);
35 [[[NSWorkspace sharedWorkspace] notificationCenter] 36 [[[NSWorkspace sharedWorkspace] notificationCenter]
36 addObserver:self 37 addObserver:self
37 selector:@selector(onNotification:) 38 selector:@selector(onNotification:)
38 name:name 39 name:name
39 object:nil]; 40 object:nil];
40 } 41 }
41 return self; 42 return self;
42 } 43 }
43 44
45 - (void)dealloc {
46 if (bundleId_)
47 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
48 else
49 [[NSNotificationCenter defaultCenter] removeObserver:self];
50 [super dealloc];
51 }
52
44 - (void)onNotification:(NSNotification*)notification { 53 - (void)onNotification:(NSNotification*)notification {
45 if (bundleId_) { 54 if (bundleId_) {
46 NSRunningApplication* application = 55 NSRunningApplication* application =
47 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; 56 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
48 if (![[application bundleIdentifier] isEqualToString:bundleId_]) 57 if (![[application bundleIdentifier] isEqualToString:bundleId_])
49 return; 58 return;
50
51 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
52 } else {
53 [[NSNotificationCenter defaultCenter] removeObserver:self];
54 } 59 }
55 60
56 notificationReceived_ = YES; 61 ++notificationCount_;
57 if (runLoop_) 62 if (runLoop_)
58 runLoop_->Quit(); 63 runLoop_->Quit();
59 } 64 }
60 65
61 - (void)wait { 66 - (BOOL)waitForCount:(int)minimumCount {
62 if (notificationReceived_) 67 while (notificationCount_ < minimumCount) {
63 return; 68 const int oldCount = notificationCount_;
69 base::RunLoop runLoop;
70 base::MessageLoop::current()->task_runner()->PostDelayedTask(
71 FROM_HERE, runLoop.QuitClosure(), TestTimeouts::action_timeout());
72 runLoop_ = &runLoop;
73 runLoop.Run();
74 runLoop_ = nullptr;
64 75
65 base::RunLoop runLoop; 76 // If there was no new notification, it must have been a timeout.
66 runLoop_ = &runLoop; 77 if (notificationCount_ == oldCount)
67 runLoop.Run(); 78 break;
68 runLoop_ = nullptr; 79 }
80 return notificationCount_ >= minimumCount;
81 }
82
83 - (BOOL)wait {
84 return [self waitForCount:1];
69 } 85 }
70 86
71 @end 87 @end
OLDNEW
« no previous file with comments | « ui/base/test/windowed_nsnotification_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698