OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/first_run/step.h" | 5 #include "chrome/browser/chromeos/first_run/step.h" |
6 | 6 |
| 7 #include <cctype> |
| 8 |
7 #include "ash/first_run/first_run_helper.h" | 9 #include "ash/first_run/first_run_helper.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h" | 12 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h" |
9 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
10 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
11 | 15 |
| 16 namespace { |
| 17 |
| 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]); |
| 30 } |
| 31 } |
| 32 return result; |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
12 namespace chromeos { | 37 namespace chromeos { |
13 namespace first_run { | 38 namespace first_run { |
14 | 39 |
15 Step::Step(const std::string& name, | 40 Step::Step(const std::string& name, |
16 ash::FirstRunHelper* shell_helper, | 41 ash::FirstRunHelper* shell_helper, |
17 FirstRunActor* actor) | 42 FirstRunActor* actor) |
18 : name_(name), | 43 : name_(name), |
19 shell_helper_(shell_helper), | 44 shell_helper_(shell_helper), |
20 actor_(actor) { | 45 actor_(actor) { |
21 } | 46 } |
22 | 47 |
23 Step::~Step() {} | 48 Step::~Step() { RecordCompletion(); } |
| 49 |
| 50 void Step::Show() { |
| 51 show_time_ = base::Time::Now(); |
| 52 DoShow(); |
| 53 } |
24 | 54 |
25 void Step::OnBeforeHide() { | 55 void Step::OnBeforeHide() { |
26 actor()->RemoveBackgroundHoles(); | 56 actor()->RemoveBackgroundHoles(); |
| 57 DoOnBeforeHide(); |
27 } | 58 } |
28 | 59 |
29 void Step::OnAfterHide() { | 60 void Step::OnAfterHide() { |
| 61 RecordCompletion(); |
| 62 DoOnAfterHide(); |
30 } | 63 } |
31 | 64 |
32 gfx::Size Step::GetOverlaySize() const { | 65 gfx::Size Step::GetOverlaySize() const { |
33 return shell_helper()->GetOverlayWidget()->GetWindowBoundsInScreen().size(); | 66 return shell_helper()->GetOverlayWidget()->GetWindowBoundsInScreen().size(); |
34 } | 67 } |
35 | 68 |
| 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(); |
| 85 } |
| 86 |
36 } // namespace first_run | 87 } // namespace first_run |
37 } // namespace chromeos | 88 } // namespace chromeos |
38 | 89 |
OLD | NEW |