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

Side by Side Diff: components/ukm/ukm_service.h

Issue 2671603002: Add network information to UKM (Closed)
Patch Set: provider test Created 3 years, 10 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 #ifndef COMPONENTS_UKM_UKM_SERVICE_H_ 5 #ifndef COMPONENTS_UKM_UKM_SERVICE_H_
6 #define COMPONENTS_UKM_UKM_SERVICE_H_ 6 #define COMPONENTS_UKM_UKM_SERVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <memory> 9 #include <memory>
10 #include <vector>
10 11
11 #include "base/feature_list.h" 12 #include "base/feature_list.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "components/metrics/metrics_provider.h"
16 #include "components/metrics/metrics_reporting_scheduler.h" 18 #include "components/metrics/metrics_reporting_scheduler.h"
17 #include "components/metrics/persisted_logs.h" 19 #include "components/metrics/persisted_logs.h"
18 20
19 class PrefRegistrySimple; 21 class PrefRegistrySimple;
20 class PrefService; 22 class PrefService;
21 23
22 namespace metrics { 24 namespace metrics {
23 class MetricsLogUploader; 25 class MetricsLogUploader;
24 class MetricsServiceClient; 26 class MetricsServiceClient;
25 } 27 }
(...skipping 27 matching lines...) Expand all
53 // Adds a new source of UKM metrics, which will be stored 55 // Adds a new source of UKM metrics, which will be stored
54 // until periodically serialized for upload, and then deleted. 56 // until periodically serialized for upload, and then deleted.
55 void RecordSource(std::unique_ptr<UkmSource> source); 57 void RecordSource(std::unique_ptr<UkmSource> source);
56 58
57 // Record any collected data into logs, and write to disk. 59 // Record any collected data into logs, and write to disk.
58 void Flush(); 60 void Flush();
59 61
60 // Delete any unsent local data. 62 // Delete any unsent local data.
61 void Purge(); 63 void Purge();
62 64
65 // Register the specified |provider| to provide additional metrics into the
Alexei Svitkine (slow) 2017/02/06 16:07:40 Nit: Registers Also can you change the tense of t
rkaplow 2017/02/06 16:31:41 fixed those and a few other comment
66 // UKM log. Should be called during MetricsService initialization only.
67 void RegisterMetricsProvider(
68 std::unique_ptr<metrics::MetricsProvider> provider);
69
63 // Registers the names of all of the preferences used by UkmService in 70 // Registers the names of all of the preferences used by UkmService in
64 // the provided PrefRegistry. 71 // the provided PrefRegistry.
65 static void RegisterPrefs(PrefRegistrySimple* registry); 72 static void RegisterPrefs(PrefRegistrySimple* registry);
66 73
67 protected: 74 protected:
68 const std::vector<std::unique_ptr<UkmSource>>& sources_for_testing() const { 75 const std::vector<std::unique_ptr<UkmSource>>& sources_for_testing() const {
69 return sources_; 76 return sources_;
70 } 77 }
71 78
72 private: 79 private:
(...skipping 20 matching lines...) Expand all
93 // A weak pointer to the PrefService used to read and write preferences. 100 // A weak pointer to the PrefService used to read and write preferences.
94 PrefService* pref_service_; 101 PrefService* pref_service_;
95 102
96 // The UKM client id stored in prefs. 103 // The UKM client id stored in prefs.
97 uint64_t client_id_; 104 uint64_t client_id_;
98 105
99 // Used to interact with the embedder. Weak pointer; must outlive |this| 106 // Used to interact with the embedder. Weak pointer; must outlive |this|
100 // instance. 107 // instance.
101 metrics::MetricsServiceClient* const client_; 108 metrics::MetricsServiceClient* const client_;
102 109
110 // Registered metrics providers.
111 std::vector<std::unique_ptr<metrics::MetricsProvider>> metrics_providers_;
112
103 // Logs that have not yet been sent. 113 // Logs that have not yet been sent.
104 metrics::PersistedLogs persisted_logs_; 114 metrics::PersistedLogs persisted_logs_;
105 115
106 // The scheduler for determining when uploads should happen. 116 // The scheduler for determining when uploads should happen.
107 std::unique_ptr<metrics::MetricsReportingScheduler> scheduler_; 117 std::unique_ptr<metrics::MetricsReportingScheduler> scheduler_;
108 118
109 base::ThreadChecker thread_checker_; 119 base::ThreadChecker thread_checker_;
110 120
111 // Instance of the helper class for uploading logs. 121 // Instance of the helper class for uploading logs.
112 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; 122 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_;
113 123
114 bool initialize_started_; 124 bool initialize_started_;
115 bool initialize_complete_; 125 bool initialize_complete_;
116 bool log_upload_in_progress_; 126 bool log_upload_in_progress_;
117 127
118 // Contains newly added sources of UKM metrics which periodically 128 // Contains newly added sources of UKM metrics which periodically
119 // get serialized and cleared by BuildAndStoreLog(). 129 // get serialized and cleared by BuildAndStoreLog().
120 std::vector<std::unique_ptr<UkmSource>> sources_; 130 std::vector<std::unique_ptr<UkmSource>> sources_;
121 131
122 // Weak pointers factory used to post task on different threads. All weak 132 // Weak pointers factory used to post task on different threads. All weak
123 // pointers managed by this factory have the same lifetime as UkmService. 133 // pointers managed by this factory have the same lifetime as UkmService.
124 base::WeakPtrFactory<UkmService> self_ptr_factory_; 134 base::WeakPtrFactory<UkmService> self_ptr_factory_;
125 135
126 DISALLOW_COPY_AND_ASSIGN(UkmService); 136 DISALLOW_COPY_AND_ASSIGN(UkmService);
127 }; 137 };
128 138
129 } // namespace ukm 139 } // namespace ukm
130 140
131 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ 141 #endif // COMPONENTS_UKM_UKM_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698