Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_UKM_UKM_SERVICE_H_ | |
| 6 #define COMPONENTS_UKM_UKM_SERVICE_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/threading/thread_checker.h" | |
| 13 #include "components/metrics/metrics_reporting_scheduler.h" | |
| 14 #include "components/metrics/persisted_logs.h" | |
| 15 | |
| 16 class PrefRegistrySimple; | |
| 17 class PrefService; | |
| 18 | |
| 19 namespace metrics { | |
| 20 class MetricsLogUploader; | |
| 21 class MetricsServiceClient; | |
| 22 } | |
| 23 | |
| 24 namespace ukm { | |
| 25 | |
| 26 // Manages the generation and uploading of UKM reports. | |
| 27 class UkmService : public base::SupportsWeakPtr<UkmService> { | |
| 28 public: | |
| 29 // Constructs a UkmService. | |
| 30 // Calling code is responsible for ensuring that the lifetime of | |
| 31 // |pref_service| is longer than the lifetime of UkmService. | |
| 32 UkmService( | |
| 33 PrefService* pref_service, | |
| 34 metrics::MetricsServiceClient* client); | |
| 35 virtual ~UkmService(); | |
| 36 | |
| 37 // Initializes the UKM service. | |
| 38 void Initialize(); | |
| 39 | |
| 40 // Enable/disable transmission of accumulated logs. | |
|
rkaplow
2017/01/02 23:23:04
it may be worth mentioning what would happen to lo
Steven Holte
2017/01/03 21:16:04
Done.
| |
| 41 void EnableReporting(); | |
| 42 void DisableReporting(); | |
| 43 | |
| 44 // Registers the names of all of the preferences used by UkmService in | |
| 45 // the provided PrefRegistry. | |
| 46 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 47 | |
| 48 private: | |
| 49 // Start metrics client initialization. | |
| 50 void StartInitTask(); | |
| 51 | |
| 52 // Called when initialization tasks are complete. | |
|
rkaplow
2017/01/02 23:23:04
Prefer if this described what this method actually
Steven Holte
2017/01/03 21:16:04
Done.
| |
| 53 void FinishedInitTask(); | |
| 54 | |
| 55 // Periodically called by scheduler_ to advance processing of logs. | |
| 56 void RotateLog(); | |
| 57 | |
| 58 // Constructs a new Report from available data and stores it in | |
| 59 // persisted_logs_. | |
| 60 void BuildAndStoreLog(); | |
| 61 | |
| 62 // Start an upload of the next log from persisted_logs_. | |
| 63 void StartScheduledUpload(); | |
| 64 | |
| 65 // Called by log_uploader_ when the an upload is completed. | |
| 66 void OnLogUploadComplete(int response_code); | |
| 67 | |
| 68 // A weak pointer to the PrefService used to read and write preferences. | |
| 69 PrefService* pref_service_; | |
| 70 | |
| 71 // The UKM client id stored in prefs. | |
| 72 uint64_t client_id_; | |
| 73 | |
| 74 // Used to interact with the embedder. Weak pointer; must outlive |this| | |
| 75 // instance. | |
| 76 metrics::MetricsServiceClient* const client_; | |
| 77 | |
| 78 // Logs that have not yet been sent. | |
| 79 metrics::PersistedLogs persisted_logs_; | |
| 80 | |
| 81 // The scheduler for determining when uploads should happen. | |
| 82 std::unique_ptr<metrics::MetricsReportingScheduler> scheduler_; | |
| 83 | |
| 84 base::ThreadChecker thread_checker_; | |
| 85 | |
| 86 // Instance of the helper class for uploading logs. | |
| 87 std::unique_ptr<metrics::MetricsLogUploader> log_uploader_; | |
| 88 | |
| 89 bool initialize_started_; | |
| 90 bool log_upload_in_progress_; | |
| 91 | |
| 92 // Weak pointers factory used to post task on different threads. All weak | |
| 93 // pointers managed by this factory have the same lifetime as UkmService. | |
| 94 base::WeakPtrFactory<UkmService> self_ptr_factory_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(UkmService); | |
| 97 }; | |
| 98 | |
| 99 } // namespace ukm | |
| 100 | |
| 101 #endif // COMPONENTS_UKM_UKM_SERVICE_H_ | |
| OLD | NEW |