| 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 #include "ios/chrome/browser/ios_chrome_main_parts.h" | 5 #include "ios/chrome/browser/ios_chrome_main_parts.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/task_scheduler/switches.h" |
| 14 #include "base/task_scheduler/task_scheduler.h" | 15 #include "base/task_scheduler/task_scheduler.h" |
| 15 #include "base/time/default_tick_clock.h" | 16 #include "base/time/default_tick_clock.h" |
| 16 #include "components/content_settings/core/browser/cookie_settings.h" | 17 #include "components/content_settings/core/browser/cookie_settings.h" |
| 17 #include "components/content_settings/core/common/content_settings_pattern.h" | 18 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 18 #include "components/flags_ui/pref_service_flags_storage.h" | 19 #include "components/flags_ui/pref_service_flags_storage.h" |
| 19 #include "components/language_usage_metrics/language_usage_metrics.h" | 20 #include "components/language_usage_metrics/language_usage_metrics.h" |
| 20 #include "components/metrics/metrics_service.h" | 21 #include "components/metrics/metrics_service.h" |
| 21 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" | 22 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" |
| 22 #include "components/metrics/profiler/tracking_synchronizer.h" | 23 #include "components/metrics/profiler/tracking_synchronizer.h" |
| 23 #include "components/metrics_services_manager/metrics_services_manager.h" | 24 #include "components/metrics_services_manager/metrics_services_manager.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 52 #include "net/http/http_stream_factory.h" | 53 #include "net/http/http_stream_factory.h" |
| 53 #include "net/url_request/url_request.h" | 54 #include "net/url_request/url_request.h" |
| 54 #include "ui/base/l10n/l10n_util_mac.h" | 55 #include "ui/base/l10n/l10n_util_mac.h" |
| 55 #include "ui/base/resource/resource_bundle.h" | 56 #include "ui/base/resource/resource_bundle.h" |
| 56 | 57 |
| 57 #if defined(ENABLE_RLZ) | 58 #if defined(ENABLE_RLZ) |
| 58 #include "components/rlz/rlz_tracker.h" // nogncheck | 59 #include "components/rlz/rlz_tracker.h" // nogncheck |
| 59 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" // nogncheck | 60 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" // nogncheck |
| 60 #endif | 61 #endif |
| 61 | 62 |
| 63 namespace { |
| 64 |
| 65 void MaybeInitializeTaskScheduler() { |
| 66 static constexpr char kFieldTrialName[] = "BrowserScheduler"; |
| 67 std::map<std::string, std::string> variation_params; |
| 68 bool used_default_config = false; |
| 69 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { |
| 70 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 71 switches::kEnableBrowserTaskScheduler)) { |
| 72 return; |
| 73 } |
| 74 |
| 75 // TODO(robliao): Remove below once iOS uses fieldtrial_testing_config.json. |
| 76 // Synchronize the below from fieldtrial_testing_config.json. |
| 77 DCHECK(variation_params.empty()); |
| 78 variation_params["Background"] = "3;8;0.1;0;30000"; |
| 79 variation_params["BackgroundFileIO"] = "3;8;0.1;0;30000"; |
| 80 variation_params["Foreground"] = "8;32;0.3;0;30000"; |
| 81 variation_params["ForegroundFileIO"] = "8;32;0.3;0;30000"; |
| 82 used_default_config = true; |
| 83 } |
| 84 |
| 85 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) |
| 86 return; |
| 87 |
| 88 // TODO(gab): Remove this when http://crbug.com/622400 concludes. |
| 89 const auto sequenced_worker_pool_param = |
| 90 variation_params.find("RedirectSequencedWorkerPools"); |
| 91 if (used_default_config || |
| 92 (sequenced_worker_pool_param != variation_params.end() && |
| 93 sequenced_worker_pool_param->second == "true")) { |
| 94 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); |
| 95 } |
| 96 } |
| 97 |
| 98 } // namespace |
| 99 |
| 62 IOSChromeMainParts::IOSChromeMainParts( | 100 IOSChromeMainParts::IOSChromeMainParts( |
| 63 const base::CommandLine& parsed_command_line) | 101 const base::CommandLine& parsed_command_line) |
| 64 : parsed_command_line_(parsed_command_line), local_state_(nullptr) { | 102 : parsed_command_line_(parsed_command_line), local_state_(nullptr) { |
| 65 // Chrome disallows cookies by default. All code paths that want to use | 103 // Chrome disallows cookies by default. All code paths that want to use |
| 66 // cookies need to go through one of Chrome's URLRequestContexts which have | 104 // cookies need to go through one of Chrome's URLRequestContexts which have |
| 67 // a ChromeNetworkDelegate attached that selectively allows cookies again. | 105 // a ChromeNetworkDelegate attached that selectively allows cookies again. |
| 68 net::URLRequest::SetDefaultCookiePolicyToBlock(); | 106 net::URLRequest::SetDefaultCookiePolicyToBlock(); |
| 69 } | 107 } |
| 70 | 108 |
| 71 IOSChromeMainParts::~IOSChromeMainParts() {} | 109 IOSChromeMainParts::~IOSChromeMainParts() {} |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 165 |
| 128 // Task Scheduler initialization needs to be here for the following reasons: | 166 // Task Scheduler initialization needs to be here for the following reasons: |
| 129 // * After |SetupFieldTrials()|: Initialization uses variations. | 167 // * After |SetupFieldTrials()|: Initialization uses variations. |
| 130 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | 168 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
| 131 // Task Scheduler must do any necessary redirection before then. | 169 // Task Scheduler must do any necessary redirection before then. |
| 132 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | 170 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
| 133 // created before any other threads are (by contract) but it creates | 171 // created before any other threads are (by contract) but it creates |
| 134 // threads itself so instantiating it earlier is also incorrect. | 172 // threads itself so instantiating it earlier is also incorrect. |
| 135 // To maintain scoping symmetry, if this line is moved, the corresponding | 173 // To maintain scoping symmetry, if this line is moved, the corresponding |
| 136 // shutdown call may also need to be moved. | 174 // shutdown call may also need to be moved. |
| 137 task_scheduler_util::InitializeDefaultBrowserTaskScheduler(); | 175 MaybeInitializeTaskScheduler(); |
| 138 | 176 |
| 139 SetupMetrics(); | 177 SetupMetrics(); |
| 140 | 178 |
| 141 // Initialize FieldTrialSynchronizer system. | 179 // Initialize FieldTrialSynchronizer system. |
| 142 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); | 180 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); |
| 143 | 181 |
| 144 application_context_->PreCreateThreads(); | 182 application_context_->PreCreateThreads(); |
| 145 } | 183 } |
| 146 | 184 |
| 147 void IOSChromeMainParts::PreMainMessageLoopRun() { | 185 void IOSChromeMainParts::PreMainMessageLoopRun() { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 333 |
| 296 void IOSChromeMainParts::StartMetricsRecording() { | 334 void IOSChromeMainParts::StartMetricsRecording() { |
| 297 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); | 335 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); |
| 298 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( | 336 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( |
| 299 net::NetworkChangeNotifier::GetConnectionType()); | 337 net::NetworkChangeNotifier::GetConnectionType()); |
| 300 bool mayUpload = !wifiOnly || !isConnectionCellular; | 338 bool mayUpload = !wifiOnly || !isConnectionCellular; |
| 301 | 339 |
| 302 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( | 340 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( |
| 303 mayUpload); | 341 mayUpload); |
| 304 } | 342 } |
| OLD | NEW |