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

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

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

Powered by Google App Engine
This is Rietveld 408576698