Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "components/metrics/metrics_provider.h" | 18 #include "components/metrics/metrics_provider.h" |
| 19 #include "components/metrics/metrics_reporting_scheduler.h" | 19 #include "components/metrics/metrics_reporting_scheduler.h" |
| 20 #include "components/metrics/persisted_logs.h" | 20 #include "components/metrics/persisted_logs.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 class PluginInfoMessageFilter; | |
| 23 class PrefRegistrySimple; | 24 class PrefRegistrySimple; |
| 24 class PrefService; | 25 class PrefService; |
| 25 class UkmPageLoadMetricsObserver; | 26 class UkmPageLoadMetricsObserver; |
| 26 | 27 |
| 27 namespace autofill { | 28 namespace autofill { |
| 28 class AutofillMetrics; | 29 class AutofillMetrics; |
| 29 } // namespace autofill | 30 } // namespace autofill |
| 30 | 31 |
| 31 namespace metrics { | 32 namespace metrics { |
| 32 class MetricsLogUploader; | 33 class MetricsLogUploader; |
| 33 class MetricsServiceClient; | 34 class MetricsServiceClient; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace ukm { | 37 namespace ukm { |
| 37 | 38 |
| 38 class UkmEntry; | 39 class UkmEntry; |
| 39 class UkmEntryBuilder; | 40 class UkmEntryBuilder; |
| 40 class UkmSource; | 41 class UkmSource; |
| 41 | 42 |
| 42 // This feature controls whether UkmService should be created. | 43 // This feature controls whether UkmService should be created. |
| 43 extern const base::Feature kUkmFeature; | 44 extern const base::Feature kUkmFeature; |
| 44 | 45 |
| 45 // The URL-Keyed Metrics (UKM) service is responsible for gathering and | 46 // The URL-Keyed Metrics (UKM) service is responsible for gathering and |
| 46 // uploading reports that contain fine grained performance metrics including | 47 // uploading reports that contain fine grained performance metrics including |
| 47 // URLs for top-level navigations. | 48 // URLs for top-level navigations. |
| 48 class UkmService : public base::SupportsWeakPtr<UkmService> { | 49 class UkmService : public base::SupportsWeakPtr<UkmService> { |
|
Bernhard Bauer
2017/03/27 11:04:43
Yak-shaving: Is this actually used? For internal c
tommycli
2017/03/28 17:20:49
Done.
| |
| 49 public: | 50 public: |
| 50 // Constructs a UkmService. | 51 // Constructs a UkmService. |
| 51 // Calling code is responsible for ensuring that the lifetime of | 52 // Calling code is responsible for ensuring that the lifetime of |
| 52 // |pref_service| is longer than the lifetime of UkmService. | 53 // |pref_service| is longer than the lifetime of UkmService. |
| 53 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); | 54 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); |
| 54 virtual ~UkmService(); | 55 virtual ~UkmService(); |
| 55 | 56 |
| 56 // Get the new source ID, which is unique for the duration of a browser | 57 // Get the new source ID, which is unique for the duration of a browser |
| 57 // session. | 58 // session. |
| 58 static int32_t GetNewSourceID(); | 59 static int32_t GetNewSourceID(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 const std::map<int32_t, std::unique_ptr<UkmSource>>& sources_for_testing() | 103 const std::map<int32_t, std::unique_ptr<UkmSource>>& sources_for_testing() |
| 103 const { | 104 const { |
| 104 return sources_; | 105 return sources_; |
| 105 } | 106 } |
| 106 | 107 |
| 107 const std::vector<std::unique_ptr<UkmEntry>>& entries_for_testing() const { | 108 const std::vector<std::unique_ptr<UkmEntry>>& entries_for_testing() const { |
| 108 return entries_; | 109 return entries_; |
| 109 } | 110 } |
| 110 | 111 |
| 111 private: | 112 private: |
| 113 friend autofill::AutofillMetrics; | |
| 114 friend PluginInfoMessageFilter; | |
| 112 friend UkmPageLoadMetricsObserver; | 115 friend UkmPageLoadMetricsObserver; |
| 113 friend autofill::AutofillMetrics; | |
| 114 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryOnlyWithNonEmptyMetrics); | 116 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, AddEntryOnlyWithNonEmptyMetrics); |
| 115 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization); | 117 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, EntryBuilderAndSerialization); |
| 116 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, | 118 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, |
| 117 LogsUploadedOnlyWhenHavingSourcesOrEntries); | 119 LogsUploadedOnlyWhenHavingSourcesOrEntries); |
| 118 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, MetricsProviderTest); | 120 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, MetricsProviderTest); |
| 119 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, PersistAndPurge); | 121 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, PersistAndPurge); |
| 120 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, WhitelistEntryTest); | 122 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, WhitelistEntryTest); |
| 121 | 123 |
| 122 // Get a new UkmEntryBuilder object for the specified source ID and event, | 124 // Get a new UkmEntryBuilder object for the specified source ID and event, |
| 123 // which can get metrics added to. | 125 // which can get metrics added to. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // Weak pointers factory used to post task on different threads. All weak | 201 // Weak pointers factory used to post task on different threads. All weak |
| 200 // pointers managed by this factory have the same lifetime as UkmService. | 202 // pointers managed by this factory have the same lifetime as UkmService. |
| 201 base::WeakPtrFactory<UkmService> self_ptr_factory_; | 203 base::WeakPtrFactory<UkmService> self_ptr_factory_; |
| 202 | 204 |
| 203 DISALLOW_COPY_AND_ASSIGN(UkmService); | 205 DISALLOW_COPY_AND_ASSIGN(UkmService); |
| 204 }; | 206 }; |
| 205 | 207 |
| 206 } // namespace ukm | 208 } // namespace ukm |
| 207 | 209 |
| 208 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | 210 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ |
| OLD | NEW |