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

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

Issue 2671603002: Add network information to UKM (Closed)
Patch Set: fix comments and includes 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
« no previous file with comments | « components/metrics/test_metrics_provider.cc ('k') | components/ukm/ukm_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 }
26 28
27 namespace ukm { 29 namespace ukm {
28 30
29 class UkmSource; 31 class UkmSource;
30 32
31 // This feature controls whether UkmService should be created. 33 // This feature controls whether UkmService should be created.
32 extern const base::Feature kUkmFeature; 34 extern const base::Feature kUkmFeature;
33 35
34 // The Url-Keyed Metrics (UKM) service is responsible for gathering and 36 // The URL-Keyed Metrics (UKM) service is responsible for gathering and
35 // uploading reports that contain fine grained performance metrics including 37 // uploading reports that contain fine grained performance metrics including
36 // URLs for top-level navigations. 38 // URLs for top-level navigations.
37 class UkmService : public base::SupportsWeakPtr<UkmService> { 39 class UkmService : public base::SupportsWeakPtr<UkmService> {
38 public: 40 public:
39 // Constructs a UkmService. 41 // Constructs a UkmService.
40 // Calling code is responsible for ensuring that the lifetime of 42 // Calling code is responsible for ensuring that the lifetime of
41 // |pref_service| is longer than the lifetime of UkmService. 43 // |pref_service| is longer than the lifetime of UkmService.
42 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); 44 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client);
43 virtual ~UkmService(); 45 virtual ~UkmService();
44 46
45 // Initializes the UKM service. 47 // Initializes the UKM service.
46 void Initialize(); 48 void Initialize();
47 49
48 // Enable/disable transmission of accumulated logs. Logs that have already 50 // Enables/disables transmission of accumulated logs. Logs that have already
49 // been created will remain persisted to disk. 51 // been created will remain persisted to disk.
50 void EnableReporting(); 52 void EnableReporting();
51 void DisableReporting(); 53 void DisableReporting();
52 54
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 // Records any collected data into logs, and writes to disk.
58 void Flush(); 60 void Flush();
59 61
60 // Delete any unsent local data. 62 // Deletes any unsent local data.
61 void Purge(); 63 void Purge();
62 64
65 // Registers the specified |provider| to provide additional metrics into the
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:
73 // Start metrics client initialization. 80 // Starts metrics client initialization.
74 void StartInitTask(); 81 void StartInitTask();
75 82
76 // Called when initialization tasks are complete, to notify the scheduler 83 // Called when initialization tasks are complete, to notify the scheduler
77 // that it can begin calling RotateLog. 84 // that it can begin calling RotateLog.
78 void FinishedInitTask(); 85 void FinishedInitTask();
79 86
80 // Periodically called by scheduler_ to advance processing of logs. 87 // Periodically called by scheduler_ to advance processing of logs.
81 void RotateLog(); 88 void RotateLog();
82 89
83 // Constructs a new Report from available data and stores it in 90 // Constructs a new Report from available data and stores it in
84 // persisted_logs_. 91 // persisted_logs_.
85 void BuildAndStoreLog(); 92 void BuildAndStoreLog();
86 93
87 // Start an upload of the next log from persisted_logs_. 94 // Starts an upload of the next log from persisted_logs_.
88 void StartScheduledUpload(); 95 void StartScheduledUpload();
89 96
90 // Called by log_uploader_ when the an upload is completed. 97 // Called by log_uploader_ when the an upload is completed.
91 void OnLogUploadComplete(int response_code); 98 void OnLogUploadComplete(int response_code);
92 99
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
« no previous file with comments | « components/metrics/test_metrics_provider.cc ('k') | components/ukm/ukm_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698