OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "chrome/browser/notifications/notification_platform_bridge_linux.h" | 5 #include "chrome/browser/notifications/notification_platform_bridge_linux.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 231 } |
232 | 232 |
233 class NotificationPlatformBridgeLinuxImpl | 233 class NotificationPlatformBridgeLinuxImpl |
234 : public NotificationPlatformBridge, | 234 : public NotificationPlatformBridge, |
235 public content::NotificationObserver, | 235 public content::NotificationObserver, |
236 public base::RefCountedThreadSafe<NotificationPlatformBridgeLinuxImpl> { | 236 public base::RefCountedThreadSafe<NotificationPlatformBridgeLinuxImpl> { |
237 public: | 237 public: |
238 explicit NotificationPlatformBridgeLinuxImpl(scoped_refptr<dbus::Bus> bus) | 238 explicit NotificationPlatformBridgeLinuxImpl(scoped_refptr<dbus::Bus> bus) |
239 : bus_(bus) { | 239 : bus_(bus) { |
240 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 240 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 241 // While the tasks in NotificationPlatformBridgeLinux merely need |
| 242 // to run in sequence, many APIs in ::dbus are required to be |
| 243 // called from the same thread (https://crbug.com/130984), so |
| 244 // |task_runner_| is created as the single-threaded flavor. |
241 task_runner_ = base::CreateSingleThreadTaskRunnerWithTraits( | 245 task_runner_ = base::CreateSingleThreadTaskRunnerWithTraits( |
242 {base::MayBlock(), base::TaskPriority::USER_BLOCKING}); | 246 {base::MayBlock(), base::TaskPriority::USER_BLOCKING}); |
243 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 247 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
244 content::NotificationService::AllSources()); | 248 content::NotificationService::AllSources()); |
245 } | 249 } |
246 | 250 |
247 // InitOnTaskRunner() cannot be posted from within the constructor | 251 // InitOnTaskRunner() cannot be posted from within the constructor |
248 // because of a race condition. The reference count for |this| | 252 // because of a race condition. The reference count for |this| |
249 // starts out as 0. Posting the Init task would increment the count | 253 // starts out as 0. Posting the Init task would increment the count |
250 // to 1. If the task finishes before the constructor returns, the | 254 // to 1. If the task finishes before the constructor returns, the |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 } | 909 } |
906 | 910 |
907 void NotificationPlatformBridgeLinux::SetReadyCallback( | 911 void NotificationPlatformBridgeLinux::SetReadyCallback( |
908 NotificationBridgeReadyCallback callback) { | 912 NotificationBridgeReadyCallback callback) { |
909 impl_->SetReadyCallback(std::move(callback)); | 913 impl_->SetReadyCallback(std::move(callback)); |
910 } | 914 } |
911 | 915 |
912 void NotificationPlatformBridgeLinux::CleanUp() { | 916 void NotificationPlatformBridgeLinux::CleanUp() { |
913 impl_->CleanUp(); | 917 impl_->CleanUp(); |
914 } | 918 } |
OLD | NEW |