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 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/metrics/histogram_macros.h" | |
11 #include "base/strings/nullable_string16.h" | 12 #include "base/strings/nullable_string16.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/task_scheduler/post_task.h" | 16 #include "base/task_scheduler/post_task.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/notifications/native_notification_display_service.h" | 19 #include "chrome/browser/notifications/native_notification_display_service.h" |
19 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
20 #include "chrome/browser/notifications/notification_display_service_factory.h" | 21 #include "chrome/browser/notifications/notification_display_service_factory.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 272 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
272 dbus::Bus::Options bus_options; | 273 dbus::Bus::Options bus_options; |
273 bus_options.bus_type = dbus::Bus::SESSION; | 274 bus_options.bus_type = dbus::Bus::SESSION; |
274 bus_options.connection_type = dbus::Bus::PRIVATE; | 275 bus_options.connection_type = dbus::Bus::PRIVATE; |
275 bus_options.dbus_task_runner = task_runner_; | 276 bus_options.dbus_task_runner = task_runner_; |
276 bus_ = make_scoped_refptr(new dbus::Bus(bus_options)); | 277 bus_ = make_scoped_refptr(new dbus::Bus(bus_options)); |
277 | 278 |
278 notification_proxy_ = | 279 notification_proxy_ = |
279 bus_->GetObjectProxy(kFreedesktopNotificationsName, | 280 bus_->GetObjectProxy(kFreedesktopNotificationsName, |
280 dbus::ObjectPath(kFreedesktopNotificationsPath)); | 281 dbus::ObjectPath(kFreedesktopNotificationsPath)); |
282 UMA_HISTOGRAM_BOOLEAN("org.Freedesktop.Notifications", | |
283 !!notification_proxy_); | |
Mark P
2017/05/01 22:07:01
drive-by nit: I find "!!" hard to read.
Tom (Use chromium acct)
2017/05/01 22:35:01
Done.
| |
281 if (!notification_proxy_) { | 284 if (!notification_proxy_) { |
282 OnConnectionInitializationFinishedOnTaskRunner(false); | 285 OnConnectionInitializationFinishedOnTaskRunner(false); |
283 return; | 286 return; |
284 } | 287 } |
285 | 288 |
289 dbus::MethodCall get_capabilities_call(kFreedesktopNotificationsName, | |
290 "GetCapabilities"); | |
291 std::unique_ptr<dbus::Response> capabilities_response = | |
292 notification_proxy_->CallMethodAndBlock( | |
293 &get_capabilities_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); | |
294 if (capabilities_response) { | |
295 dbus::MessageReader reader(capabilities_response.get()); | |
296 std::vector<std::string> capabilities; | |
297 reader.PopArrayOfStrings(&capabilities); | |
298 for (const std::string& capability : capabilities) | |
299 capabilities_.insert(capability); | |
300 } | |
301 // Histogram macros must be called with the same name for each | |
302 // callsite, so we can't roll the below into a nice loop. | |
303 UMA_HISTOGRAM_BOOLEAN( | |
304 "org.Freedesktop.Notifications.Capabilities.action-icons", | |
305 capabilities_.count("action-icons")); | |
306 UMA_HISTOGRAM_BOOLEAN("org.Freedesktop.Notifications.Capabilities.actions", | |
307 capabilities_.count("actions")); | |
308 UMA_HISTOGRAM_BOOLEAN("org.Freedesktop.Notifications.Capabilities.body", | |
309 capabilities_.count("body")); | |
310 UMA_HISTOGRAM_BOOLEAN( | |
311 "org.Freedesktop.Notifications.Capabilities.body-hyperlinks", | |
312 capabilities_.count("body-hyperlinks")); | |
313 UMA_HISTOGRAM_BOOLEAN( | |
314 "org.Freedesktop.Notifications.Capabilities.body-images", | |
315 capabilities_.count("body-images")); | |
316 UMA_HISTOGRAM_BOOLEAN( | |
317 "org.Freedesktop.Notifications.Capabilities.body-markup", | |
318 capabilities_.count("body-markup")); | |
319 UMA_HISTOGRAM_BOOLEAN( | |
320 "org.Freedesktop.Notifications.Capabilities.icon-multi", | |
321 capabilities_.count("icon-multi")); | |
322 UMA_HISTOGRAM_BOOLEAN( | |
323 "org.Freedesktop.Notifications.Capabilities.icon-static", | |
324 capabilities_.count("icon-static")); | |
325 UMA_HISTOGRAM_BOOLEAN( | |
326 "org.Freedesktop.Notifications.Capabilities.persistence", | |
327 capabilities_.count("persistence")); | |
328 UMA_HISTOGRAM_BOOLEAN("org.Freedesktop.Notifications.Capabilities.sound", | |
329 capabilities_.count("sound")); | |
330 | |
286 connected_signals_barrier_ = base::BarrierClosure( | 331 connected_signals_barrier_ = base::BarrierClosure( |
287 2, base::Bind(&NotificationPlatformBridgeLinuxImpl:: | 332 2, base::Bind(&NotificationPlatformBridgeLinuxImpl:: |
288 OnConnectionInitializationFinishedOnTaskRunner, | 333 OnConnectionInitializationFinishedOnTaskRunner, |
289 this, true)); | 334 this, true)); |
290 notification_proxy_->ConnectToSignal( | 335 notification_proxy_->ConnectToSignal( |
291 kFreedesktopNotificationsName, "ActionInvoked", | 336 kFreedesktopNotificationsName, "ActionInvoked", |
292 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnActionInvoked, this), | 337 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnActionInvoked, this), |
293 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnSignalConnected, | 338 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnSignalConnected, |
294 this)); | 339 this)); |
295 notification_proxy_->ConnectToSignal( | 340 notification_proxy_->ConnectToSignal( |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 return; | 585 return; |
541 | 586 |
542 ForwardNotificationOperation(data, NotificationCommon::CLOSE, -1); | 587 ForwardNotificationOperation(data, NotificationCommon::CLOSE, -1); |
543 notifications_.erase(data); | 588 notifications_.erase(data); |
544 } | 589 } |
545 | 590 |
546 // Called once the connection has been set up (or not). |success| | 591 // Called once the connection has been set up (or not). |success| |
547 // indicates the connection is ready to use. | 592 // indicates the connection is ready to use. |
548 void OnConnectionInitializationFinishedOnUiThread(bool success) { | 593 void OnConnectionInitializationFinishedOnUiThread(bool success) { |
549 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 594 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
595 UMA_HISTOGRAM_BOOLEAN("Linux.NativeNotifications.UsingNativeNotifications", | |
596 success); | |
550 connected_ = success; | 597 connected_ = success; |
551 for (auto& callback : on_connected_callbacks_) | 598 for (auto& callback : on_connected_callbacks_) |
552 std::move(callback).Run(success); | 599 std::move(callback).Run(success); |
553 on_connected_callbacks_.clear(); | 600 on_connected_callbacks_.clear(); |
554 if (!success) | 601 if (!success) |
555 CleanUp(); | 602 CleanUp(); |
556 } | 603 } |
557 | 604 |
558 void OnConnectionInitializationFinishedOnTaskRunner(bool success) { | 605 void OnConnectionInitializationFinishedOnTaskRunner(bool success) { |
559 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 606 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 28 matching lines...) Expand all Loading... | |
588 | 635 |
589 bool cleanup_posted_ = false; | 636 bool cleanup_posted_ = false; |
590 | 637 |
591 ////////////////////////////////////////////////////////////////////////////// | 638 ////////////////////////////////////////////////////////////////////////////// |
592 // Members used only on the task runner thread. | 639 // Members used only on the task runner thread. |
593 | 640 |
594 scoped_refptr<dbus::Bus> bus_; | 641 scoped_refptr<dbus::Bus> bus_; |
595 | 642 |
596 dbus::ObjectProxy* notification_proxy_ = nullptr; | 643 dbus::ObjectProxy* notification_proxy_ = nullptr; |
597 | 644 |
645 std::unordered_set<std::string> capabilities_; | |
646 | |
598 base::Closure connected_signals_barrier_; | 647 base::Closure connected_signals_barrier_; |
599 | 648 |
600 // A std::set<std::unique_ptr<T>> doesn't work well because | 649 // A std::set<std::unique_ptr<T>> doesn't work well because |
601 // eg. std::set::erase(T) would require a std::unique_ptr<T> | 650 // eg. std::set::erase(T) would require a std::unique_ptr<T> |
602 // argument, so the data would get double-destructed. | 651 // argument, so the data would get double-destructed. |
603 template <typename T> | 652 template <typename T> |
604 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; | 653 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; |
605 | 654 |
606 UnorderedUniqueSet<NotificationData> notifications_; | 655 UnorderedUniqueSet<NotificationData> notifications_; |
607 | 656 |
(...skipping 25 matching lines...) Expand all Loading... | |
633 const std::string& profile_id, | 682 const std::string& profile_id, |
634 bool incognito, | 683 bool incognito, |
635 const GetDisplayedNotificationsCallback& callback) const { | 684 const GetDisplayedNotificationsCallback& callback) const { |
636 impl_->GetDisplayed(profile_id, incognito, callback); | 685 impl_->GetDisplayed(profile_id, incognito, callback); |
637 } | 686 } |
638 | 687 |
639 void NotificationPlatformBridgeLinux::SetReadyCallback( | 688 void NotificationPlatformBridgeLinux::SetReadyCallback( |
640 NotificationBridgeReadyCallback callback) { | 689 NotificationBridgeReadyCallback callback) { |
641 impl_->SetReadyCallback(std::move(callback)); | 690 impl_->SetReadyCallback(std::move(callback)); |
642 } | 691 } |
OLD | NEW |