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

Unified Diff: chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.mm

Issue 2419213003: Ensure the xpc transaction is ended (Closed)
Patch Set: review Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b1f6b1e73a27583903f8c84e27fac092870240f7
--- /dev/null
+++ b/chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.mm
@@ -0,0 +1,44 @@
+// 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 {
+ bool transactionOpen_;
+}
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ transactionOpen_ = false;
+ }
+ return self;
+}
+
+- (void)openTransactionIfNeeded {
+ @synchronized(self) {
+ if (transactionOpen_) {
+ return;
+ }
+ xpc_transaction_begin();
+ transactionOpen_ = true;
+ }
+}
+
+- (void)closeTransactionIfNeeded {
+ @synchronized(self) {
+ NSUserNotificationCenter* notificationCenter =
+ [NSUserNotificationCenter defaultUserNotificationCenter];
+ NSUInteger showing = [[notificationCenter deliveredNotifications] count];
+ if (showing == 0) {
+ xpc_transaction_end();
+ transactionOpen_ = false;
+ }
+ }
+}
+@end
« no previous file with comments | « chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698