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

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

Issue 2649303004: UKM: Added support for navigation sources (Closed)
Patch Set: Histogram description Created 3 years, 11 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/ukm/test_ukm_service.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 10
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "components/metrics/metrics_reporting_scheduler.h" 16 #include "components/metrics/metrics_reporting_scheduler.h"
17 #include "components/metrics/persisted_logs.h" 17 #include "components/metrics/persisted_logs.h"
18 18
19 class PrefRegistrySimple; 19 class PrefRegistrySimple;
20 class PrefService; 20 class PrefService;
21 21
22 namespace metrics { 22 namespace metrics {
23 class MetricsLogUploader; 23 class MetricsLogUploader;
24 class MetricsServiceClient; 24 class MetricsServiceClient;
25 } 25 }
26 26
27 namespace ukm { 27 namespace ukm {
28 28
29 class UkmSource;
30
29 // This feature controls whether UkmService should be created. 31 // This feature controls whether UkmService should be created.
30 extern const base::Feature kUkmFeature; 32 extern const base::Feature kUkmFeature;
31 33
32 // The Url-Keyed Metrics (UKM) service is responsible for gathering and 34 // The Url-Keyed Metrics (UKM) service is responsible for gathering and
33 // uploading reports that contain fine grained performance metrics including 35 // uploading reports that contain fine grained performance metrics including
34 // URLs for top-level navigations. 36 // URLs for top-level navigations.
35 class UkmService : public base::SupportsWeakPtr<UkmService> { 37 class UkmService : public base::SupportsWeakPtr<UkmService> {
36 public: 38 public:
37 // Constructs a UkmService. 39 // Constructs a UkmService.
38 // Calling code is responsible for ensuring that the lifetime of 40 // Calling code is responsible for ensuring that the lifetime of
39 // |pref_service| is longer than the lifetime of UkmService. 41 // |pref_service| is longer than the lifetime of UkmService.
40 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); 42 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client);
41 virtual ~UkmService(); 43 virtual ~UkmService();
42 44
43 // Initializes the UKM service. 45 // Initializes the UKM service.
44 void Initialize(); 46 void Initialize();
45 47
46 // Enable/disable transmission of accumulated logs. Logs that have already 48 // Enable/disable transmission of accumulated logs. Logs that have already
47 // been created will remain persisted to disk. 49 // been created will remain persisted to disk.
48 void EnableReporting(); 50 void EnableReporting();
49 void DisableReporting(); 51 void DisableReporting();
50 52
53 // Adds a new source of UKM metrics, which will be stored
54 // until periodically serialized for upload, and then deleted.
55 void RecordSource(std::unique_ptr<UkmSource> source);
56
51 // Record any collected data into logs, and write to disk. 57 // Record any collected data into logs, and write to disk.
52 void Flush(); 58 void Flush();
53 59
54 // Delete any unsent local data. 60 // Delete any unsent local data.
55 void Purge(); 61 void Purge();
56 62
57 // Registers the names of all of the preferences used by UkmService in 63 // Registers the names of all of the preferences used by UkmService in
58 // the provided PrefRegistry. 64 // the provided PrefRegistry.
59 static void RegisterPrefs(PrefRegistrySimple* registry); 65 static void RegisterPrefs(PrefRegistrySimple* registry);
60 66
67 protected:
68 const std::vector<std::unique_ptr<UkmSource>>& sources_for_testing() const {
69 return sources_;
70 }
71
61 private: 72 private:
62 // Start metrics client initialization. 73 // Start metrics client initialization.
63 void StartInitTask(); 74 void StartInitTask();
64 75
65 // Called when initialization tasks are complete, to notify the scheduler 76 // Called when initialization tasks are complete, to notify the scheduler
66 // that it can begin calling RotateLog. 77 // that it can begin calling RotateLog.
67 void FinishedInitTask(); 78 void FinishedInitTask();
68 79
69 // Periodically called by scheduler_ to advance processing of logs. 80 // Periodically called by scheduler_ to advance processing of logs.
70 void RotateLog(); 81 void RotateLog();
(...skipping 26 matching lines...) Expand all
97 108
98 base::ThreadChecker thread_checker_; 109 base::ThreadChecker thread_checker_;
99 110
100 // Instance of the helper class for uploading logs. 111 // Instance of the helper class for uploading logs.
101 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; 112 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_;
102 113
103 bool initialize_started_; 114 bool initialize_started_;
104 bool initialize_complete_; 115 bool initialize_complete_;
105 bool log_upload_in_progress_; 116 bool log_upload_in_progress_;
106 117
118 // Contains newly added sources of UKM metrics which periodically
119 // get serialized and cleared by BuildAndStoreLog().
120 std::vector<std::unique_ptr<UkmSource>> sources_;
121
107 // Weak pointers factory used to post task on different threads. All weak 122 // Weak pointers factory used to post task on different threads. All weak
108 // pointers managed by this factory have the same lifetime as UkmService. 123 // pointers managed by this factory have the same lifetime as UkmService.
109 base::WeakPtrFactory<UkmService> self_ptr_factory_; 124 base::WeakPtrFactory<UkmService> self_ptr_factory_;
110 125
111 DISALLOW_COPY_AND_ASSIGN(UkmService); 126 DISALLOW_COPY_AND_ASSIGN(UkmService);
112 }; 127 };
113 128
114 } // namespace ukm 129 } // namespace ukm
115 130
116 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ 131 #endif // COMPONENTS_UKM_UKM_SERVICE_H_
OLDNEW
« no previous file with comments | « components/ukm/test_ukm_service.cc ('k') | components/ukm/ukm_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698