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

Side by Side Diff: components/ukm/public/ukm_entry_builder.h

Issue 2883563002: Refactor UKM interface for mojo-ification (Closed)
Patch Set: Fix uma_session_stats.cc Created 3 years, 7 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_ENTRY_BUILDER_H 5 #ifndef COMPONENTS_UKM_UKM_ENTRY_BUILDER_H
6 #define COMPONENTS_UKM_UKM_ENTRY_BUILDER_H 6 #define COMPONENTS_UKM_UKM_ENTRY_BUILDER_H
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "components/ukm/ukm_service.h" 11 #include "components/ukm/public/interfaces/ukm_interface.mojom.h"
12 12
13 namespace ukm { 13 namespace ukm {
14 14
15 class UkmEntry; 15 typedef int64_t SourceId;
16 class UkmService;
17 16
18 // The builder that builds UkmEntry and adds it to UkmService. 17 // The builder that builds UkmEntry and adds it to UkmRecorder.
19 // The example usage is: 18 // The example usage is:
20 // 19 //
21 // { 20 // {
22 // unique_ptr<UkmEntryBuilder> builder = 21 // unique_ptr<UkmEntryBuilder> builder =
23 // ukm_service->GetEntryBuilder(source_id, "PageLoad"); 22 // ukm_recorder->GetEntryBuilder(source_id, "PageLoad");
24 // builder->AddMetric("NavigationStart", navigation_start_time); 23 // builder->AddMetric("NavigationStart", navigation_start_time);
25 // builder->AddMetric("ResponseStart", response_start_time); 24 // builder->AddMetric("ResponseStart", response_start_time);
26 // builder->AddMetric("FirstPaint", first_paint_time); 25 // builder->AddMetric("FirstPaint", first_paint_time);
27 // builder->AddMetric("FirstContentfulPaint", fcp_time); 26 // builder->AddMetric("FirstContentfulPaint", fcp_time);
28 // } 27 // }
29 // 28 //
30 // When there exists an added metric, the builder will automatically add the 29 // When there exists an added metric, the builder will automatically add the
31 // UkmEntry to UkmService upon destruction when going out of scope. 30 // UkmEntry to UkmService upon destruction when going out of scope.
32 class UkmEntryBuilder { 31 class UkmEntryBuilder {
33 public: 32 public:
33 using AddEntryCallback = base::Callback<void(mojom::UkmEntryPtr)>;
34 UkmEntryBuilder(const AddEntryCallback& callback,
35 ukm::SourceId source_id,
36 const char* event_name);
37 ~UkmEntryBuilder();
38
34 // Add metric to the entry. A metric contains a metric name and value. 39 // Add metric to the entry. A metric contains a metric name and value.
35 void AddMetric(const char* metric_name, int64_t value); 40 void AddMetric(const char* metric_name, int64_t value);
36 41
37 ~UkmEntryBuilder();
38
39 private: 42 private:
40 friend class UkmService; 43 AddEntryCallback add_entry_callback_;
41 44 mojom::UkmEntryPtr entry_;
42 UkmEntryBuilder(const UkmService::AddEntryCallback& callback,
43 int32_t source_id,
44 const char* event_name);
45
46 UkmService::AddEntryCallback add_entry_callback_;
47 std::unique_ptr<UkmEntry> entry_;
48 45
49 DISALLOW_COPY_AND_ASSIGN(UkmEntryBuilder); 46 DISALLOW_COPY_AND_ASSIGN(UkmEntryBuilder);
50 }; 47 };
51 48
52 } // namespace ukm 49 } // namespace ukm
53 50
54 #endif // COMPONENTS_UKM_UKM_ENTRY_BUILDER_H 51 #endif // COMPONENTS_UKM_UKM_ENTRY_BUILDER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698