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

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

Issue 2617883004: Initial UKMPageLoadMetricsObserver (Closed)
Patch Set: Class rename 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 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 "components/metrics/metrics_reporting_scheduler.h" 15 #include "components/metrics/metrics_reporting_scheduler.h"
16 #include "components/metrics/persisted_logs.h" 16 #include "components/metrics/persisted_logs.h"
17 17
18 class PrefRegistrySimple; 18 class PrefRegistrySimple;
19 class PrefService; 19 class PrefService;
20 20
21 namespace metrics { 21 namespace metrics {
22 class MetricsLogUploader; 22 class MetricsLogUploader;
23 class MetricsServiceClient; 23 class MetricsServiceClient;
24 } 24 }
25 25
26 namespace ukm { 26 namespace ukm {
27 27
28 class UkmSource;
29
28 // This feature controls whether UkmService should be created. 30 // This feature controls whether UkmService should be created.
29 extern const base::Feature kUkmFeature; 31 extern const base::Feature kUkmFeature;
30 32
31 // Manages the generation and uploading of UKM reports. 33 // Manages the generation and uploading of UKM reports.
32 // These reports contained fine grained performance metrics including URLs for 34 // These reports contained fine grained performance metrics including URLs for
33 // top-level navigations. 35 // top-level navigations.
34 class UkmService : public base::SupportsWeakPtr<UkmService> { 36 class UkmService : public base::SupportsWeakPtr<UkmService> {
35 public: 37 public:
36 // Constructs a UkmService. 38 // Constructs a UkmService.
37 // Calling code is responsible for ensuring that the lifetime of 39 // Calling code is responsible for ensuring that the lifetime of
38 // |pref_service| is longer than the lifetime of UkmService. 40 // |pref_service| is longer than the lifetime of UkmService.
39 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); 41 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client);
40 virtual ~UkmService(); 42 virtual ~UkmService();
41 43
42 // Initializes the UKM service. 44 // Initializes the UKM service.
43 void Initialize(); 45 void Initialize();
44 46
45 // Enable/disable transmission of accumulated logs. Logs that have already 47 // Enable/disable transmission of accumulated logs. Logs that have already
46 // been created will remain persisted to disk. 48 // been created will remain persisted to disk.
47 void EnableReporting(); 49 void EnableReporting();
48 void DisableReporting(); 50 void DisableReporting();
49 51
52 void RecordSource(std::unique_ptr<UkmSource> source);
53
50 // Record any collected data into logs, and write to disk. 54 // Record any collected data into logs, and write to disk.
51 void Flush(); 55 void Flush();
52 56
53 // Delete any unsent local data. 57 // Delete any unsent local data.
54 void Purge(); 58 void Purge();
55 59
56 // Registers the names of all of the preferences used by UkmService in 60 // Registers the names of all of the preferences used by UkmService in
57 // the provided PrefRegistry. 61 // the provided PrefRegistry.
58 static void RegisterPrefs(PrefRegistrySimple* registry); 62 static void RegisterPrefs(PrefRegistrySimple* registry);
59 63
64 protected:
65 const std::vector<std::unique_ptr<UkmSource>>& sources_for_testing() const {
66 return sources_;
67 }
68
60 private: 69 private:
61 // Start metrics client initialization. 70 // Start metrics client initialization.
62 void StartInitTask(); 71 void StartInitTask();
63 72
64 // Called when initialization tasks are complete, to notify the scheduler 73 // Called when initialization tasks are complete, to notify the scheduler
65 // that it can begin calling RotateLog. 74 // that it can begin calling RotateLog.
66 void FinishedInitTask(); 75 void FinishedInitTask();
67 76
68 // Periodically called by scheduler_ to advance processing of logs. 77 // Periodically called by scheduler_ to advance processing of logs.
69 void RotateLog(); 78 void RotateLog();
(...skipping 26 matching lines...) Expand all
96 105
97 base::ThreadChecker thread_checker_; 106 base::ThreadChecker thread_checker_;
98 107
99 // Instance of the helper class for uploading logs. 108 // Instance of the helper class for uploading logs.
100 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; 109 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_;
101 110
102 bool initialize_started_; 111 bool initialize_started_;
103 bool initialize_complete_; 112 bool initialize_complete_;
104 bool log_upload_in_progress_; 113 bool log_upload_in_progress_;
105 114
115 std::vector<std::unique_ptr<UkmSource>> sources_;
116
106 // Weak pointers factory used to post task on different threads. All weak 117 // Weak pointers factory used to post task on different threads. All weak
107 // pointers managed by this factory have the same lifetime as UkmService. 118 // pointers managed by this factory have the same lifetime as UkmService.
108 base::WeakPtrFactory<UkmService> self_ptr_factory_; 119 base::WeakPtrFactory<UkmService> self_ptr_factory_;
109 120
110 DISALLOW_COPY_AND_ASSIGN(UkmService); 121 DISALLOW_COPY_AND_ASSIGN(UkmService);
111 }; 122 };
112 123
113 } // namespace ukm 124 } // namespace ukm
114 125
115 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ 126 #endif // COMPONENTS_UKM_UKM_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698