| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_METRICS_METRICS_LOG_MANAGER_H_ | 5 #ifndef COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ |
| 6 #define COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ | 6 #define COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "components/metrics/metrics_log_base.h" | 13 #include "components/metrics/metrics_log.h" |
| 14 #include "components/metrics/persisted_logs.h" | 14 #include "components/metrics/persisted_logs.h" |
| 15 | 15 |
| 16 namespace metrics { | 16 namespace metrics { |
| 17 | 17 |
| 18 // Manages all the log objects used by a MetricsService implementation. Keeps | 18 // Manages all the log objects used by a MetricsService implementation. Keeps |
| 19 // track of both an in progress log and a log that is staged for uploading as | 19 // track of both an in progress log and a log that is staged for uploading as |
| 20 // text, as well as saving logs to, and loading logs from, persistent storage. | 20 // text, as well as saving logs to, and loading logs from, persistent storage. |
| 21 class MetricsLogManager { | 21 class MetricsLogManager { |
| 22 public: | 22 public: |
| 23 typedef MetricsLogBase::LogType LogType; | |
| 24 | |
| 25 // The metrics log manager will persist it's unsent logs by storing them in | 23 // The metrics log manager will persist it's unsent logs by storing them in |
| 26 // |local_state|, and will not persist ongoing logs over | 24 // |local_state|, and will not persist ongoing logs over |
| 27 // |max_ongoing_log_size|. | 25 // |max_ongoing_log_size|. |
| 28 MetricsLogManager(PrefService* local_state, size_t max_ongoing_log_size); | 26 MetricsLogManager(PrefService* local_state, size_t max_ongoing_log_size); |
| 29 ~MetricsLogManager(); | 27 ~MetricsLogManager(); |
| 30 | 28 |
| 31 // Makes |log| the current_log. This should only be called if there is not a | 29 // Makes |log| the current_log. This should only be called if there is not a |
| 32 // current log. | 30 // current log. |
| 33 void BeginLoggingWithLog(scoped_ptr<MetricsLogBase> log); | 31 void BeginLoggingWithLog(scoped_ptr<MetricsLog> log); |
| 34 | 32 |
| 35 // Returns the in-progress log. | 33 // Returns the in-progress log. |
| 36 MetricsLogBase* current_log() { return current_log_.get(); } | 34 MetricsLog* current_log() { return current_log_.get(); } |
| 37 | 35 |
| 38 // Closes current_log(), compresses it, and stores the compressed log for | 36 // Closes current_log(), compresses it, and stores the compressed log for |
| 39 // later, leaving current_log() NULL. | 37 // later, leaving current_log() NULL. |
| 40 void FinishCurrentLog(); | 38 void FinishCurrentLog(); |
| 41 | 39 |
| 42 // Returns true if there are any logs waiting to be uploaded. | 40 // Returns true if there are any logs waiting to be uploaded. |
| 43 bool has_unsent_logs() const { | 41 bool has_unsent_logs() const { |
| 44 return initial_log_queue_.size() || ongoing_log_queue_.size(); | 42 return initial_log_queue_.size() || ongoing_log_queue_.size(); |
| 45 } | 43 } |
| 46 | 44 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Saves any unsent logs to persistent storage. | 101 // Saves any unsent logs to persistent storage. |
| 104 void PersistUnsentLogs(); | 102 void PersistUnsentLogs(); |
| 105 | 103 |
| 106 // Loads any unsent logs from persistent storage. | 104 // Loads any unsent logs from persistent storage. |
| 107 void LoadPersistedUnsentLogs(); | 105 void LoadPersistedUnsentLogs(); |
| 108 | 106 |
| 109 private: | 107 private: |
| 110 // Saves |log| as the given type. | 108 // Saves |log| as the given type. |
| 111 // NOTE: This clears the contents of |log| (to avoid an expensive copy), | 109 // NOTE: This clears the contents of |log| (to avoid an expensive copy), |
| 112 // so the log should be discarded after this call. | 110 // so the log should be discarded after this call. |
| 113 void StoreLog(std::string* log, LogType log_type); | 111 void StoreLog(std::string* log, MetricsLog::LogType log_type); |
| 114 | 112 |
| 115 // Tracks whether unsent logs (if any) have been loaded from the serializer. | 113 // Tracks whether unsent logs (if any) have been loaded from the serializer. |
| 116 bool unsent_logs_loaded_; | 114 bool unsent_logs_loaded_; |
| 117 | 115 |
| 118 // The log that we are still appending to. | 116 // The log that we are still appending to. |
| 119 scoped_ptr<MetricsLogBase> current_log_; | 117 scoped_ptr<MetricsLog> current_log_; |
| 120 | 118 |
| 121 // A paused, previously-current log. | 119 // A paused, previously-current log. |
| 122 scoped_ptr<MetricsLogBase> paused_log_; | 120 scoped_ptr<MetricsLog> paused_log_; |
| 123 | 121 |
| 124 // Logs that have not yet been sent. | 122 // Logs that have not yet been sent. |
| 125 metrics::PersistedLogs initial_log_queue_; | 123 metrics::PersistedLogs initial_log_queue_; |
| 126 metrics::PersistedLogs ongoing_log_queue_; | 124 metrics::PersistedLogs ongoing_log_queue_; |
| 127 | 125 |
| 128 DISALLOW_COPY_AND_ASSIGN(MetricsLogManager); | 126 DISALLOW_COPY_AND_ASSIGN(MetricsLogManager); |
| 129 }; | 127 }; |
| 130 | 128 |
| 131 } // namespace metrics | 129 } // namespace metrics |
| 132 | 130 |
| 133 #endif // COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ | 131 #endif // COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ |
| OLD | NEW |