| OLD | NEW |
| 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_SERVICE_H_ | 5 #ifndef COMPONENTS_UKM_UKM_SERVICE_H_ |
| 6 #define COMPONENTS_UKM_UKM_SERVICE_H_ | 6 #define COMPONENTS_UKM_UKM_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void RegisterMetricsProvider( | 92 void RegisterMetricsProvider( |
| 93 std::unique_ptr<metrics::MetricsProvider> provider); | 93 std::unique_ptr<metrics::MetricsProvider> provider); |
| 94 | 94 |
| 95 // Registers the names of all of the preferences used by UkmService in | 95 // Registers the names of all of the preferences used by UkmService in |
| 96 // the provided PrefRegistry. | 96 // the provided PrefRegistry. |
| 97 static void RegisterPrefs(PrefRegistrySimple* registry); | 97 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 98 | 98 |
| 99 using AddEntryCallback = base::Callback<void(std::unique_ptr<UkmEntry>)>; | 99 using AddEntryCallback = base::Callback<void(std::unique_ptr<UkmEntry>)>; |
| 100 | 100 |
| 101 protected: | 101 protected: |
| 102 const std::vector<std::unique_ptr<UkmSource>>& sources_for_testing() const { | 102 const std::map<int32_t, std::unique_ptr<UkmSource>>& sources_for_testing() |
| 103 const { |
| 103 return sources_; | 104 return sources_; |
| 104 } | 105 } |
| 105 | 106 |
| 106 const std::vector<std::unique_ptr<UkmEntry>>& entries_for_testing() const { | 107 const std::vector<std::unique_ptr<UkmEntry>>& entries_for_testing() const { |
| 107 return entries_; | 108 return entries_; |
| 108 } | 109 } |
| 109 | 110 |
| 110 private: | 111 private: |
| 111 friend UkmPageLoadMetricsObserver; | 112 friend UkmPageLoadMetricsObserver; |
| 112 friend autofill::AutofillMetrics; | 113 friend autofill::AutofillMetrics; |
| 113 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryOnlyWithNonEmptyMetrics); | 114 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryOnlyWithNonEmptyMetrics); |
| 114 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization); | 115 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization); |
| 115 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, | 116 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, |
| 116 LogsUploadedOnlyWhenHavingSourcesOrEntries); | 117 LogsUploadedOnlyWhenHavingSourcesOrEntries); |
| 117 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, MetricsProviderTest); | 118 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, MetricsProviderTest); |
| 118 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, PersistAndPurge); | 119 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, PersistAndPurge); |
| 119 | 120 |
| 120 // Get a new UkmEntryBuilder object for the specified source ID and event, | 121 // Get a new UkmEntryBuilder object for the specified source ID and event, |
| 121 // which can get metrics added to. | 122 // which can get metrics added to. |
| 122 // | 123 // |
| 123 // This API being private is intentional. Any client using UKM needs to | 124 // This API being private is intentional. Any client using UKM needs to |
| 124 // declare itself to be a friend of UkmService and go through code review | 125 // declare itself to be a friend of UkmService and go through code review |
| 125 // process. | 126 // process. |
| 126 std::unique_ptr<UkmEntryBuilder> GetEntryBuilder(int32_t source_id, | 127 std::unique_ptr<UkmEntryBuilder> GetEntryBuilder(int32_t source_id, |
| 127 const char* event_name); | 128 const char* event_name); |
| 128 | 129 |
| 129 // Adds a new source of UKM metrics, which will be stored until periodically | |
| 130 // serialized for upload, and then deleted. This method is deprecated. Please | |
| 131 // use GetEntryBuilder and UpdateSourceURL above. | |
| 132 void RecordSource(std::unique_ptr<UkmSource> source); | |
| 133 | |
| 134 // Starts metrics client initialization. | 130 // Starts metrics client initialization. |
| 135 void StartInitTask(); | 131 void StartInitTask(); |
| 136 | 132 |
| 137 // Called when initialization tasks are complete, to notify the scheduler | 133 // Called when initialization tasks are complete, to notify the scheduler |
| 138 // that it can begin calling RotateLog. | 134 // that it can begin calling RotateLog. |
| 139 void FinishedInitTask(); | 135 void FinishedInitTask(); |
| 140 | 136 |
| 141 // Periodically called by scheduler_ to advance processing of logs. | 137 // Periodically called by scheduler_ to advance processing of logs. |
| 142 void RotateLog(); | 138 void RotateLog(); |
| 143 | 139 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 179 |
| 184 // Instance of the helper class for uploading logs. | 180 // Instance of the helper class for uploading logs. |
| 185 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; | 181 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; |
| 186 | 182 |
| 187 bool initialize_started_; | 183 bool initialize_started_; |
| 188 bool initialize_complete_; | 184 bool initialize_complete_; |
| 189 bool log_upload_in_progress_; | 185 bool log_upload_in_progress_; |
| 190 | 186 |
| 191 // Contains newly added sources and entries of UKM metrics which periodically | 187 // Contains newly added sources and entries of UKM metrics which periodically |
| 192 // get serialized and cleared by BuildAndStoreLog(). | 188 // get serialized and cleared by BuildAndStoreLog(). |
| 193 // TODO(zhenw): update sources to a map keyed by source ID. | 189 std::map<int32_t, std::unique_ptr<UkmSource>> sources_; |
| 194 std::vector<std::unique_ptr<UkmSource>> sources_; | |
| 195 std::vector<std::unique_ptr<UkmEntry>> entries_; | 190 std::vector<std::unique_ptr<UkmEntry>> entries_; |
| 196 | 191 |
| 197 // Weak pointers factory used to post task on different threads. All weak | 192 // Weak pointers factory used to post task on different threads. All weak |
| 198 // pointers managed by this factory have the same lifetime as UkmService. | 193 // pointers managed by this factory have the same lifetime as UkmService. |
| 199 base::WeakPtrFactory<UkmService> self_ptr_factory_; | 194 base::WeakPtrFactory<UkmService> self_ptr_factory_; |
| 200 | 195 |
| 201 DISALLOW_COPY_AND_ASSIGN(UkmService); | 196 DISALLOW_COPY_AND_ASSIGN(UkmService); |
| 202 }; | 197 }; |
| 203 | 198 |
| 204 } // namespace ukm | 199 } // namespace ukm |
| 205 | 200 |
| 206 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | 201 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ |
| OLD | NEW |