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

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_linux.cc

Issue 2856753002: Linux native notifications: Add server capabilities metrics (Closed)
Patch Set: address mpearson@'s comments Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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
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("Freedesktop.Notifications",
283 notification_proxy_ != nullptr);
Peter Beverloo 2017/05/02 14:15:24 The difference between this one and the UMA define
Tom (Use chromium acct) 2017/05/02 18:49:41 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("Freedesktop.Notifications.Capabilities.ActionIcons",
304 capabilities_.count("action-icons"));
305 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.Actions",
306 capabilities_.count("actions"));
307 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.Body",
308 capabilities_.count("body"));
309 UMA_HISTOGRAM_BOOLEAN(
310 "Freedesktop.Notifications.Capabilities.BodyHyperlinks",
311 capabilities_.count("body-hyperlinks"));
312 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.BodyImages",
313 capabilities_.count("body-images"));
314 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.BodyMarkup",
315 capabilities_.count("body-markup"));
316 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.IconMulti",
317 capabilities_.count("icon-multi"));
318 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.IconStatic",
319 capabilities_.count("icon-static"));
320 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.Persistence",
321 capabilities_.count("persistence"));
322 UMA_HISTOGRAM_BOOLEAN("Freedesktop.Notifications.Capabilities.Sound",
323 capabilities_.count("sound"));
Peter Beverloo 2017/05/02 14:15:24 nit: maybe move this to another method so that we
Tom (Use chromium acct) 2017/05/02 18:49:41 Done.
324
286 connected_signals_barrier_ = base::BarrierClosure( 325 connected_signals_barrier_ = base::BarrierClosure(
287 2, base::Bind(&NotificationPlatformBridgeLinuxImpl:: 326 2, base::Bind(&NotificationPlatformBridgeLinuxImpl::
288 OnConnectionInitializationFinishedOnTaskRunner, 327 OnConnectionInitializationFinishedOnTaskRunner,
289 this, true)); 328 this, true));
290 notification_proxy_->ConnectToSignal( 329 notification_proxy_->ConnectToSignal(
291 kFreedesktopNotificationsName, "ActionInvoked", 330 kFreedesktopNotificationsName, "ActionInvoked",
292 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnActionInvoked, this), 331 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnActionInvoked, this),
293 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnSignalConnected, 332 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnSignalConnected,
294 this)); 333 this));
295 notification_proxy_->ConnectToSignal( 334 notification_proxy_->ConnectToSignal(
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 627
589 bool cleanup_posted_ = false; 628 bool cleanup_posted_ = false;
590 629
591 ////////////////////////////////////////////////////////////////////////////// 630 //////////////////////////////////////////////////////////////////////////////
592 // Members used only on the task runner thread. 631 // Members used only on the task runner thread.
593 632
594 scoped_refptr<dbus::Bus> bus_; 633 scoped_refptr<dbus::Bus> bus_;
595 634
596 dbus::ObjectProxy* notification_proxy_ = nullptr; 635 dbus::ObjectProxy* notification_proxy_ = nullptr;
597 636
637 std::unordered_set<std::string> capabilities_;
638
598 base::Closure connected_signals_barrier_; 639 base::Closure connected_signals_barrier_;
599 640
600 // A std::set<std::unique_ptr<T>> doesn't work well because 641 // 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> 642 // eg. std::set::erase(T) would require a std::unique_ptr<T>
602 // argument, so the data would get double-destructed. 643 // argument, so the data would get double-destructed.
603 template <typename T> 644 template <typename T>
604 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; 645 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>;
605 646
606 UnorderedUniqueSet<NotificationData> notifications_; 647 UnorderedUniqueSet<NotificationData> notifications_;
607 648
(...skipping 25 matching lines...) Expand all
633 const std::string& profile_id, 674 const std::string& profile_id,
634 bool incognito, 675 bool incognito,
635 const GetDisplayedNotificationsCallback& callback) const { 676 const GetDisplayedNotificationsCallback& callback) const {
636 impl_->GetDisplayed(profile_id, incognito, callback); 677 impl_->GetDisplayed(profile_id, incognito, callback);
637 } 678 }
638 679
639 void NotificationPlatformBridgeLinux::SetReadyCallback( 680 void NotificationPlatformBridgeLinux::SetReadyCallback(
640 NotificationBridgeReadyCallback callback) { 681 NotificationBridgeReadyCallback callback) {
641 impl_->SetReadyCallback(std::move(callback)); 682 impl_->SetReadyCallback(std::move(callback));
642 } 683 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698