Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / first_run / step.cc
blob77530749cca2fffa8761f492da93397f2738d3af
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.
5 #include "chrome/browser/chromeos/first_run/step.h"
7 #include <cctype>
9 #include "ash/first_run/first_run_helper.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/histogram.h"
12 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/views/widget/widget.h"
16 namespace {
18 // Converts from "with-dashes-names" to "WithDashesNames".
19 std::string ToCamelCase(const std::string& name) {
20 std::string result;
21 bool next_to_upper = true;
22 for (size_t i = 0; i < name.length(); ++i) {
23 if (name[i] == '-') {
24 next_to_upper = true;
25 } else if (next_to_upper) {
26 result.push_back(std::toupper(name[i]));
27 next_to_upper = false;
28 } else {
29 result.push_back(name[i]);
32 return result;
35 } // namespace
37 namespace chromeos {
38 namespace first_run {
40 Step::Step(const std::string& name,
41 ash::FirstRunHelper* shell_helper,
42 FirstRunActor* actor)
43 : name_(name),
44 shell_helper_(shell_helper),
45 actor_(actor) {
48 Step::~Step() { RecordCompletion(); }
50 void Step::Show() {
51 show_time_ = base::Time::Now();
52 DoShow();
55 void Step::OnBeforeHide() {
56 actor()->RemoveBackgroundHoles();
57 DoOnBeforeHide();
60 void Step::OnAfterHide() {
61 RecordCompletion();
62 DoOnAfterHide();
65 gfx::Size Step::GetOverlaySize() const {
66 return shell_helper()->GetOverlayWidget()->GetWindowBoundsInScreen().size();
69 void Step::RecordCompletion() {
70 if (show_time_.is_null())
71 return;
72 std::string histogram_name =
73 "CrosFirstRun.TimeSpentOnStep" + ToCamelCase(name());
74 // Equivalent to using UMA_HISTOGRAM_CUSTOM_TIMES with 50 buckets on range
75 // [100ms, 3 min.]. UMA_HISTOGRAM_CUSTOM_TIMES can not be used here, because
76 // |histogram_name| is calculated dynamically and changes from call to call.
77 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
78 histogram_name,
79 base::TimeDelta::FromMilliseconds(100),
80 base::TimeDelta::FromMinutes(3),
81 50,
82 base::HistogramBase::kUmaTargetedHistogramFlag);
83 histogram->AddTime(base::Time::Now() - show_time_);
84 show_time_ = base::Time();
87 } // namespace first_run
88 } // namespace chromeos