| 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 #include "components/metrics/proto/ukm/report.pb.h" |
| 18 | 19 |
| 19 class PrefRegistrySimple; | 20 class PrefRegistrySimple; |
| 20 class PrefService; | 21 class PrefService; |
| 21 | 22 |
| 22 namespace metrics { | 23 namespace metrics { |
| 23 class MetricsLogUploader; | 24 class MetricsLogUploader; |
| 24 class MetricsServiceClient; | 25 class MetricsServiceClient; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace ukm { | 28 namespace ukm { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 void Flush(); | 53 void Flush(); |
| 53 | 54 |
| 54 // Delete any unsent local data. | 55 // Delete any unsent local data. |
| 55 void Purge(); | 56 void Purge(); |
| 56 | 57 |
| 57 // Registers the names of all of the preferences used by UkmService in | 58 // Registers the names of all of the preferences used by UkmService in |
| 58 // the provided PrefRegistry. | 59 // the provided PrefRegistry. |
| 59 static void RegisterPrefs(PrefRegistrySimple* registry); | 60 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 60 | 61 |
| 61 private: | 62 private: |
| 63 FRIEND_TEST_ALL_PREFIXES(UkmServiceTest, PopulateSystemProfile); |
| 64 |
| 62 // Start metrics client initialization. | 65 // Start metrics client initialization. |
| 63 void StartInitTask(); | 66 void StartInitTask(); |
| 64 | 67 |
| 65 // Called when initialization tasks are complete, to notify the scheduler | 68 // Called when initialization tasks are complete, to notify the scheduler |
| 66 // that it can begin calling RotateLog. | 69 // that it can begin calling RotateLog. |
| 67 void FinishedInitTask(); | 70 void FinishedInitTask(); |
| 68 | 71 |
| 69 // Periodically called by scheduler_ to advance processing of logs. | 72 // Periodically called by scheduler_ to advance processing of logs. |
| 70 void RotateLog(); | 73 void RotateLog(); |
| 71 | 74 |
| 72 // Constructs a new Report from available data and stores it in | 75 // Constructs a new Report from available data and stores it in |
| 73 // persisted_logs_. | 76 // persisted_logs_. |
| 74 void BuildAndStoreLog(); | 77 void BuildAndStoreLog(); |
| 75 | 78 |
| 76 // Start an upload of the next log from persisted_logs_. | 79 // Start an upload of the next log from persisted_logs_. |
| 77 void StartScheduledUpload(); | 80 void StartScheduledUpload(); |
| 78 | 81 |
| 79 // Called by log_uploader_ when the an upload is completed. | 82 // Called by log_uploader_ when the an upload is completed. |
| 80 void OnLogUploadComplete(int response_code); | 83 void OnLogUploadComplete(int response_code); |
| 81 | 84 |
| 85 // Populate system information (version, channel, etc.) in the Report. |
| 86 void PopulateSystemProfile(Report* report); |
| 87 |
| 82 // A weak pointer to the PrefService used to read and write preferences. | 88 // A weak pointer to the PrefService used to read and write preferences. |
| 83 PrefService* pref_service_; | 89 PrefService* pref_service_; |
| 84 | 90 |
| 85 // The UKM client id stored in prefs. | 91 // The UKM client id stored in prefs. |
| 86 uint64_t client_id_; | 92 uint64_t client_id_; |
| 87 | 93 |
| 88 // Used to interact with the embedder. Weak pointer; must outlive |this| | 94 // Used to interact with the embedder. Weak pointer; must outlive |this| |
| 89 // instance. | 95 // instance. |
| 90 metrics::MetricsServiceClient* const client_; | 96 metrics::MetricsServiceClient* const client_; |
| 91 | 97 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 // Weak pointers factory used to post task on different threads. All weak | 113 // Weak pointers factory used to post task on different threads. All weak |
| 108 // pointers managed by this factory have the same lifetime as UkmService. | 114 // pointers managed by this factory have the same lifetime as UkmService. |
| 109 base::WeakPtrFactory<UkmService> self_ptr_factory_; | 115 base::WeakPtrFactory<UkmService> self_ptr_factory_; |
| 110 | 116 |
| 111 DISALLOW_COPY_AND_ASSIGN(UkmService); | 117 DISALLOW_COPY_AND_ASSIGN(UkmService); |
| 112 }; | 118 }; |
| 113 | 119 |
| 114 } // namespace ukm | 120 } // namespace ukm |
| 115 | 121 |
| 116 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | 122 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ |
| OLD | NEW |