| OLD | NEW |
| (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_ENTRY_BUILDER_H | |
| 6 #define COMPONENTS_UKM_UKM_ENTRY_BUILDER_H | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "components/ukm/ukm_service.h" | |
| 12 | |
| 13 namespace ukm { | |
| 14 | |
| 15 class UkmEntry; | |
| 16 class UkmService; | |
| 17 | |
| 18 // The builder that builds UkmEntry and adds it to UkmService. | |
| 19 // The example usage is: | |
| 20 // | |
| 21 // { | |
| 22 // unique_ptr<UkmEntryBuilder> builder = | |
| 23 // ukm_service->GetEntryBuilder(source_id, "PageLoad"); | |
| 24 // builder->AddMetric("NavigationStart", navigation_start_time); | |
| 25 // builder->AddMetric("ResponseStart", response_start_time); | |
| 26 // builder->AddMetric("FirstPaint", first_paint_time); | |
| 27 // builder->AddMetric("FirstContentfulPaint", fcp_time); | |
| 28 // } | |
| 29 // | |
| 30 // When there exists an added metric, the builder will automatically add the | |
| 31 // UkmEntry to UkmService upon destruction when going out of scope. | |
| 32 class UkmEntryBuilder { | |
| 33 public: | |
| 34 // Add metric to the entry. A metric contains a metric name and value. | |
| 35 void AddMetric(const char* metric_name, int64_t value); | |
| 36 | |
| 37 ~UkmEntryBuilder(); | |
| 38 | |
| 39 private: | |
| 40 friend class UkmService; | |
| 41 | |
| 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 | |
| 49 DISALLOW_COPY_AND_ASSIGN(UkmEntryBuilder); | |
| 50 }; | |
| 51 | |
| 52 } // namespace ukm | |
| 53 | |
| 54 #endif // COMPONENTS_UKM_UKM_ENTRY_BUILDER_H | |
| OLD | NEW |