Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: content/app/content_main_runner.cc

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: Fix unit test and remove macro Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/app/content_main_runner.h" 5 #include "content/public/app/content_main_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/allocator/allocator_check.h" 15 #include "base/allocator/allocator_check.h"
16 #include "base/allocator/allocator_extension.h" 16 #include "base/allocator/allocator_extension.h"
17 #include "base/at_exit.h" 17 #include "base/at_exit.h"
18 #include "base/base_switches.h" 18 #include "base/base_switches.h"
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/debug/debugger.h" 20 #include "base/debug/debugger.h"
21 #include "base/debug/stack_trace.h" 21 #include "base/debug/stack_trace.h"
22 #include "base/feature_list.h" 22 #include "base/feature_list.h"
23 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
24 #include "base/i18n/icu_util.h" 24 #include "base/i18n/icu_util.h"
25 #include "base/lazy_instance.h" 25 #include "base/lazy_instance.h"
26 #include "base/logging.h" 26 #include "base/logging.h"
27 #include "base/macros.h" 27 #include "base/macros.h"
28 #include "base/memory/scoped_vector.h" 28 #include "base/memory/scoped_vector.h"
29 #include "base/memory/shared_memory.h"
29 #include "base/metrics/field_trial.h" 30 #include "base/metrics/field_trial.h"
30 #include "base/metrics/histogram_base.h" 31 #include "base/metrics/histogram_base.h"
31 #include "base/metrics/statistics_recorder.h" 32 #include "base/metrics/statistics_recorder.h"
32 #include "base/path_service.h" 33 #include "base/path_service.h"
33 #include "base/process/launch.h" 34 #include "base/process/launch.h"
34 #include "base/process/memory.h" 35 #include "base/process/memory.h"
36 #include "base/process/process.h"
35 #include "base/process/process_handle.h" 37 #include "base/process/process_handle.h"
36 #include "base/profiler/scoped_tracker.h" 38 #include "base/profiler/scoped_tracker.h"
37 #include "base/strings/string_number_conversions.h" 39 #include "base/strings/string_number_conversions.h"
38 #include "base/strings/string_util.h" 40 #include "base/strings/string_util.h"
39 #include "base/strings/stringprintf.h" 41 #include "base/strings/stringprintf.h"
40 #include "base/trace_event/trace_event.h" 42 #include "base/trace_event/trace_event.h"
41 #include "build/build_config.h" 43 #include "build/build_config.h"
42 #include "components/tracing/browser/trace_config_file.h" 44 #include "components/tracing/browser/trace_config_file.h"
43 #include "components/tracing/common/trace_to_console.h" 45 #include "components/tracing/common/trace_to_console.h"
44 #include "components/tracing/common/tracing_switches.h" 46 #include "components/tracing/common/tracing_switches.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 *base::CommandLine::ForCurrentProcess(); 141 *base::CommandLine::ForCurrentProcess();
140 142
141 // Initialize statistical testing infrastructure. We set the entropy 143 // Initialize statistical testing infrastructure. We set the entropy
142 // provider to nullptr to disallow non-browser processes from creating 144 // provider to nullptr to disallow non-browser processes from creating
143 // their own one-time randomized trials; they should be created in the 145 // their own one-time randomized trials; they should be created in the
144 // browser process. 146 // browser process.
145 field_trial_list->reset(new base::FieldTrialList(nullptr)); 147 field_trial_list->reset(new base::FieldTrialList(nullptr));
146 148
147 // Ensure any field trials in browser are reflected into the child 149 // Ensure any field trials in browser are reflected into the child
148 // process. 150 // process.
149 if (command_line.HasSwitch(switches::kForceFieldTrials)) { 151 if (command_line.HasSwitch(switches::kFieldTrialHandle)) {
152 std::string arg =
153 command_line.GetSwitchValueASCII(switches::kFieldTrialHandle);
154 size_t token = arg.find(",");
155 int field_trial_handle = std::stoi(arg.substr(0, token));
156 int field_trial_length = std::stoi(arg.substr(token + 1, arg.length()));
157
158 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle);
159 base::SharedMemoryHandle shm_handle =
160 base::SharedMemoryHandle(handle, base::GetCurrentProcId());
161
162 base::SharedMemory shared_memory(shm_handle, false);
163 shared_memory.Map(field_trial_length);
164
165 char* field_trial_state = static_cast<char*>(shared_memory.memory());
166 bool result = base::FieldTrialList::CreateTrialsFromString(
167 std::string(field_trial_state), std::set<std::string>());
168 DCHECK(result);
169 } else if (command_line.HasSwitch(switches::kForceFieldTrials)) {
150 bool result = base::FieldTrialList::CreateTrialsFromString( 170 bool result = base::FieldTrialList::CreateTrialsFromString(
151 command_line.GetSwitchValueASCII(switches::kForceFieldTrials), 171 command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
152 std::set<std::string>()); 172 std::set<std::string>());
153 DCHECK(result); 173 DCHECK(result);
154 } 174 }
155 175
156 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 176 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
157 feature_list->InitializeFromCommandLine( 177 feature_list->InitializeFromCommandLine(
158 command_line.GetSwitchValueASCII(switches::kEnableFeatures), 178 command_line.GetSwitchValueASCII(switches::kEnableFeatures),
159 command_line.GetSwitchValueASCII(switches::kDisableFeatures)); 179 command_line.GetSwitchValueASCII(switches::kDisableFeatures));
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 862
843 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 863 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
844 }; 864 };
845 865
846 // static 866 // static
847 ContentMainRunner* ContentMainRunner::Create() { 867 ContentMainRunner* ContentMainRunner::Create() {
848 return new ContentMainRunnerImpl(); 868 return new ContentMainRunnerImpl();
849 } 869 }
850 870
851 } // namespace content 871 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698