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..903f6ea2038e13620cdbe26d413dbed70e652f92 |
| --- /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. |
| +#import <AppKit/AppKit.h> |
| +#import <Foundation/Foundation.h> |
| + |
| +#import "chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h" |
| + |
| +@class NSUserNotificationCenter; |
| + |
| +@implementation XPCTransactionHandler { |
| + Boolean transactionOpen; |
|
Robert Sesek
2016/10/24 23:11:05
Use BOOL or bool.
Robert Sesek
2016/10/24 23:11:05
naming: needs trailing underscore
Miguel Garcia
2016/10/26 15:56:38
Done.
Miguel Garcia
2016/10/26 15:56:38
Done.
|
| +} |
| +- (instancetype)init { |
| + if ((self = [super init])) { |
| + transactionOpen = NO; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)openTransactionIfNeeded { |
| + @synchronized(self) { |
|
Robert Sesek
2016/10/24 23:11:05
Why @synchronized here? I assume we're avoiding ba
Miguel Garcia
2016/10/26 15:56:38
We need a synchronized block because alerts are ad
|
| + if (transactionOpen) { |
| + return; |
| + } |
| + xpc_transaction_begin(); |
| + transactionOpen = YES; |
| + } |
| +} |
| + |
| +- (void)closeTransactionIfNeeded { |
| + @synchronized(self) { |
| + NSUserNotificationCenter* notificationCenter = |
| + [NSUserNotificationCenter defaultUserNotificationCenter]; |
| + NSInteger showing = [[notificationCenter deliveredNotifications] count]; |
| + if (showing == 0) { |
| + xpc_transaction_end(); |
| + transactionOpen = NO; |
| + } |
| + } |
| +} |
| +@end |