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

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

Issue 1146873002: [MacViews] Enable dragging a window by its caption/draggable areas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ui/base/test/windowed_nsnotification_observer.h"
6
7 #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.
8
9 @interface WindowedNSNotificationObserver ()
10 - (void)observe:(NSNotification*)notification;
tapted 2015/06/03 07:04:49 maybe observe -> onNotificationMessage? or onNotif
jackhou1 2015/06/03 08:13:51 Done.
11 @end
12
13 @implementation WindowedNSNotificationObserver
14
15 - (id)initForNotification:(NSString*)name {
16 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.
17 [[NSNotificationCenter defaultCenter] addObserver:self
18 selector:@selector(observe:)
19 name:name
20 object:nil];
21 }
22 return self;
23 }
24
25 - (id)initForNotification:(NSString*)name
26 andBundleId:(NSString*)bundleId {
27 if (self = [super init]) {
tapted 2015/06/03 07:04:49 if ((self = ..
jackhou1 2015/06/03 08:13:51 Done.
28 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.
29 [[[NSWorkspace sharedWorkspace] notificationCenter]
30 addObserver:self
31 selector:@selector(observe:)
32 name:name
33 object:nil];
34 }
35 return self;
36 }
37
38 - (void)observe:(NSNotification*)notification {
39 if (bundleId_) {
40 NSRunningApplication* application =
41 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
42 if (![[application bundleIdentifier] isEqualToString:bundleId_])
43 return;
44
45 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
46 } else {
47 [[NSNotificationCenter defaultCenter] removeObserver:self];
48 }
49
50 notificationReceived_ = YES;
51 if (runLoop_.get())
52 runLoop_->Quit();
53 }
54
55 - (void)wait {
56 if (notificationReceived_)
57 return;
58
59 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.
60 runLoop_->Run();
61 }
62
63 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698