Chromium Code Reviews| Index: chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.mm |
| diff --git a/chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.mm b/chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e6fcd7c19518e696362bdb250f295e209e104a59 |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.mm |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2016 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. |
|
Robert Sesek
2016/10/26 18:49:41
nit: blank line after
Miguel Garcia
2016/10/28 14:53:57
Done.
|
| +#import <AppKit/AppKit.h> |
| +#import <Foundation/Foundation.h> |
| + |
| +#import "chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h" |
| + |
| +@class NSUserNotificationCenter; |
| + |
| +@implementation XPCTransactionHandler { |
| + bool transactionOpen_; |
| +} |
|
Robert Sesek
2016/10/26 18:49:41
nit: blank line after
Miguel Garcia
2016/10/28 14:53:56
Done.
|
| +- (instancetype)init { |
| + if ((self = [super init])) { |
| + transactionOpen_ = NO; |
|
Robert Sesek
2016/10/26 18:49:41
NO -> false
Miguel Garcia
2016/10/28 14:53:57
Done.
|
| + } |
| + return self; |
| +} |
| + |
| +- (void)openTransactionIfNeeded { |
| + @synchronized(self) { |
| + if (transactionOpen_) { |
| + return; |
| + } |
| + xpc_transaction_begin(); |
| + transactionOpen_ = YES; |
|
Robert Sesek
2016/10/26 18:49:41
YES -> true
Miguel Garcia
2016/10/28 14:53:57
Done.
|
| + } |
| +} |
| + |
| +- (void)closeTransactionIfNeeded { |
| + @synchronized(self) { |
| + NSUserNotificationCenter* notificationCenter = |
| + [NSUserNotificationCenter defaultUserNotificationCenter]; |
| + NSInteger showing = [[notificationCenter deliveredNotifications] count]; |
|
Robert Sesek
2016/10/26 18:49:41
-[NSArray count] returns NSUInteger
Miguel Garcia
2016/10/28 14:53:57
Done.
|
| + if (showing == 0) { |
| + xpc_transaction_end(); |
| + transactionOpen_ = NO; |
|
Robert Sesek
2016/10/26 18:49:41
NO -> false
Miguel Garcia
2016/10/28 14:53:56
Done.
|
| + } |
| + } |
| +} |
| +@end |