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 | 10 |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "components/metrics/metrics_reporting_scheduler.h" | 16 #include "components/metrics/metrics_reporting_scheduler.h" |
| 17 #include "components/metrics/persisted_logs.h" | 17 #include "components/metrics/persisted_logs.h" |
| 18 | 18 |
| 19 class PrefRegistrySimple; | 19 class PrefRegistrySimple; |
| 20 class PrefService; | 20 class PrefService; |
| 21 | 21 |
| 22 namespace metrics { | 22 namespace metrics { |
| 23 class MetricsLogUploader; | 23 class MetricsLogUploader; |
| 24 class MetricsServiceClient; | 24 class MetricsServiceClient; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace ukm { | 27 namespace ukm { |
| 28 | 28 |
| 29 class UkmSource; | |
| 30 | |
| 29 // This feature controls whether UkmService should be created. | 31 // This feature controls whether UkmService should be created. |
| 30 extern const base::Feature kUkmFeature; | 32 extern const base::Feature kUkmFeature; |
| 31 | 33 |
| 32 // The Url-Keyed Metrics (UKM) service is responsible for gathering and | 34 // The Url-Keyed Metrics (UKM) service is responsible for gathering and |
| 33 // uploading reports that contain fine grained performance metrics including | 35 // uploading reports that contain fine grained performance metrics including |
| 34 // URLs for top-level navigations. | 36 // URLs for top-level navigations. |
| 35 class UkmService : public base::SupportsWeakPtr<UkmService> { | 37 class UkmService : public base::SupportsWeakPtr<UkmService> { |
| 36 public: | 38 public: |
| 37 // Constructs a UkmService. | 39 // Constructs a UkmService. |
| 38 // Calling code is responsible for ensuring that the lifetime of | 40 // Calling code is responsible for ensuring that the lifetime of |
| 39 // |pref_service| is longer than the lifetime of UkmService. | 41 // |pref_service| is longer than the lifetime of UkmService. |
| 40 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); | 42 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); |
| 41 virtual ~UkmService(); | 43 virtual ~UkmService(); |
| 42 | 44 |
| 43 // Initializes the UKM service. | 45 // Initializes the UKM service. |
| 44 void Initialize(); | 46 void Initialize(); |
| 45 | 47 |
| 46 // Enable/disable transmission of accumulated logs. Logs that have already | 48 // Enable/disable transmission of accumulated logs. Logs that have already |
| 47 // been created will remain persisted to disk. | 49 // been created will remain persisted to disk. |
| 48 void EnableReporting(); | 50 void EnableReporting(); |
| 49 void DisableReporting(); | 51 void DisableReporting(); |
| 50 | 52 |
| 53 void RecordSource(std::unique_ptr<UkmSource> source); | |
|
Alexei Svitkine (slow)
2017/01/25 15:35:04
Add a comment about what this does. Mention the li
oystein (OOO til 10th of July)
2017/01/25 18:38:04
Done.
Alexei Svitkine (slow)
2017/01/25 18:40:44
Not done? I don't see the change.
| |
| 54 | |
| 51 // Record any collected data into logs, and write to disk. | 55 // Record any collected data into logs, and write to disk. |
| 52 void Flush(); | 56 void Flush(); |
| 53 | 57 |
| 54 // Delete any unsent local data. | 58 // Delete any unsent local data. |
| 55 void Purge(); | 59 void Purge(); |
| 56 | 60 |
| 57 // Registers the names of all of the preferences used by UkmService in | 61 // Registers the names of all of the preferences used by UkmService in |
| 58 // the provided PrefRegistry. | 62 // the provided PrefRegistry. |
| 59 static void RegisterPrefs(PrefRegistrySimple* registry); | 63 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 60 | 64 |
| 65 protected: | |
| 66 const std::vector<std::unique_ptr<UkmSource>>& sources_for_testing() const { | |
| 67 return sources_; | |
| 68 } | |
| 69 | |
| 61 private: | 70 private: |
| 62 // Start metrics client initialization. | 71 // Start metrics client initialization. |
| 63 void StartInitTask(); | 72 void StartInitTask(); |
| 64 | 73 |
| 65 // Called when initialization tasks are complete, to notify the scheduler | 74 // Called when initialization tasks are complete, to notify the scheduler |
| 66 // that it can begin calling RotateLog. | 75 // that it can begin calling RotateLog. |
| 67 void FinishedInitTask(); | 76 void FinishedInitTask(); |
| 68 | 77 |
| 69 // Periodically called by scheduler_ to advance processing of logs. | 78 // Periodically called by scheduler_ to advance processing of logs. |
| 70 void RotateLog(); | 79 void RotateLog(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 97 | 106 |
| 98 base::ThreadChecker thread_checker_; | 107 base::ThreadChecker thread_checker_; |
| 99 | 108 |
| 100 // Instance of the helper class for uploading logs. | 109 // Instance of the helper class for uploading logs. |
| 101 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; | 110 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; |
| 102 | 111 |
| 103 bool initialize_started_; | 112 bool initialize_started_; |
| 104 bool initialize_complete_; | 113 bool initialize_complete_; |
| 105 bool log_upload_in_progress_; | 114 bool log_upload_in_progress_; |
| 106 | 115 |
| 116 std::vector<std::unique_ptr<UkmSource>> sources_; | |
| 117 | |
| 107 // Weak pointers factory used to post task on different threads. All weak | 118 // Weak pointers factory used to post task on different threads. All weak |
| 108 // pointers managed by this factory have the same lifetime as UkmService. | 119 // pointers managed by this factory have the same lifetime as UkmService. |
| 109 base::WeakPtrFactory<UkmService> self_ptr_factory_; | 120 base::WeakPtrFactory<UkmService> self_ptr_factory_; |
| 110 | 121 |
| 111 DISALLOW_COPY_AND_ASSIGN(UkmService); | 122 DISALLOW_COPY_AND_ASSIGN(UkmService); |
| 112 }; | 123 }; |
| 113 | 124 |
| 114 } // namespace ukm | 125 } // namespace ukm |
| 115 | 126 |
| 116 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | 127 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ |
| OLD | NEW |