Commit 3aada460 authored by tony@chromium.org's avatar tony@chromium.org

Move code around in browser_main.cc.

- Move SetSocketReusePolicy down into the existing, larger anonymous
  namespace.
- Move AddPreReadHistogramTime into the anonymous namespace.
- Add function declaration for SetSocketReusePolicy because it's used in
  BrowserMainParts, but defined in the anonymous namespace which comes
  afterwards (maybe we should move the anonymous namespace up?).
- Move RecordPreReadExperimentTime to the end of the file (it's declared
  at the end of browser_main.h, so that seems more consistent).


Review URL: http://codereview.chromium.org/7623022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96472 0039d316-1c4b-4281-b951-d872f2087c98
parent c1dd346f
......@@ -212,63 +212,15 @@
#include "views/touchui/touch_factory.h"
#endif
namespace {
void SetSocketReusePolicy(int warmest_socket_trial_group,
const int socket_policy[],
int num_groups) {
const int* result = std::find(socket_policy, socket_policy + num_groups,
warmest_socket_trial_group);
DCHECK_NE(result, socket_policy + num_groups)
<< "Not a valid socket reuse policy group";
net::SetSocketReusePolicy(result - socket_policy);
}
}
namespace net {
class NetLog;
} // namespace net
// This code is specific to the Windows-only PreReadExperiment field-trial.
static void AddPreReadHistogramTime(const char* name, base::TimeDelta time) {
const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1));
const base::TimeDelta kMax(base::TimeDelta::FromHours(1));
static const size_t kBuckets(100);
// FactoryTimeGet will always return a pointer to the same histogram object,
// keyed on its name. There's no need for us to store it explicitly anywhere.
base::Histogram* counter = base::Histogram::FactoryTimeGet(
name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag);
counter->AddTime(time);
}
// This code is specific to the Windows-only PreReadExperiment field-trial.
void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) {
DCHECK(name != NULL);
// This gets called with different histogram names, so we don't want to use
// the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the
// first call wins.
AddPreReadHistogramTime(name, time);
#if defined(OS_WIN)
static const char kEnvVar[] = "CHROME_PRE_READ_EXPERIMENT";
// The pre-read experiment is Windows specific.
scoped_ptr<base::Environment> env(base::Environment::Create());
DCHECK(env.get() != NULL);
// Only record the sub-histogram result if the experiment is running
// (environment variable is set, and valid).
std::string pre_read;
if (env->GetVar(kEnvVar, &pre_read) && (pre_read == "0" || pre_read == "1")) {
std::string uma_name(name);
uma_name += "_PreRead";
uma_name += pre_read == "1" ? "Enabled" : "Disabled";
AddPreReadHistogramTime(uma_name.c_str(), time);
}
#endif
}
namespace {
void SetSocketReusePolicy(int warmest_socket_trial_group,
const int socket_policy[],
int num_groups);
} // namespace
// BrowserMainParts ------------------------------------------------------------
......@@ -1265,30 +1217,29 @@ void RegisterTranslateableItems(void) {
}
#endif // defined(OS_CHROMEOS)
} // namespace
#if defined(OS_CHROMEOS)
// Allows authenticator to be invoked without adding refcounting. The instances
// will delete themselves upon completion.
DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin);
#endif
void SetSocketReusePolicy(int warmest_socket_trial_group,
const int socket_policy[],
int num_groups) {
const int* result = std::find(socket_policy, socket_policy + num_groups,
warmest_socket_trial_group);
DCHECK_NE(result, socket_policy + num_groups)
<< "Not a valid socket reuse policy group";
net::SetSocketReusePolicy(result - socket_policy);
}
#if defined(OS_WIN)
#define DLLEXPORT __declspec(dllexport)
// This code is specific to the Windows-only PreReadExperiment field-trial.
void AddPreReadHistogramTime(const char* name, base::TimeDelta time) {
const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1));
const base::TimeDelta kMax(base::TimeDelta::FromHours(1));
static const size_t kBuckets(100);
// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
extern "C" {
DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
}
// FactoryTimeGet will always return a pointer to the same histogram object,
// keyed on its name. There's no need for us to store it explicitly anywhere.
base::Histogram* counter = base::Histogram::FactoryTimeGet(
name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag);
DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
// Need an instance of AtExitManager to handle singleton creations and
// deletions. We need this new instance because, the old instance created
// in ChromeMain() got destructed when the function returned.
base::AtExitManager exit_manager;
upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
counter->AddTime(time);
}
#endif
#if defined(USE_LINUX_BREAKPAD)
bool IsCrashReportingEnabled(const PrefService* local_state) {
......@@ -1321,6 +1272,31 @@ bool IsCrashReportingEnabled(const PrefService* local_state) {
}
#endif // #if defined(USE_LINUX_BREAKPAD)
} // namespace
#if defined(OS_CHROMEOS)
// Allows authenticator to be invoked without adding refcounting. The instances
// will delete themselves upon completion.
DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin);
#endif
#if defined(OS_WIN)
#define DLLEXPORT __declspec(dllexport)
// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
extern "C" {
DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
}
DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
// Need an instance of AtExitManager to handle singleton creations and
// deletions. We need this new instance because, the old instance created
// in ChromeMain() got destructed when the function returned.
base::AtExitManager exit_manager;
upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
}
#endif
// Main routine for running as the Browser process.
int BrowserMain(const MainFunctionParams& parameters) {
TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, "");
......@@ -2165,3 +2141,31 @@ int BrowserMain(const MainFunctionParams& parameters) {
TRACE_EVENT_END_ETW("BrowserMain", 0, 0);
return result_code;
}
// This code is specific to the Windows-only PreReadExperiment field-trial.
void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) {
DCHECK(name != NULL);
// This gets called with different histogram names, so we don't want to use
// the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the
// first call wins.
AddPreReadHistogramTime(name, time);
#if defined(OS_WIN)
static const char kEnvVar[] = "CHROME_PRE_READ_EXPERIMENT";
// The pre-read experiment is Windows specific.
scoped_ptr<base::Environment> env(base::Environment::Create());
DCHECK(env.get() != NULL);
// Only record the sub-histogram result if the experiment is running
// (environment variable is set, and valid).
std::string pre_read;
if (env->GetVar(kEnvVar, &pre_read) && (pre_read == "0" || pre_read == "1")) {
std::string uma_name(name);
uma_name += "_PreRead";
uma_name += pre_read == "1" ? "Enabled" : "Disabled";
AddPreReadHistogramTime(uma_name.c_str(), time);
}
#endif
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment