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_PUBLIC_UKM_RECORDER_H_ |
| 6 #define COMPONENTS_UKM_PUBLIC_UKM_RECORDER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/feature_list.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "components/ukm/public/interfaces/ukm_interface.mojom.h" |
| 15 #include "components/ukm/public/ukm_entry_builder.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 class ContextualSearchRankerLoggerImpl; |
| 19 class PluginInfoMessageFilter; |
| 20 class UkmPageLoadMetricsObserver; |
| 21 |
| 22 namespace autofill { |
| 23 class AutofillMetrics; |
| 24 } |
| 25 |
| 26 namespace content { |
| 27 class RenderFrameImpl; |
| 28 } |
| 29 |
| 30 namespace translate { |
| 31 class TranslateRankerImpl; |
| 32 } |
| 33 |
| 34 namespace payments { |
| 35 class JourneyLogger; |
| 36 } |
| 37 |
| 38 namespace ukm { |
| 39 |
| 40 class UkmEntryBuilder; |
| 41 class UkmInterface; |
| 42 class TestRecordingHelper; |
| 43 |
| 44 // This feature controls whether UkmService should be created. |
| 45 extern const base::Feature kUkmFeature; |
| 46 |
| 47 typedef int64_t SourceId; |
| 48 |
| 49 // Interface for recording UKM |
| 50 class UkmRecorder { |
| 51 public: |
| 52 UkmRecorder(); |
| 53 virtual ~UkmRecorder(); |
| 54 |
| 55 // Get the new source ID, which is unique for the duration of a browser |
| 56 // session. |
| 57 static SourceId GetNewSourceID(); |
| 58 |
| 59 // Update the URL on the source keyed to the given source ID. If the source |
| 60 // does not exist, it will create a new UkmSource object. |
| 61 virtual void UpdateSourceURL(SourceId source_id, const GURL& url) = 0; |
| 62 |
| 63 private: |
| 64 friend autofill::AutofillMetrics; |
| 65 friend payments::JourneyLogger; |
| 66 friend ContextualSearchRankerLoggerImpl; |
| 67 friend PluginInfoMessageFilter; |
| 68 friend UkmPageLoadMetricsObserver; |
| 69 friend translate::TranslateRankerImpl; |
| 70 friend TestRecordingHelper; |
| 71 friend UkmInterface; |
| 72 friend content::RenderFrameImpl; |
| 73 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryWithEmptyMetrics); |
| 74 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization); |
| 75 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, |
| 76 LogsUploadedOnlyWhenHavingSourcesOrEntries); |
| 77 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, MetricsProviderTest); |
| 78 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, PersistAndPurge); |
| 79 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, WhitelistEntryTest); |
| 80 |
| 81 // Get a new UkmEntryBuilder object for the specified source ID and event, |
| 82 // which can get metrics added to. |
| 83 // |
| 84 // This API being private is intentional. Any client using UKM needs to |
| 85 // declare itself to be a friend of UkmService and go through code review |
| 86 // process. |
| 87 std::unique_ptr<UkmEntryBuilder> GetEntryBuilder(SourceId source_id, |
| 88 const char* event_name); |
| 89 |
| 90 private: |
| 91 // Add an entry to the UkmEntry list. |
| 92 virtual void AddEntry(mojom::UkmEntryPtr entry) = 0; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(UkmRecorder); |
| 95 }; |
| 96 |
| 97 } // namespace ukm |
| 98 |
| 99 #endif // COMPONENTS_UKM_PUBLIC_UKM_RECORDER_H_ |
OLD | NEW |