OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import <UIKit/UIKit.h> | 5 #import <UIKit/UIKit.h> |
6 | 6 |
7 #import "ios/chrome/today_extension/today_metrics_logger.h" | 7 #import "ios/chrome/today_extension/today_metrics_logger.h" |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/cpu.h" | 10 #include "base/cpu.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 // User default key to keep track of the current log session ID. Increased every | 40 // User default key to keep track of the current log session ID. Increased every |
41 // time a log is created. This ID must be offset using | 41 // time a log is created. This ID must be offset using |
42 // app_group::AppGroupSessionID. | 42 // app_group::AppGroupSessionID. |
43 NSString* const kTodayExtensionMetricsSessionID = @"MetricsSessionID"; | 43 NSString* const kTodayExtensionMetricsSessionID = @"MetricsSessionID"; |
44 | 44 |
45 // User default key to the current log serialized. In case of an extension | 45 // User default key to the current log serialized. In case of an extension |
46 // restart, this log can be written to disk for upload. | 46 // restart, this log can be written to disk for upload. |
47 NSString* const kTodayExtensionMetricsCurrentLog = @"MetricsCurrentLog"; | 47 NSString* const kTodayExtensionMetricsCurrentLog = @"MetricsCurrentLog"; |
48 | 48 |
49 // Maximum number of event in a log. | |
50 const int kMaxEventsPerLog = 1000; | |
51 | |
52 // Maximum age of a log. | 49 // Maximum age of a log. |
53 const int kMaxLogLifeTimeInSeconds = 86400; | 50 const int kMaxLogLifeTimeInSeconds = 86400; |
54 | 51 |
55 // A simple implementation of metrics::MetricsServiceClient. | 52 // A simple implementation of metrics::MetricsServiceClient. |
56 // As logs are uploaded by Chrome application, not all methods are needed. | 53 // As logs are uploaded by Chrome application, not all methods are needed. |
57 // Only the method needed to initialize the metrics logs are implementsd. | 54 // Only the method needed to initialize the metrics logs are implementsd. |
58 class TodayMetricsServiceClient : public metrics::MetricsServiceClient { | 55 class TodayMetricsServiceClient : public metrics::MetricsServiceClient { |
59 public: | 56 public: |
60 TodayMetricsServiceClient() {} | 57 TodayMetricsServiceClient() {} |
61 metrics::MetricsService* GetMetricsService() override; | 58 metrics::MetricsService* GetMetricsService() override; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 histogram_snapshot_manager_.PrepareDeltas( | 197 histogram_snapshot_manager_.PrepareDeltas( |
201 base::StatisticsRecorder::begin(false), base::StatisticsRecorder::end(), | 198 base::StatisticsRecorder::begin(false), base::StatisticsRecorder::end(), |
202 base::Histogram::kNoFlags, base::Histogram::kNoFlags); | 199 base::Histogram::kNoFlags, base::Histogram::kNoFlags); |
203 std::string encoded_log; | 200 std::string encoded_log; |
204 log_->GetOpenEncodedLog(&encoded_log); | 201 log_->GetOpenEncodedLog(&encoded_log); |
205 NSData* ns_encoded_log = | 202 NSData* ns_encoded_log = |
206 [NSData dataWithBytes:encoded_log.c_str() length:encoded_log.length()]; | 203 [NSData dataWithBytes:encoded_log.c_str() length:encoded_log.length()]; |
207 [[NSUserDefaults standardUserDefaults] | 204 [[NSUserDefaults standardUserDefaults] |
208 setObject:ns_encoded_log | 205 setObject:ns_encoded_log |
209 forKey:kTodayExtensionMetricsCurrentLog]; | 206 forKey:kTodayExtensionMetricsCurrentLog]; |
210 if (log_->num_events() >= kMaxEventsPerLog || | 207 log_->TruncateEvents(); |
211 (base::TimeTicks::Now() - log_->creation_time()).InSeconds() >= | 208 if ((base::TimeTicks::Now() - log_->creation_time()).InSeconds() >= |
212 kMaxLogLifeTimeInSeconds) { | 209 kMaxLogLifeTimeInSeconds) { |
213 CreateNewLog(); | 210 CreateNewLog(); |
214 } | 211 } |
215 } | 212 } |
216 | 213 |
217 bool TodayMetricsLogger::CreateNewLog() { | 214 bool TodayMetricsLogger::CreateNewLog() { |
218 id previous_log = [[NSUserDefaults standardUserDefaults] | 215 id previous_log = [[NSUserDefaults standardUserDefaults] |
219 dataForKey:kTodayExtensionMetricsCurrentLog]; | 216 dataForKey:kTodayExtensionMetricsCurrentLog]; |
220 if (previous_log) { | 217 if (previous_log) { |
221 app_group::client_app::AddPendingLog(previous_log, | 218 app_group::client_app::AddPendingLog(previous_log, |
222 app_group::APP_GROUP_TODAY_EXTENSION); | 219 app_group::APP_GROUP_TODAY_EXTENSION); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 void TodayMetricsLogger::UniqueInconsistencyDetected( | 295 void TodayMetricsLogger::UniqueInconsistencyDetected( |
299 base::HistogramBase::Inconsistency problem) { | 296 base::HistogramBase::Inconsistency problem) { |
300 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", problem, | 297 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", problem, |
301 base::HistogramBase::NEVER_EXCEEDED_VALUE); | 298 base::HistogramBase::NEVER_EXCEEDED_VALUE); |
302 } | 299 } |
303 | 300 |
304 void TodayMetricsLogger::InconsistencyDetectedInLoggedCount(int amount) { | 301 void TodayMetricsLogger::InconsistencyDetectedInLoggedCount(int amount) { |
305 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", | 302 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", |
306 std::abs(amount)); | 303 std::abs(amount)); |
307 } | 304 } |
OLD | NEW |