blob: 05405c253b910d78e90cbdf28596ededd7d0c799 [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:
Lev Rumyantsevdeae3252017-12-06 04:57:0534 // This is public for testing only.
35 enum class NativeBridgeType {
36 // Native bridge value has not been received from the container yet.
37 UNKNOWN = 0,
38 // Native bridge is not used.
39 NONE = 1,
40 // Using houdini translator.
41 HOUDINI = 2,
42 // Using ndk-translation translator.
43 NDK_TRANSLATION = 3,
44 COUNT
45 };
46
yusukesef9c7752017-11-28 17:57:4447 // Returns the factory instance for this class.
48 static BrowserContextKeyedServiceFactory* GetFactory();
49
Hidehiko Abef7f59ab62017-07-16 12:56:5850 // Returns singleton instance for the given BrowserContext,
51 // or nullptr if the browser |context| is not allowed to use ARC.
52 static ArcMetricsService* GetForBrowserContext(
53 content::BrowserContext* context);
54
55 ArcMetricsService(content::BrowserContext* context,
56 ArcBridgeService* bridge_service);
cnwan1ed447862016-03-21 08:00:1057 ~ArcMetricsService() override;
58
Hidehiko Abeac2e5512017-11-21 09:54:4659 // Implementations for ConnectionObserver<mojom::ProcessInstance>.
60 void OnProcessConnectionReady();
61 void OnProcessConnectionClosed();
cnwan1ed447862016-03-21 08:00:1062
cywang020b77ac2016-04-27 06:13:0963 // MetricsHost overrides.
yusukesd6ea165b2017-05-26 23:26:0464 void ReportBootProgress(std::vector<mojom::BootProgressEventPtr> events,
65 mojom::BootType boot_type) override;
Lev Rumyantsevdeae3252017-12-06 04:57:0566 void ReportNativeBridge(mojom::NativeBridgeType native_bridge_type) override;
67
68 NativeBridgeType native_bridge_type_for_testing() const {
69 return native_bridge_type_;
70 }
cywang020b77ac2016-04-27 06:13:0971
cnwan1ed447862016-03-21 08:00:1072 private:
lhchavezde2de962016-07-13 04:43:0173 // Adapter to be able to also observe ProcessInstance events.
Hidehiko Abeac2e5512017-11-21 09:54:4674 class ProcessObserver : public ConnectionObserver<mojom::ProcessInstance> {
lhchavezde2de962016-07-13 04:43:0175 public:
76 explicit ProcessObserver(ArcMetricsService* arc_metrics_service);
77 ~ProcessObserver() override;
78
79 private:
Hidehiko Abeac2e5512017-11-21 09:54:4680 // ConnectionObserver<mojom::ProcessInstance> overrides.
81 void OnConnectionReady() override;
82 void OnConnectionClosed() override;
lhchavezde2de962016-07-13 04:43:0183
84 ArcMetricsService* arc_metrics_service_;
yusukesdbfd3952017-01-16 02:48:5685
86 DISALLOW_COPY_AND_ASSIGN(ProcessObserver);
lhchavezde2de962016-07-13 04:43:0187 };
88
Hidehiko Abea0cfefae2017-06-22 19:30:1189 void RequestProcessList();
90 void ParseProcessList(std::vector<mojom::RunningAppProcessInfoPtr> processes);
91
92 // DBus callbacks.
Hidehiko Abed0c8e462017-11-22 06:02:1793 void OnArcStartTimeRetrieved(std::vector<mojom::BootProgressEventPtr> events,
94 mojom::BootType boot_type,
95 base::Optional<base::TimeTicks> arc_start_time);
Hidehiko Abea0cfefae2017-06-22 19:30:1196
97 THREAD_CHECKER(thread_checker_);
98
Hidehiko Abef7f59ab62017-07-16 12:56:5899 ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
100
lhchavezde2de962016-07-13 04:43:01101 ProcessObserver process_observer_;
cnwan1ed447862016-03-21 08:00:10102 base::RepeatingTimer timer_;
103
Lev Rumyantsevdeae3252017-12-06 04:57:05104 NativeBridgeType native_bridge_type_;
105
cnwan1ed447862016-03-21 08:00:10106 // Always keep this the last member of this class to make sure it's the
107 // first thing to be destructed.
108 base::WeakPtrFactory<ArcMetricsService> weak_ptr_factory_;
109
110 DISALLOW_COPY_AND_ASSIGN(ArcMetricsService);
111};
112
113} // namespace arc
114
lhchavezde2de962016-07-13 04:43:01115#endif // COMPONENTS_ARC_METRICS_ARC_METRICS_SERVICE_H_