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

Unified Diff: base/metrics/field_trial.cc

Issue 2961333002: Fix field trials not working in utility processes. (Closed)
Patch Set: review comment Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/process/process_info.h » ('j') | base/process/process_info_win.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.cc
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index f3c16d2a1ae865f3880fbf06217c6ab9dd80f4aa..dddc29100d241d5ebfab62673eb930c42c61f3aa 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -14,6 +14,8 @@
#include "base/logging.h"
#include "base/metrics/field_trial_param_associator.h"
#include "base/process/memory.h"
+#include "base/process/process_handle.h"
+#include "base/process/process_info.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
@@ -1142,6 +1144,17 @@ SharedMemoryHandle DeserializeImpl(const std::string& switch_value) {
if (!base::StringToInt(tokens[0], &field_trial_handle))
return SharedMemoryHandle();
RawHandle handle = reinterpret_cast<RawHandle>(field_trial_handle);
+#if defined(OS_WIN)
+ if (base::IsCurrentProcessElevated()) {
+ // base::LaunchElevatedProcess doesn't have a way to duplicate the handle,
+ // but this process can since by definition it's not sandboxed.
+ base::ProcessId parent_pid = base::GetParentProcessId(GetCurrentProcess());
+ HANDLE parent_handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, parent_pid);
+ DuplicateHandle(parent_handle, handle, GetCurrentProcess(), &handle, 0,
+ FALSE, DUPLICATE_SAME_ACCESS);
+ CloseHandle(parent_handle);
+ }
(unused - use chromium) 2017/06/30 16:15:18 Having OS-dependent elevantion-level-dependent cod
Alexei Svitkine (slow) 2017/06/30 16:20:37 I agree this is not ideal. But I don't have a sugg
+#endif
base::UnguessableToken guid;
if (!DeserializeGUIDFromStringPieces(tokens[1], tokens[2], &guid))
« no previous file with comments | « no previous file | base/process/process_info.h » ('j') | base/process/process_info_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698