OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | |
11 #include <map> | |
10 #include <set> | 12 #include <set> |
11 #include <string> | 13 #include <string> |
12 #include <utility> | 14 #include <utility> |
13 #include <vector> | 15 #include <vector> |
14 | 16 |
15 #include "base/at_exit.h" | 17 #include "base/at_exit.h" |
16 #include "base/base_switches.h" | 18 #include "base/base_switches.h" |
17 #include "base/bind.h" | 19 #include "base/bind.h" |
18 #include "base/command_line.h" | 20 #include "base/command_line.h" |
fdoray
2016/08/05 20:58:54
#include "base/logging.h"
robliao
2016/08/05 22:23:28
Done.
| |
19 #include "base/debug/crash_logging.h" | 21 #include "base/debug/crash_logging.h" |
20 #include "base/debug/debugger.h" | 22 #include "base/debug/debugger.h" |
21 #include "base/feature_list.h" | 23 #include "base/feature_list.h" |
22 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
23 #include "base/files/file_util.h" | 25 #include "base/files/file_util.h" |
24 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
25 #include "base/metrics/field_trial.h" | 27 #include "base/metrics/field_trial.h" |
26 #include "base/metrics/histogram_macros.h" | 28 #include "base/metrics/histogram_macros.h" |
27 #include "base/path_service.h" | 29 #include "base/path_service.h" |
28 #include "base/profiler/scoped_tracker.h" | 30 #include "base/profiler/scoped_tracker.h" |
29 #include "base/run_loop.h" | 31 #include "base/run_loop.h" |
30 #include "base/strings/string_number_conversions.h" | 32 #include "base/strings/string_number_conversions.h" |
31 #include "base/strings/string_piece.h" | 33 #include "base/strings/string_piece.h" |
32 #include "base/strings/string_split.h" | 34 #include "base/strings/string_split.h" |
33 #include "base/strings/sys_string_conversions.h" | 35 #include "base/strings/sys_string_conversions.h" |
34 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
35 #include "base/sys_info.h" | 37 #include "base/sys_info.h" |
38 #include "base/task_scheduler/scheduler_worker_pool_params.h" | |
39 #include "base/task_scheduler/task_scheduler.h" | |
40 #include "base/task_scheduler/task_traits.h" | |
36 #include "base/threading/platform_thread.h" | 41 #include "base/threading/platform_thread.h" |
37 #include "base/time/default_tick_clock.h" | 42 #include "base/time/default_tick_clock.h" |
38 #include "base/time/time.h" | 43 #include "base/time/time.h" |
39 #include "base/trace_event/trace_event.h" | 44 #include "base/trace_event/trace_event.h" |
40 #include "base/values.h" | 45 #include "base/values.h" |
41 #include "build/build_config.h" | 46 #include "build/build_config.h" |
42 #include "cc/base/switches.h" | 47 #include "cc/base/switches.h" |
43 #include "chrome/browser/about_flags.h" | 48 #include "chrome/browser/about_flags.h" |
44 #include "chrome/browser/after_startup_task_utils.h" | 49 #include "chrome/browser/after_startup_task_utils.h" |
45 #include "chrome/browser/browser_process.h" | 50 #include "chrome/browser/browser_process.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, | 315 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, |
311 const std::vector<GURL>& new_tabs) { | 316 const std::vector<GURL>& new_tabs) { |
312 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); | 317 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
313 it != new_tabs.end(); ++it) { | 318 it != new_tabs.end(); ++it) { |
314 if (it->is_valid()) | 319 if (it->is_valid()) |
315 browser_creator->AddFirstRunTab(*it); | 320 browser_creator->AddFirstRunTab(*it); |
316 } | 321 } |
317 } | 322 } |
318 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 323 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
319 | 324 |
325 enum WorkerPoolType : size_t { | |
fdoray
2016/08/05 20:58:54
enum class?
robliao
2016/08/05 22:23:28
I kept this as an enum for the similar reason we d
| |
326 BACKGROUND_WORKER_POOL = 0, | |
327 BACKGROUND_FILE_IO_WORKER_POOL, | |
328 FOREGROUND_WORKER_POOL, | |
329 FOREGROUND_FILE_IO_WORKER_POOL, | |
330 WORKER_POOL_COUNT, | |
331 }; | |
332 | |
333 struct WorkerPoolVariationValues { | |
334 WorkerPoolVariationValues() | |
335 : threads(0), | |
336 detach_milliseconds(0) {} | |
337 | |
338 int threads; | |
fdoray
2016/08/05 20:58:53
struct WorkerPoolVariationValues {
int threads =
robliao
2016/08/05 22:23:28
Done. I kept forgetting about inline initializatio
| |
339 int64_t detach_milliseconds; | |
340 }; | |
341 | |
342 // Converts |pool_descriptor| to a WorkerPoolVariationValues. Returns a default | |
fdoray
2016/08/05 20:58:53
|pool_descriptor| is a string that follows the for
robliao
2016/08/05 22:23:29
Done.
| |
343 // WorkerPoolVariationValues on failure. | |
fdoray
2016/08/05 20:58:54
No need to document what the function does after N
robliao
2016/08/05 22:23:28
See below on the NOTREACHED discussion. Changed to
| |
344 WorkerPoolVariationValues StringToWorkerPoolVariationValues( | |
345 const base::StringPiece& pool_descriptor) { | |
346 std::vector<std::string> tokens = SplitString(pool_descriptor, ",", | |
fdoray
2016/08/05 20:58:53
const
robliao
2016/08/05 22:23:29
Done.
| |
347 base::KEEP_WHITESPACE, | |
348 base::SPLIT_WANT_NONEMPTY); | |
349 int minimum; | |
350 int maximum; | |
351 double multiplier; | |
352 int offset; | |
353 int detach_milliseconds; | |
354 // Checking for a size greater than the expected amount allows us to be | |
355 // forward compatible if we add more variation values. | |
356 if (tokens.size() >= 5 && | |
357 base::StringToInt(tokens[0], &minimum) && | |
358 base::StringToInt(tokens[1], &maximum) && | |
359 base::StringToDouble(tokens[2], &multiplier) && | |
360 base::StringToInt(tokens[3], &offset) && | |
361 base::StringToInt(tokens[4], &detach_milliseconds)) { | |
362 int num_of_cores = base::SysInfo::NumberOfProcessors(); | |
363 int threads = std::round<int>(num_of_cores * multiplier) + offset; | |
fdoray
2016/08/05 20:58:54
const num_of_cores
const threads
robliao
2016/08/05 22:23:28
Done.
| |
364 WorkerPoolVariationValues values; | |
365 values.threads = std::min(maximum, std::max(minimum, threads)); | |
366 values.detach_milliseconds = detach_milliseconds; | |
367 return values; | |
368 } | |
369 NOTREACHED() << "Invalid Worker Pool Descriptor: " << pool_descriptor; | |
370 return WorkerPoolVariationValues(); | |
371 } | |
372 | |
373 // Returns the worker pool index for |traits| defaulting to | |
374 // FOREGROUND_WORKER_POOL or FOREGROUND_FILE_IO_WORKER_POOL on unknown | |
375 // priorities. | |
376 size_t WorkerPoolIndexForTraits(const base::TaskTraits& traits) { | |
377 if (traits.with_file_io()) { | |
378 return traits.priority() == base::TaskPriority::BACKGROUND | |
379 ? WorkerPoolType::BACKGROUND_FILE_IO_WORKER_POOL | |
380 : WorkerPoolType::FOREGROUND_FILE_IO_WORKER_POOL; | |
381 } | |
382 return traits.priority() == base::TaskPriority::BACKGROUND | |
383 ? WorkerPoolType::BACKGROUND_WORKER_POOL | |
384 : WorkerPoolType::FOREGROUND_WORKER_POOL; | |
385 } | |
386 | |
387 // Initializes the Default Browser Task Scheduler if there is a valid variation | |
388 // parameter for the field trial. | |
389 void MaybeInitializeTaskScheduler() { | |
390 static const char kFieldTrialName[] = "BrowserScheduler"; | |
fdoray
2016/08/05 20:58:54
constexpr
robliao
2016/08/05 22:23:29
Done.
| |
391 std::map<std::string, std::string> variation_params; | |
392 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) | |
393 return; | |
394 | |
395 // Order matches WorkerPoolType above. | |
396 static const char* kWorkerPoolNames[] = { | |
fdoray
2016/08/05 20:58:54
constexpr
robliao
2016/08/05 22:23:29
This triggers a compiler bug, so it's going to hav
| |
397 "Background", | |
398 "BackgroundFileIO", | |
399 "Foreground", | |
400 "ForegroundFileIO", | |
401 }; | |
402 static_assert( | |
403 arraysize(kWorkerPoolNames) == WorkerPoolType::WORKER_POOL_COUNT, | |
404 "Mismatched Worker Pool Types and Names"); | |
405 | |
406 std::vector<WorkerPoolVariationValues> values; | |
407 for (size_t i = 0; i < arraysize(kWorkerPoolNames); i++) { | |
408 const char* current = kWorkerPoolNames[i]; | |
409 auto pair = variation_params.find(current); | |
410 if (pair == variation_params.end()) { | |
411 NOTREACHED() << "Missing Worker Pool Configuration: " << current; | |
fdoray
2016/08/05 20:58:54
https://chromium.googlesource.com/chromium/src/+/m
robliao
2016/08/05 22:23:29
I guess these are coming in from the land of netwo
| |
412 return; | |
413 } | |
414 | |
415 const WorkerPoolVariationValues variation_value = | |
416 StringToWorkerPoolVariationValues(pair->second); | |
417 | |
418 if (variation_value.threads == 0 || | |
419 variation_value.detach_milliseconds == 0) { | |
420 NOTREACHED() << "Invalid Worker Pool Configuration: " << current << | |
421 " [" << pair->second << "]"; | |
fdoray
2016/08/05 20:58:53
ditto
robliao
2016/08/05 22:23:28
See above.
| |
422 return; | |
423 } | |
424 | |
425 values.push_back(variation_value); | |
426 } | |
427 | |
428 DCHECK_EQ(values.size(), WorkerPoolType::WORKER_POOL_COUNT); | |
fdoray
2016/08/05 20:58:54
overkill DCHECK?
I don't suggest that you remove i
robliao
2016/08/05 22:23:29
I guess it's not intrinsic that the values.size()
| |
429 | |
430 using ThreadPriority = base::ThreadPriority; | |
431 using IORestriction = base::SchedulerWorkerPoolParams::IORestriction; | |
432 std::vector<base::SchedulerWorkerPoolParams> params_vector; | |
433 DCHECK_EQ(params_vector.size(), WorkerPoolType::BACKGROUND_WORKER_POOL); | |
434 params_vector.emplace_back( | |
435 kWorkerPoolNames[BACKGROUND_WORKER_POOL], | |
436 ThreadPriority::BACKGROUND, | |
437 IORestriction::DISALLOWED, | |
438 values[BACKGROUND_WORKER_POOL].threads, | |
439 base::TimeDelta::FromMilliseconds( | |
440 values[BACKGROUND_WORKER_POOL].detach_milliseconds)); | |
441 | |
442 DCHECK_EQ(params_vector.size(), | |
443 WorkerPoolType::BACKGROUND_FILE_IO_WORKER_POOL); | |
444 params_vector.emplace_back( | |
445 kWorkerPoolNames[BACKGROUND_FILE_IO_WORKER_POOL], | |
446 ThreadPriority::BACKGROUND, | |
447 IORestriction::ALLOWED, | |
448 values[BACKGROUND_FILE_IO_WORKER_POOL].threads, | |
449 base::TimeDelta::FromMilliseconds( | |
450 values[BACKGROUND_FILE_IO_WORKER_POOL].detach_milliseconds)); | |
451 | |
452 DCHECK_EQ(params_vector.size(), WorkerPoolType::FOREGROUND_WORKER_POOL); | |
453 params_vector.emplace_back( | |
454 kWorkerPoolNames[FOREGROUND_WORKER_POOL], | |
455 ThreadPriority::NORMAL, | |
456 IORestriction::DISALLOWED, | |
457 values[FOREGROUND_WORKER_POOL].threads, | |
458 base::TimeDelta::FromMilliseconds( | |
459 values[FOREGROUND_WORKER_POOL].detach_milliseconds)); | |
460 | |
461 DCHECK_EQ(params_vector.size(), | |
462 WorkerPoolType::FOREGROUND_FILE_IO_WORKER_POOL); | |
463 params_vector.emplace_back( | |
464 kWorkerPoolNames[FOREGROUND_FILE_IO_WORKER_POOL], | |
465 ThreadPriority::NORMAL, | |
466 IORestriction::ALLOWED, | |
467 values[FOREGROUND_FILE_IO_WORKER_POOL].threads, | |
468 base::TimeDelta::FromMilliseconds( | |
469 values[FOREGROUND_FILE_IO_WORKER_POOL].detach_milliseconds)); | |
470 | |
471 DCHECK_EQ(params_vector.size(), WorkerPoolType::WORKER_POOL_COUNT); | |
472 | |
473 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
474 params_vector, base::Bind(WorkerPoolIndexForTraits)); | |
475 } | |
476 | |
320 // Returns the new local state object, guaranteed non-NULL. | 477 // Returns the new local state object, guaranteed non-NULL. |
321 // |local_state_task_runner| must be a shutdown-blocking task runner. | 478 // |local_state_task_runner| must be a shutdown-blocking task runner. |
322 PrefService* InitializeLocalState( | 479 PrefService* InitializeLocalState( |
323 base::SequencedTaskRunner* local_state_task_runner, | 480 base::SequencedTaskRunner* local_state_task_runner, |
324 const base::CommandLine& parsed_command_line) { | 481 const base::CommandLine& parsed_command_line) { |
325 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") | 482 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") |
326 | 483 |
327 // Load local state. This includes the application locale so we know which | 484 // Load local state. This includes the application locale so we know which |
328 // locale dll to load. This also causes local state prefs to be registered. | 485 // locale dll to load. This also causes local state prefs to be registered. |
329 PrefService* local_state = g_browser_process->local_state(); | 486 PrefService* local_state = g_browser_process->local_state(); |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1207 chromeos::CrosSettings::Initialize(); | 1364 chromeos::CrosSettings::Initialize(); |
1208 #endif // defined(OS_CHROMEOS) | 1365 #endif // defined(OS_CHROMEOS) |
1209 | 1366 |
1210 SetupOriginTrialsCommandLine(); | 1367 SetupOriginTrialsCommandLine(); |
1211 | 1368 |
1212 // Now the command line has been mutated based on about:flags, we can setup | 1369 // Now the command line has been mutated based on about:flags, we can setup |
1213 // metrics and initialize field trials. The field trials are needed by | 1370 // metrics and initialize field trials. The field trials are needed by |
1214 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1371 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
1215 SetupMetricsAndFieldTrials(); | 1372 SetupMetricsAndFieldTrials(); |
1216 | 1373 |
1374 MaybeInitializeTaskScheduler(); | |
1375 | |
1217 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1376 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
1218 browser_process_->PreCreateThreads(); | 1377 browser_process_->PreCreateThreads(); |
1219 | 1378 |
1220 device::GeolocationProvider::SetGeolocationDelegate( | 1379 device::GeolocationProvider::SetGeolocationDelegate( |
1221 new ChromeGeolocationDelegate()); | 1380 new ChromeGeolocationDelegate()); |
1222 | 1381 |
1223 return content::RESULT_CODE_NORMAL_EXIT; | 1382 return content::RESULT_CODE_NORMAL_EXIT; |
1224 } | 1383 } |
1225 | 1384 |
1226 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1385 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2068 chromeos::CrosSettings::Shutdown(); | 2227 chromeos::CrosSettings::Shutdown(); |
2069 #endif // defined(OS_CHROMEOS) | 2228 #endif // defined(OS_CHROMEOS) |
2070 #endif // defined(OS_ANDROID) | 2229 #endif // defined(OS_ANDROID) |
2071 } | 2230 } |
2072 | 2231 |
2073 // Public members: | 2232 // Public members: |
2074 | 2233 |
2075 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2234 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
2076 chrome_extra_parts_.push_back(parts); | 2235 chrome_extra_parts_.push_back(parts); |
2077 } | 2236 } |
OLD | NEW |