1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_METRICS_EVENT_SERVICE_PROVIDER_H_ 6 #define CHROME_BROWSER_CHROMEOS_DBUS_METRICS_EVENT_SERVICE_PROVIDER_H_ 7 8 #include <string> 9 10 #include "base/macros.h" 11 #include "base/memory/ref_counted.h" 12 #include "chrome/browser/resource_coordinator/tab_lifecycle_observer.h" 13 #include "chromeos/dbus/metrics_event/metrics_event.pb.h" 14 #include "chromeos/dbus/services/cros_dbus_service.h" 15 #include "dbus/exported_object.h" 16 17 namespace chromeos { 18 19 // This class does not export any methods. An instance of this class can send 20 // signals to clients for a number of events of statistical interest, e.g. tab 21 // discards. 22 class MetricsEventServiceProvider 23 : public CrosDBusService::ServiceProviderInterface, 24 public resource_coordinator::TabLifecycleObserver { 25 public: 26 MetricsEventServiceProvider(); 27 ~MetricsEventServiceProvider() override; 28 29 // CrosDBusService::ServiceProviderInterface overrides: 30 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override; 31 32 private: 33 // resource_coordinator::TabLifecycleObserver: 34 void OnDiscardedStateChange(content::WebContents* contents, 35 mojom::LifecycleUnitDiscardReason reason, 36 bool is_discarded) override; 37 38 // Emits the D-Bus signal for this event. 39 void EmitSignal(metrics_event::Event_Type type); 40 41 // A reference on ExportedObject for sending signals. 42 scoped_refptr<dbus::ExportedObject> exported_object_; 43 44 DISALLOW_COPY_AND_ASSIGN(MetricsEventServiceProvider); 45 }; 46 47 } // namespace chromeos 48 49 #endif // CHROME_BROWSER_CHROMEOS_DBUS_METRICS_EVENT_SERVICE_PROVIDER_H_ 50