app_list_service.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/app_list/app_list_service.h"
6
7#include "base/command_line.h"
8#include "base/metrics/histogram.h"
9#include "base/prefs/pref_registry_simple.h"
10#include "base/process_info.h"
11#include "base/strings/string_number_conversions.h"
12#include "base/time.h"
13#include "chrome/common/chrome_switches.h"
14#include "chrome/common/pref_names.h"
15
16namespace {
17
18base::TimeDelta GetTimeFromOriginalProcessStart(
19    const CommandLine& command_line) {
20  std::string start_time_string =
21      command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime);
22  int64 remote_start_time;
23  base::StringToInt64(start_time_string, &remote_start_time);
24  return base::Time::Now() - base::Time::FromInternalValue(remote_start_time);
25}
26
27}
28
29// static
30void AppListService::RegisterPrefs(PrefRegistrySimple* registry) {
31  registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0);
32  registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0);
33  registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0);
34  registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0);
35  registry->RegisterStringPref(prefs::kAppListProfile, std::string());
36  registry->RegisterBooleanPref(prefs::kRestartWithAppList, false);
37}
38
39// static
40void AppListService::RecordShowTimings(const CommandLine& command_line) {
41  // The presence of kOriginalProcessStartTime implies that another process
42  // has sent us its command line to handle, ie: we are already running.
43  if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) {
44     UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart",
45                              GetTimeFromOriginalProcessStart(command_line));
46  } else {
47    // base::CurrentProcessInfo::CreationTime() is only defined on win/mac.
48#if defined(OS_WIN) || defined(OS_MACOSX)
49    UMA_HISTOGRAM_LONG_TIMES(
50        "Startup.ShowAppListColdStart",
51        base::Time::Now() - *base::CurrentProcessInfo::CreationTime());
52#endif
53  }
54}
55