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"
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"
18 // Converts from "with-dashes-names" to "WithDashesNames".
19 std::string
ToCamelCase(const std::string
& name
) {
21 bool next_to_upper
= true;
22 for (size_t i
= 0; i
< name
.length(); ++i
) {
25 } else if (next_to_upper
) {
26 result
.push_back(std::toupper(name
[i
]));
27 next_to_upper
= false;
29 result
.push_back(name
[i
]);
40 Step::Step(const std::string
& name
,
41 ash::FirstRunHelper
* shell_helper
,
44 shell_helper_(shell_helper
),
48 Step::~Step() { RecordCompletion(); }
51 show_time_
= base::Time::Now();
55 void Step::OnBeforeHide() {
56 actor()->RemoveBackgroundHoles();
60 void Step::OnAfterHide() {
65 gfx::Size
Step::GetOverlaySize() const {
66 return shell_helper()->GetOverlayWidget()->GetWindowBoundsInScreen().size();
69 void Step::RecordCompletion() {
70 if (show_time_
.is_null())
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(
79 base::TimeDelta::FromMilliseconds(100),
80 base::TimeDelta::FromMinutes(3),
82 base::HistogramBase::kUmaTargetedHistogramFlag
);
83 histogram
->AddTime(base::Time::Now() - show_time_
);
84 show_time_
= base::Time();
87 } // namespace first_run
88 } // namespace chromeos