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" | |
15 #include "base/task_scheduler/task_scheduler.h" | 14 #include "base/task_scheduler/task_scheduler.h" |
16 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
17 #include "components/content_settings/core/browser/cookie_settings.h" | 16 #include "components/content_settings/core/browser/cookie_settings.h" |
18 #include "components/content_settings/core/common/content_settings_pattern.h" | 17 #include "components/content_settings/core/common/content_settings_pattern.h" |
19 #include "components/flags_ui/pref_service_flags_storage.h" | 18 #include "components/flags_ui/pref_service_flags_storage.h" |
20 #include "components/language_usage_metrics/language_usage_metrics.h" | 19 #include "components/language_usage_metrics/language_usage_metrics.h" |
21 #include "components/metrics/metrics_service.h" | 20 #include "components/metrics/metrics_service.h" |
22 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" | 21 #include "components/metrics/profiler/ios/ios_tracking_synchronizer_delegate.h" |
23 #include "components/metrics/profiler/tracking_synchronizer.h" | 22 #include "components/metrics/profiler/tracking_synchronizer.h" |
24 #include "components/metrics_services_manager/metrics_services_manager.h" | 23 #include "components/metrics_services_manager/metrics_services_manager.h" |
(...skipping 28 matching lines...) Expand all Loading... |
53 #include "net/http/http_stream_factory.h" | 52 #include "net/http/http_stream_factory.h" |
54 #include "net/url_request/url_request.h" | 53 #include "net/url_request/url_request.h" |
55 #include "ui/base/l10n/l10n_util_mac.h" | 54 #include "ui/base/l10n/l10n_util_mac.h" |
56 #include "ui/base/resource/resource_bundle.h" | 55 #include "ui/base/resource/resource_bundle.h" |
57 | 56 |
58 #if defined(ENABLE_RLZ) | 57 #if defined(ENABLE_RLZ) |
59 #include "components/rlz/rlz_tracker.h" // nogncheck | 58 #include "components/rlz/rlz_tracker.h" // nogncheck |
60 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" // nogncheck | 59 #include "ios/chrome/browser/rlz/rlz_tracker_delegate_impl.h" // nogncheck |
61 #endif | 60 #endif |
62 | 61 |
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 | |
100 IOSChromeMainParts::IOSChromeMainParts( | 62 IOSChromeMainParts::IOSChromeMainParts( |
101 const base::CommandLine& parsed_command_line) | 63 const base::CommandLine& parsed_command_line) |
102 : parsed_command_line_(parsed_command_line), local_state_(nullptr) { | 64 : parsed_command_line_(parsed_command_line), local_state_(nullptr) { |
103 // Chrome disallows cookies by default. All code paths that want to use | 65 // Chrome disallows cookies by default. All code paths that want to use |
104 // cookies need to go through one of Chrome's URLRequestContexts which have | 66 // cookies need to go through one of Chrome's URLRequestContexts which have |
105 // a ChromeNetworkDelegate attached that selectively allows cookies again. | 67 // a ChromeNetworkDelegate attached that selectively allows cookies again. |
106 net::URLRequest::SetDefaultCookiePolicyToBlock(); | 68 net::URLRequest::SetDefaultCookiePolicyToBlock(); |
107 } | 69 } |
108 | 70 |
109 IOSChromeMainParts::~IOSChromeMainParts() {} | 71 IOSChromeMainParts::~IOSChromeMainParts() {} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 127 |
166 // Task Scheduler initialization needs to be here for the following reasons: | 128 // Task Scheduler initialization needs to be here for the following reasons: |
167 // * After |SetupFieldTrials()|: Initialization uses variations. | 129 // * After |SetupFieldTrials()|: Initialization uses variations. |
168 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | 130 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
169 // Task Scheduler must do any necessary redirection before then. | 131 // Task Scheduler must do any necessary redirection before then. |
170 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | 132 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
171 // created before any other threads are (by contract) but it creates | 133 // created before any other threads are (by contract) but it creates |
172 // threads itself so instantiating it earlier is also incorrect. | 134 // threads itself so instantiating it earlier is also incorrect. |
173 // To maintain scoping symmetry, if this line is moved, the corresponding | 135 // To maintain scoping symmetry, if this line is moved, the corresponding |
174 // shutdown call may also need to be moved. | 136 // shutdown call may also need to be moved. |
175 MaybeInitializeTaskScheduler(); | 137 task_scheduler_util::InitializeDefaultBrowserTaskScheduler(); |
176 | 138 |
177 SetupMetrics(); | 139 SetupMetrics(); |
178 | 140 |
179 // Initialize FieldTrialSynchronizer system. | 141 // Initialize FieldTrialSynchronizer system. |
180 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); | 142 field_trial_synchronizer_.reset(new ios::FieldTrialSynchronizer); |
181 | 143 |
182 application_context_->PreCreateThreads(); | 144 application_context_->PreCreateThreads(); |
183 } | 145 } |
184 | 146 |
185 void IOSChromeMainParts::PreMainMessageLoopRun() { | 147 void IOSChromeMainParts::PreMainMessageLoopRun() { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 295 |
334 void IOSChromeMainParts::StartMetricsRecording() { | 296 void IOSChromeMainParts::StartMetricsRecording() { |
335 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); | 297 bool wifiOnly = local_state_->GetBoolean(prefs::kMetricsReportingWifiOnly); |
336 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( | 298 bool isConnectionCellular = net::NetworkChangeNotifier::IsConnectionCellular( |
337 net::NetworkChangeNotifier::GetConnectionType()); | 299 net::NetworkChangeNotifier::GetConnectionType()); |
338 bool mayUpload = !wifiOnly || !isConnectionCellular; | 300 bool mayUpload = !wifiOnly || !isConnectionCellular; |
339 | 301 |
340 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( | 302 application_context_->GetMetricsServicesManager()->UpdateUploadPermissions( |
341 mayUpload); | 303 mayUpload); |
342 } | 304 } |
OLD | NEW |