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 |
sdefresne
2017/01/17 14:48:29
Do you forgot to add ARC guards here?
stkhapugin
2017/01/17 14:53:55
Done.
| |
34 namespace { | 33 namespace { |
35 // The amount of time (in seconds) between two background fetch calls. | 34 // The amount of time (in seconds) between two background fetch calls. |
36 // TODO(crbug.com/496172): Re-enable background fetch. | 35 // TODO(crbug.com/496172): Re-enable background fetch. |
37 const NSTimeInterval kBackgroundFetchIntervalDelay = | 36 const NSTimeInterval kBackgroundFetchIntervalDelay = |
38 UIApplicationBackgroundFetchIntervalNever; | 37 UIApplicationBackgroundFetchIntervalNever; |
39 // The amount of time (in seconds) to wait for the user to start a new task. | 38 // The amount of time (in seconds) to wait for the user to start a new task. |
40 const NSTimeInterval kFirstUserActionTimeout = 30.0; | 39 const NSTimeInterval kFirstUserActionTimeout = 30.0; |
41 } // namespace | 40 } // namespace |
42 | 41 |
43 namespace metrics_mediator { | 42 namespace metrics_mediator { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 base::SysUTF8ToNSString(metrics->GetClientId()), brandCode, | 232 base::SysUTF8ToNSString(metrics->GetClientId()), brandCode, |
234 prefs->GetInt64(metrics::prefs::kInstallDate), | 233 prefs->GetInt64(metrics::prefs::kInstallDate), |
235 prefs->GetInt64(metrics::prefs::kMetricsReportingEnabledTimestamp)); | 234 prefs->GetInt64(metrics::prefs::kMetricsReportingEnabledTimestamp)); |
236 } else { | 235 } else { |
237 app_group::main_app::DisableMetrics(); | 236 app_group::main_app::DisableMetrics(); |
238 } | 237 } |
239 | 238 |
240 // If metrics are enabled, process the logs. Otherwise, just delete them. | 239 // If metrics are enabled, process the logs. Otherwise, just delete them. |
241 base::mac::ScopedBlock<app_group::ProceduralBlockWithData> callback; | 240 base::mac::ScopedBlock<app_group::ProceduralBlockWithData> callback; |
242 if (enabled) { | 241 if (enabled) { |
243 callback.reset( | 242 callback.reset([^(NSData* log_content) { |
244 ^(NSData* log_content) { | 243 std::string log(static_cast<const char*>([log_content bytes]), |
245 std::string log(static_cast<const char*>([log_content bytes]), | 244 static_cast<size_t>([log_content length])); |
246 static_cast<size_t>([log_content length])); | 245 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, |
247 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, | 246 base::BindBlockArc(^{ |
248 base::BindBlock(^{ | 247 metrics->PushExternalLog(log); |
249 metrics->PushExternalLog(log); | 248 })); |
250 })); | 249 } copy]); |
251 }, | |
252 base::scoped_policy::RETAIN); | |
253 } | 250 } |
254 | 251 |
255 web::WebThread::PostTask( | 252 web::WebThread::PostTask( |
256 web::WebThread::FILE, FROM_HERE, | 253 web::WebThread::FILE, FROM_HERE, |
257 base::Bind(&app_group::main_app::ProcessPendingLogs, callback)); | 254 base::Bind(&app_group::main_app::ProcessPendingLogs, callback)); |
258 } | 255 } |
259 | 256 |
260 - (void)processCrashReportsPresentAtStartup { | 257 - (void)processCrashReportsPresentAtStartup { |
261 _hasProcessedCrashReportsPresentAtStartup = YES; | 258 _hasProcessedCrashReportsPresentAtStartup = YES; |
262 | 259 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 } | 382 } |
386 | 383 |
387 - (BOOL)isMetricsReportingEnabledWifiOnly { | 384 - (BOOL)isMetricsReportingEnabledWifiOnly { |
388 return GetApplicationContext()->GetLocalState()->GetBoolean( | 385 return GetApplicationContext()->GetLocalState()->GetBoolean( |
389 metrics::prefs::kMetricsReportingEnabled) && | 386 metrics::prefs::kMetricsReportingEnabled) && |
390 GetApplicationContext()->GetLocalState()->GetBoolean( | 387 GetApplicationContext()->GetLocalState()->GetBoolean( |
391 prefs::kMetricsReportingWifiOnly); | 388 prefs::kMetricsReportingWifiOnly); |
392 } | 389 } |
393 | 390 |
394 @end | 391 @end |
OLD | NEW |