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