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

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

Issue 2365273004: Initial implementation for sharing field trial state (win) (Closed)
Patch Set: Remove windows macro causing compilation issue 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.
151 #if defined(OS_WIN)
152 if (command_line.HasSwitch("field_trial_handle")) {
153 int field_trial_handle = std::stoi(
154 command_line.GetSwitchValueASCII("field_trial_handle"));
155 size_t field_trial_length = std::stoi(
156 command_line.GetSwitchValueASCII("field_trial_length"));
Alexei Svitkine (slow) 2016/10/03 15:28:05 I suggest using a single flag whose value is the p
lawrencewu 2016/10/03 21:36:11 Done.
157
158 HANDLE handle = reinterpret_cast<HANDLE>(field_trial_handle);
159 base::SharedMemoryHandle shm_handle = base::SharedMemoryHandle(
160 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),
Alexei Svitkine (slow) 2016/10/03 15:28:05 When wrapping indent 4, not 2. You can possibly ju
lawrencewu 2016/10/03 21:36:11 Done. git cl format++
168 std::set<std::string>());
169 DCHECK(result);
170 }
171 #else
Alexei Svitkine (slow) 2016/10/03 15:28:05 Nit: ifdefs shouldn't be indented.
lawrencewu 2016/10/03 21:36:11 Done.
149 if (command_line.HasSwitch(switches::kForceFieldTrials)) { 172 if (command_line.HasSwitch(switches::kForceFieldTrials)) {
150 bool result = base::FieldTrialList::CreateTrialsFromString( 173 bool result = base::FieldTrialList::CreateTrialsFromString(
151 command_line.GetSwitchValueASCII(switches::kForceFieldTrials), 174 command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
152 std::set<std::string>()); 175 std::set<std::string>());
153 DCHECK(result); 176 DCHECK(result);
154 } 177 }
178 #endif
155 179
156 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 180 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
157 feature_list->InitializeFromCommandLine( 181 feature_list->InitializeFromCommandLine(
158 command_line.GetSwitchValueASCII(switches::kEnableFeatures), 182 command_line.GetSwitchValueASCII(switches::kEnableFeatures),
159 command_line.GetSwitchValueASCII(switches::kDisableFeatures)); 183 command_line.GetSwitchValueASCII(switches::kDisableFeatures));
160 base::FeatureList::SetInstance(std::move(feature_list)); 184 base::FeatureList::SetInstance(std::move(feature_list));
161 } 185 }
162 186
163 } // namespace 187 } // namespace
164 188
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 866
843 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 867 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
844 }; 868 };
845 869
846 // static 870 // static
847 ContentMainRunner* ContentMainRunner::Create() { 871 ContentMainRunner* ContentMainRunner::Create() {
848 return new ContentMainRunnerImpl(); 872 return new ContentMainRunnerImpl();
849 } 873 }
850 874
851 } // namespace content 875 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698