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

Side by Side Diff: base/metrics/field_trial.h

Issue 2546653002: Store and retrieve features from shared memory (Closed)
Patch Set: asvitkine@ comments Created 4 years 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 // FieldTrial is a class for handling details of statistical experiments 5 // FieldTrial is a class for handling details of statistical experiments
6 // performed by actual users in the field (i.e., in a shipped or beta product). 6 // performed by actual users in the field (i.e., in a shipped or beta product).
7 // All code is called exclusively on the UI thread currently. 7 // All code is called exclusively on the UI thread currently.
8 // 8 //
9 // The simplest example is an experiment to see whether one of two options 9 // The simplest example is an experiment to see whether one of two options
10 // produces "better" results across our user population. In that scenario, UMA 10 // produces "better" results across our user population. In that scenario, UMA
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include <stdint.h> 58 #include <stdint.h>
59 59
60 #include <map> 60 #include <map>
61 #include <memory> 61 #include <memory>
62 #include <set> 62 #include <set>
63 #include <string> 63 #include <string>
64 #include <vector> 64 #include <vector>
65 65
66 #include "base/base_export.h" 66 #include "base/base_export.h"
67 #include "base/command_line.h" 67 #include "base/command_line.h"
68 #include "base/feature_list.h"
68 #include "base/files/file.h" 69 #include "base/files/file.h"
69 #include "base/gtest_prod_util.h" 70 #include "base/gtest_prod_util.h"
70 #include "base/macros.h" 71 #include "base/macros.h"
71 #include "base/memory/ref_counted.h" 72 #include "base/memory/ref_counted.h"
72 #include "base/memory/shared_memory.h" 73 #include "base/memory/shared_memory.h"
73 #include "base/metrics/persistent_memory_allocator.h" 74 #include "base/metrics/persistent_memory_allocator.h"
74 #include "base/observer_list_threadsafe.h" 75 #include "base/observer_list_threadsafe.h"
75 #include "base/process/launch.h" 76 #include "base/process/launch.h"
76 #include "base/strings/string_piece.h" 77 #include "base/strings/string_piece.h"
77 #include "base/synchronization/lock.h" 78 #include "base/synchronization/lock.h"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 // handle or command line argument. A bit of a misnomer since on POSIX we 501 // handle or command line argument. A bit of a misnomer since on POSIX we
501 // simply get the trials from opening |fd_key| if using shared memory. On 502 // simply get the trials from opening |fd_key| if using shared memory. On
502 // Windows, we expect the |cmd_line| switch for |field_trial_handle_switch| to 503 // Windows, we expect the |cmd_line| switch for |field_trial_handle_switch| to
503 // contain the shared memory handle that contains the field trial allocator. 504 // contain the shared memory handle that contains the field trial allocator.
504 // We need the |field_trial_handle_switch| and |fd_key| arguments to be passed 505 // We need the |field_trial_handle_switch| and |fd_key| arguments to be passed
505 // in since base/ can't depend on content/. 506 // in since base/ can't depend on content/.
506 static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line, 507 static void CreateTrialsFromCommandLine(const base::CommandLine& cmd_line,
507 const char* field_trial_handle_switch, 508 const char* field_trial_handle_switch,
508 int fd_key); 509 int fd_key);
509 510
511 // Creates base::Feature overrides from the command line by first trying to
512 // use shared memory and then falling back to the command line if it fails.
513 static void CreateFeaturesFromCommandLine(
514 const base::CommandLine& command_line,
515 const char* enable_features_switch,
516 const char* disable_features_switch,
517 FeatureList* feature_list);
518
510 #if defined(OS_WIN) 519 #if defined(OS_WIN)
511 // On Windows, we need to explicitly pass down any handles to be inherited. 520 // On Windows, we need to explicitly pass down any handles to be inherited.
512 // This function adds the shared memory handle to field trial state to the 521 // This function adds the shared memory handle to field trial state to the
513 // list of handles to be inherited. 522 // list of handles to be inherited.
514 static void AppendFieldTrialHandleIfNeeded( 523 static void AppendFieldTrialHandleIfNeeded(
515 base::HandlesToInheritVector* handles); 524 base::HandlesToInheritVector* handles);
516 #elif defined(OS_POSIX) 525 #elif defined(OS_POSIX)
517 // On POSIX, we also need to explicitly pass down this file descriptor that 526 // On POSIX, we also need to explicitly pass down this file descriptor that
518 // should be shared with the child process. Returns kInvalidPlatformFile if no 527 // should be shared with the child process. Returns kInvalidPlatformFile if no
519 // handle exists or was not initialized properly. 528 // handle exists or was not initialized properly.
520 static PlatformFile GetFieldTrialHandle(); 529 static PlatformFile GetFieldTrialHandle();
521 #endif 530 #endif
522 531
523 // Adds a switch to the command line containing the field trial state as a 532 // Adds a switch to the command line containing the field trial state as a
524 // string (if not using shared memory to share field trial state), or the 533 // string (if not using shared memory to share field trial state), or the
525 // shared memory handle + length. 534 // shared memory handle + length.
526 // Needs the |field_trial_handle_switch| argument to be passed in since base/ 535 // Needs the |field_trial_handle_switch| argument to be passed in since base/
527 // can't depend on content/. 536 // can't depend on content/.
528 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch, 537 static void CopyFieldTrialStateToFlags(const char* field_trial_handle_switch,
538 const char* enable_features_switch,
539 const char* disable_features_switch,
529 base::CommandLine* cmd_line); 540 base::CommandLine* cmd_line);
530 541
531 // Create a FieldTrial with the given |name| and using 100% probability for 542 // Create a FieldTrial with the given |name| and using 100% probability for
532 // the FieldTrial, force FieldTrial to have the same group string as 543 // the FieldTrial, force FieldTrial to have the same group string as
533 // |group_name|. This is commonly used in a non-browser process, to carry 544 // |group_name|. This is commonly used in a non-browser process, to carry
534 // randomly selected state in a browser process into this non-browser process. 545 // randomly selected state in a browser process into this non-browser process.
535 // It returns NULL if there is a FieldTrial that is already registered with 546 // It returns NULL if there is a FieldTrial that is already registered with
536 // the same |name| but has different finalized group string (|group_name|). 547 // the same |name| but has different finalized group string (|group_name|).
537 static FieldTrial* CreateFieldTrial(const std::string& name, 548 static FieldTrial* CreateFieldTrial(const std::string& name,
538 const std::string& group_name); 549 const std::string& group_name);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 662
652 // Tracks whether CreateTrialsFromCommandLine() has been called. 663 // Tracks whether CreateTrialsFromCommandLine() has been called.
653 bool create_trials_from_command_line_called_ = false; 664 bool create_trials_from_command_line_called_ = false;
654 665
655 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 666 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
656 }; 667 };
657 668
658 } // namespace base 669 } // namespace base
659 670
660 #endif // BASE_METRICS_FIELD_TRIAL_H_ 671 #endif // BASE_METRICS_FIELD_TRIAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698