OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/app/application_delegate/metrics_mediator.h" | 5 #import "ios/chrome/app/application_delegate/metrics_mediator.h" |
6 | 6 |
7 #include "base/ios/weak_nsobject.h" | |
8 #include "base/mac/bind_objc_block.h" | 7 #include "base/mac/bind_objc_block.h" |
9 #include "base/metrics/user_metrics_action.h" | 8 #include "base/metrics/user_metrics_action.h" |
10 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
11 #include "components/crash/core/common/crash_keys.h" | 10 #include "components/crash/core/common/crash_keys.h" |
12 #include "components/metrics/metrics_pref_names.h" | 11 #include "components/metrics/metrics_pref_names.h" |
13 #include "components/metrics/metrics_service.h" | 12 #include "components/metrics/metrics_service.h" |
14 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
15 #import "ios/chrome/app/application_delegate/startup_information.h" | 14 #import "ios/chrome/app/application_delegate/startup_information.h" |
16 #include "ios/chrome/browser/application_context.h" | 15 #include "ios/chrome/browser/application_context.h" |
17 #include "ios/chrome/browser/chrome_url_constants.h" | 16 #include "ios/chrome/browser/chrome_url_constants.h" |
18 #include "ios/chrome/browser/crash_report/breakpad_helper.h" | 17 #include "ios/chrome/browser/crash_report/breakpad_helper.h" |
19 #import "ios/chrome/browser/crash_report/crash_report_background_uploader.h" | 18 #import "ios/chrome/browser/crash_report/crash_report_background_uploader.h" |
20 #include "ios/chrome/browser/experimental_flags.h" | 19 #include "ios/chrome/browser/experimental_flags.h" |
21 #include "ios/chrome/browser/metrics/first_user_action_recorder.h" | 20 #include "ios/chrome/browser/metrics/first_user_action_recorder.h" |
22 #import "ios/chrome/browser/metrics/previous_session_info.h" | 21 #import "ios/chrome/browser/metrics/previous_session_info.h" |
23 #import "ios/chrome/browser/net/connection_type_observer_bridge.h" | 22 #import "ios/chrome/browser/net/connection_type_observer_bridge.h" |
24 #include "ios/chrome/browser/pref_names.h" | 23 #include "ios/chrome/browser/pref_names.h" |
25 #import "ios/chrome/browser/tabs/tab.h" | 24 #import "ios/chrome/browser/tabs/tab.h" |
26 #import "ios/chrome/browser/tabs/tab_model.h" | 25 #import "ios/chrome/browser/tabs/tab_model.h" |
27 #import "ios/chrome/browser/ui/main/browser_view_information.h" | 26 #import "ios/chrome/browser/ui/main/browser_view_information.h" |
28 #include "ios/chrome/common/app_group/app_group_metrics_mainapp.h" | 27 #include "ios/chrome/common/app_group/app_group_metrics_mainapp.h" |
29 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 28 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
30 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi
der.h" | 29 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi
der.h" |
31 #include "ios/web/public/web_thread.h" | 30 #include "ios/web/public/web_thread.h" |
32 #include "url/gurl.h" | 31 #include "url/gurl.h" |
33 | 32 |
| 33 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 34 #error "This file requires ARC support." |
| 35 #endif |
| 36 |
34 namespace { | 37 namespace { |
35 // The amount of time (in seconds) between two background fetch calls. | 38 // The amount of time (in seconds) between two background fetch calls. |
36 // TODO(crbug.com/496172): Re-enable background fetch. | 39 // TODO(crbug.com/496172): Re-enable background fetch. |
37 const NSTimeInterval kBackgroundFetchIntervalDelay = | 40 const NSTimeInterval kBackgroundFetchIntervalDelay = |
38 UIApplicationBackgroundFetchIntervalNever; | 41 UIApplicationBackgroundFetchIntervalNever; |
39 // The amount of time (in seconds) to wait for the user to start a new task. | 42 // The amount of time (in seconds) to wait for the user to start a new task. |
40 const NSTimeInterval kFirstUserActionTimeout = 30.0; | 43 const NSTimeInterval kFirstUserActionTimeout = 30.0; |
41 } // namespace | 44 } // namespace |
42 | 45 |
43 namespace metrics_mediator { | 46 namespace metrics_mediator { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 ->GetDistributionBrandCode()); | 234 ->GetDistributionBrandCode()); |
232 app_group::main_app::EnableMetrics( | 235 app_group::main_app::EnableMetrics( |
233 base::SysUTF8ToNSString(metrics->GetClientId()), brandCode, | 236 base::SysUTF8ToNSString(metrics->GetClientId()), brandCode, |
234 prefs->GetInt64(metrics::prefs::kInstallDate), | 237 prefs->GetInt64(metrics::prefs::kInstallDate), |
235 prefs->GetInt64(metrics::prefs::kMetricsReportingEnabledTimestamp)); | 238 prefs->GetInt64(metrics::prefs::kMetricsReportingEnabledTimestamp)); |
236 } else { | 239 } else { |
237 app_group::main_app::DisableMetrics(); | 240 app_group::main_app::DisableMetrics(); |
238 } | 241 } |
239 | 242 |
240 // If metrics are enabled, process the logs. Otherwise, just delete them. | 243 // If metrics are enabled, process the logs. Otherwise, just delete them. |
241 base::mac::ScopedBlock<app_group::ProceduralBlockWithData> callback; | 244 app_group::ProceduralBlockWithData callback; |
242 if (enabled) { | 245 if (enabled) { |
243 callback.reset( | 246 callback = [^(NSData* log_content) { |
244 ^(NSData* log_content) { | 247 std::string log(static_cast<const char*>([log_content bytes]), |
245 std::string log(static_cast<const char*>([log_content bytes]), | 248 static_cast<size_t>([log_content length])); |
246 static_cast<size_t>([log_content length])); | 249 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, |
247 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, | 250 base::BindBlockArc(^{ |
248 base::BindBlock(^{ | 251 metrics->PushExternalLog(log); |
249 metrics->PushExternalLog(log); | 252 })); |
250 })); | 253 } copy]; |
251 }, | |
252 base::scoped_policy::RETAIN); | |
253 } | 254 } |
254 | 255 |
255 web::WebThread::PostTask( | 256 web::WebThread::PostTask( |
256 web::WebThread::FILE, FROM_HERE, | 257 web::WebThread::FILE, FROM_HERE, |
257 base::Bind(&app_group::main_app::ProcessPendingLogs, callback)); | 258 base::Bind(&app_group::main_app::ProcessPendingLogs, callback)); |
258 } | 259 } |
259 | 260 |
260 - (void)processCrashReportsPresentAtStartup { | 261 - (void)processCrashReportsPresentAtStartup { |
261 _hasProcessedCrashReportsPresentAtStartup = YES; | 262 _hasProcessedCrashReportsPresentAtStartup = YES; |
262 | 263 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 386 } |
386 | 387 |
387 - (BOOL)isMetricsReportingEnabledWifiOnly { | 388 - (BOOL)isMetricsReportingEnabledWifiOnly { |
388 return GetApplicationContext()->GetLocalState()->GetBoolean( | 389 return GetApplicationContext()->GetLocalState()->GetBoolean( |
389 metrics::prefs::kMetricsReportingEnabled) && | 390 metrics::prefs::kMetricsReportingEnabled) && |
390 GetApplicationContext()->GetLocalState()->GetBoolean( | 391 GetApplicationContext()->GetLocalState()->GetBoolean( |
391 prefs::kMetricsReportingWifiOnly); | 392 prefs::kMetricsReportingWifiOnly); |
392 } | 393 } |
393 | 394 |
394 @end | 395 @end |
OLD | NEW |