OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_UKM_UKM_SERVICE_H_ | |
6 #define COMPONENTS_UKM_UKM_SERVICE_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "components/metrics/metrics_reporting_scheduler.h" | |
14 #include "components/metrics/persisted_logs.h" | |
15 | |
16 class PrefRegistrySimple; | |
17 class PrefService; | |
18 | |
19 namespace metrics { | |
20 class MetricsLogUploader; | |
21 class MetricsServiceClient; | |
22 } | |
23 | |
24 namespace ukm { | |
25 | |
26 // Manages the generation and uploading of UKM reports. | |
rkaplow
2017/01/04 17:57:57
I'd suggest a bit more top-level documentation on
Steven Holte
2017/01/04 22:47:55
Expanded this a bit.
| |
27 class UkmService : public base::SupportsWeakPtr<UkmService> { | |
28 public: | |
29 // Constructs a UkmService. | |
30 // Calling code is responsible for ensuring that the lifetime of | |
31 // |pref_service| is longer than the lifetime of UkmService. | |
32 UkmService( | |
33 PrefService* pref_service, | |
34 metrics::MetricsServiceClient* client); | |
35 virtual ~UkmService(); | |
36 | |
37 // Initializes the UKM service. | |
38 void Initialize(); | |
39 | |
40 // Enable/disable transmission of accumulated logs. Logs that have already | |
41 // been created will remain persisted to disk. | |
42 void EnableReporting(); | |
43 void DisableReporting(); | |
44 | |
45 // Registers the names of all of the preferences used by UkmService in | |
46 // the provided PrefRegistry. | |
47 static void RegisterPrefs(PrefRegistrySimple* registry); | |
48 | |
49 private: | |
50 // Start metrics client initialization. | |
51 void StartInitTask(); | |
52 | |
53 // Called when initialization tasks are complete, to notify the scheduler | |
54 // that it can begin calling RotateLog. | |
55 void FinishedInitTask(); | |
56 | |
57 // Periodically called by scheduler_ to advance processing of logs. | |
58 void RotateLog(); | |
59 | |
60 // Constructs a new Report from available data and stores it in | |
61 // persisted_logs_. | |
62 void BuildAndStoreLog(); | |
63 | |
64 // Start an upload of the next log from persisted_logs_. | |
65 void StartScheduledUpload(); | |
66 | |
67 // Called by log_uploader_ when the an upload is completed. | |
68 void OnLogUploadComplete(int response_code); | |
69 | |
70 // A weak pointer to the PrefService used to read and write preferences. | |
71 PrefService* pref_service_; | |
72 | |
73 // The UKM client id stored in prefs. | |
74 uint64_t client_id_; | |
75 | |
76 // Used to interact with the embedder. Weak pointer; must outlive |this| | |
77 // instance. | |
78 metrics::MetricsServiceClient* const client_; | |
79 | |
80 // Logs that have not yet been sent. | |
81 metrics::PersistedLogs persisted_logs_; | |
82 | |
83 // The scheduler for determining when uploads should happen. | |
84 std::unique_ptr<metrics::MetricsReportingScheduler> scheduler_; | |
85 | |
86 base::ThreadChecker thread_checker_; | |
87 | |
88 // Instance of the helper class for uploading logs. | |
89 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; | |
90 | |
91 bool initialize_started_; | |
92 bool log_upload_in_progress_; | |
93 | |
94 // Weak pointers factory used to post task on different threads. All weak | |
95 // pointers managed by this factory have the same lifetime as UkmService. | |
96 base::WeakPtrFactory<UkmService> self_ptr_factory_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(UkmService); | |
99 }; | |
100 | |
101 } // namespace ukm | |
102 | |
103 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | |
OLD | NEW |