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

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

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

Powered by Google App Engine
This is Rietveld 408576698