blob: 76ea2e803ed7912adf12a1bc82396f9ce94774b2 [file] [log] [blame]
cnwan1ed447862016-03-21 08:00:101// Copyright 2016 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
lhchavezde2de962016-07-13 04:43:015#ifndef COMPONENTS_ARC_METRICS_ARC_METRICS_SERVICE_H_
6#define COMPONENTS_ARC_METRICS_ARC_METRICS_SERVICE_H_
cnwan1ed447862016-03-21 08:00:107
lhchavezdb94ad72016-11-12 04:08:478#include <vector>
9
cnwan1ed447862016-03-21 08:00:1010#include "base/macros.h"
11#include "base/memory/weak_ptr.h"
Hidehiko Abe3c446ed2017-10-11 10:31:2512#include "base/optional.h"
cnwan1ed447862016-03-21 08:00:1013#include "base/threading/thread_checker.h"
14#include "base/timer/timer.h"
yusukes883612b2016-10-13 18:07:0515#include "components/arc/common/metrics.mojom.h"
16#include "components/arc/common/process.mojom.h"
Hidehiko Abeac2e5512017-11-21 09:54:4617#include "components/arc/connection_observer.h"
Hidehiko Abef7f59ab62017-07-16 12:56:5818#include "components/keyed_service/core/keyed_service.h"
cnwan1ed447862016-03-21 08:00:1019
yusukesef9c7752017-11-28 17:57:4420class BrowserContextKeyedServiceFactory;
21
Hidehiko Abef7f59ab62017-07-16 12:56:5822namespace content {
23class BrowserContext;
24} // namespace content
25
cnwan1ed447862016-03-21 08:00:1026namespace arc {
27
yusukes883612b2016-10-13 18:07:0528class ArcBridgeService;
29
cnwan1ed447862016-03-21 08:00:1030// Collects information from other ArcServices and send UMA metrics.
Hidehiko Abeac2e5512017-11-21 09:54:4631class ArcMetricsService : public KeyedService,
Hidehiko Abeac2e5512017-11-21 09:54:4632 public mojom::MetricsHost {
cnwan1ed447862016-03-21 08:00:1033 public:
yusukesef9c7752017-11-28 17:57:4434 // Returns the factory instance for this class.
35 static BrowserContextKeyedServiceFactory* GetFactory();
36
Hidehiko Abef7f59ab62017-07-16 12:56:5837 // Returns singleton instance for the given BrowserContext,
38 // or nullptr if the browser |context| is not allowed to use ARC.
39 static ArcMetricsService* GetForBrowserContext(
40 content::BrowserContext* context);
41
42 ArcMetricsService(content::BrowserContext* context,
43 ArcBridgeService* bridge_service);
cnwan1ed447862016-03-21 08:00:1044 ~ArcMetricsService() override;
45
Hidehiko Abeac2e5512017-11-21 09:54:4646 // Implementations for ConnectionObserver<mojom::ProcessInstance>.
47 void OnProcessConnectionReady();
48 void OnProcessConnectionClosed();
cnwan1ed447862016-03-21 08:00:1049
cywang020b77ac2016-04-27 06:13:0950 // MetricsHost overrides.
yusukesd6ea165b2017-05-26 23:26:0451 void ReportBootProgress(std::vector<mojom::BootProgressEventPtr> events,
52 mojom::BootType boot_type) override;
cywang020b77ac2016-04-27 06:13:0953
cnwan1ed447862016-03-21 08:00:1054 private:
lhchavezde2de962016-07-13 04:43:0155 // Adapter to be able to also observe ProcessInstance events.
Hidehiko Abeac2e5512017-11-21 09:54:4656 class ProcessObserver : public ConnectionObserver<mojom::ProcessInstance> {
lhchavezde2de962016-07-13 04:43:0157 public:
58 explicit ProcessObserver(ArcMetricsService* arc_metrics_service);
59 ~ProcessObserver() override;
60
61 private:
Hidehiko Abeac2e5512017-11-21 09:54:4662 // ConnectionObserver<mojom::ProcessInstance> overrides.
63 void OnConnectionReady() override;
64 void OnConnectionClosed() override;
lhchavezde2de962016-07-13 04:43:0165
66 ArcMetricsService* arc_metrics_service_;
yusukesdbfd3952017-01-16 02:48:5667
68 DISALLOW_COPY_AND_ASSIGN(ProcessObserver);
lhchavezde2de962016-07-13 04:43:0169 };
70
Hidehiko Abea0cfefae2017-06-22 19:30:1171 void RequestProcessList();
72 void ParseProcessList(std::vector<mojom::RunningAppProcessInfoPtr> processes);
73
74 // DBus callbacks.
Hidehiko Abed0c8e462017-11-22 06:02:1775 void OnArcStartTimeRetrieved(std::vector<mojom::BootProgressEventPtr> events,
76 mojom::BootType boot_type,
77 base::Optional<base::TimeTicks> arc_start_time);
Hidehiko Abea0cfefae2017-06-22 19:30:1178
79 THREAD_CHECKER(thread_checker_);
80
Hidehiko Abef7f59ab62017-07-16 12:56:5881 ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
82
lhchavezde2de962016-07-13 04:43:0183 ProcessObserver process_observer_;
cnwan1ed447862016-03-21 08:00:1084 base::RepeatingTimer timer_;
85
86 // Always keep this the last member of this class to make sure it's the
87 // first thing to be destructed.
88 base::WeakPtrFactory<ArcMetricsService> weak_ptr_factory_;
89
90 DISALLOW_COPY_AND_ASSIGN(ArcMetricsService);
91};
92
93} // namespace arc
94
lhchavezde2de962016-07-13 04:43:0195#endif // COMPONENTS_ARC_METRICS_ARC_METRICS_SERVICE_H_