| 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 29 matching lines...) Expand all Loading... |
| 40 public: | 40 public: |
| 41 // Constructs a UkmService. | 41 // Constructs a UkmService. |
| 42 // Calling code is responsible for ensuring that the lifetime of | 42 // Calling code is responsible for ensuring that the lifetime of |
| 43 // |pref_service| is longer than the lifetime of UkmService. | 43 // |pref_service| is longer than the lifetime of UkmService. |
| 44 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); | 44 UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client); |
| 45 virtual ~UkmService(); | 45 virtual ~UkmService(); |
| 46 | 46 |
| 47 // Initializes the UKM service. | 47 // Initializes the UKM service. |
| 48 void Initialize(); | 48 void Initialize(); |
| 49 | 49 |
| 50 // Enables/disables recording control if data is allowed to be collected. |
| 51 void EnableRecording(); |
| 52 void DisableRecording(); |
| 53 |
| 50 // Enables/disables transmission of accumulated logs. Logs that have already | 54 // Enables/disables transmission of accumulated logs. Logs that have already |
| 51 // been created will remain persisted to disk. | 55 // been created will remain persisted to disk. |
| 52 void EnableReporting(); | 56 void EnableReporting(); |
| 53 void DisableReporting(); | 57 void DisableReporting(); |
| 54 | 58 |
| 55 // Adds a new source of UKM metrics, which will be stored | 59 // Adds a new source of UKM metrics, which will be stored |
| 56 // until periodically serialized for upload, and then deleted. | 60 // until periodically serialized for upload, and then deleted. |
| 57 void RecordSource(std::unique_ptr<UkmSource> source); | 61 void RecordSource(std::unique_ptr<UkmSource> source); |
| 58 | 62 |
| 59 // Records any collected data into logs, and writes to disk. | 63 // Records any collected data into logs, and writes to disk. |
| 60 void Flush(); | 64 void Flush(); |
| 61 | 65 |
| 62 // Deletes any unsent local data. | 66 // Deletes any unsent local data. |
| 63 void Purge(); | 67 void Purge(); |
| 64 | 68 |
| 69 // Resets the client id stored in prefs. |
| 70 void ResetClientId(); |
| 71 |
| 65 // Registers the specified |provider| to provide additional metrics into the | 72 // Registers the specified |provider| to provide additional metrics into the |
| 66 // UKM log. Should be called during MetricsService initialization only. | 73 // UKM log. Should be called during MetricsService initialization only. |
| 67 void RegisterMetricsProvider( | 74 void RegisterMetricsProvider( |
| 68 std::unique_ptr<metrics::MetricsProvider> provider); | 75 std::unique_ptr<metrics::MetricsProvider> provider); |
| 69 | 76 |
| 70 // Registers the names of all of the preferences used by UkmService in | 77 // Registers the names of all of the preferences used by UkmService in |
| 71 // the provided PrefRegistry. | 78 // the provided PrefRegistry. |
| 72 static void RegisterPrefs(PrefRegistrySimple* registry); | 79 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 73 | 80 |
| 74 protected: | 81 protected: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 | 100 |
| 94 // Starts an upload of the next log from persisted_logs_. | 101 // Starts an upload of the next log from persisted_logs_. |
| 95 void StartScheduledUpload(); | 102 void StartScheduledUpload(); |
| 96 | 103 |
| 97 // Called by log_uploader_ when the an upload is completed. | 104 // Called by log_uploader_ when the an upload is completed. |
| 98 void OnLogUploadComplete(int response_code); | 105 void OnLogUploadComplete(int response_code); |
| 99 | 106 |
| 100 // A weak pointer to the PrefService used to read and write preferences. | 107 // A weak pointer to the PrefService used to read and write preferences. |
| 101 PrefService* pref_service_; | 108 PrefService* pref_service_; |
| 102 | 109 |
| 110 // Whether recording new data is currently allowed. |
| 111 bool recording_enabled_; |
| 112 |
| 103 // The UKM client id stored in prefs. | 113 // The UKM client id stored in prefs. |
| 104 uint64_t client_id_; | 114 uint64_t client_id_; |
| 105 | 115 |
| 106 // Used to interact with the embedder. Weak pointer; must outlive |this| | 116 // Used to interact with the embedder. Weak pointer; must outlive |this| |
| 107 // instance. | 117 // instance. |
| 108 metrics::MetricsServiceClient* const client_; | 118 metrics::MetricsServiceClient* const client_; |
| 109 | 119 |
| 110 // Registered metrics providers. | 120 // Registered metrics providers. |
| 111 std::vector<std::unique_ptr<metrics::MetricsProvider>> metrics_providers_; | 121 std::vector<std::unique_ptr<metrics::MetricsProvider>> metrics_providers_; |
| 112 | 122 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 132 // Weak pointers factory used to post task on different threads. All weak | 142 // Weak pointers factory used to post task on different threads. All weak |
| 133 // pointers managed by this factory have the same lifetime as UkmService. | 143 // pointers managed by this factory have the same lifetime as UkmService. |
| 134 base::WeakPtrFactory<UkmService> self_ptr_factory_; | 144 base::WeakPtrFactory<UkmService> self_ptr_factory_; |
| 135 | 145 |
| 136 DISALLOW_COPY_AND_ASSIGN(UkmService); | 146 DISALLOW_COPY_AND_ASSIGN(UkmService); |
| 137 }; | 147 }; |
| 138 | 148 |
| 139 } // namespace ukm | 149 } // namespace ukm |
| 140 | 150 |
| 141 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | 151 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ |
| OLD | NEW |