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/first_run_controller.h" | 5 #include "chrome/browser/chromeos/first_run/first_run_controller.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | |
10 #include "chrome/browser/chromeos/first_run/first_run_view.h" | 11 #include "chrome/browser/chromeos/first_run/first_run_view.h" |
12 #include "chrome/browser/chromeos/first_run/metrics.h" | |
11 #include "chrome/browser/chromeos/first_run/steps/app_list_step.h" | 13 #include "chrome/browser/chromeos/first_run/steps/app_list_step.h" |
12 #include "chrome/browser/chromeos/first_run/steps/help_step.h" | 14 #include "chrome/browser/chromeos/first_run/steps/help_step.h" |
13 #include "chrome/browser/chromeos/first_run/steps/tray_step.h" | 15 #include "chrome/browser/chromeos/first_run/steps/tray_step.h" |
14 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
15 #include "chrome/browser/ui/chrome_pages.h" | 17 #include "chrome/browser/ui/chrome_pages.h" |
16 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 size_t NONE_STEP_INDEX = std::numeric_limits<size_t>::max(); | 22 size_t NONE_STEP_INDEX = std::numeric_limits<size_t>::max(); |
21 | 23 |
22 // Instance of currently running controller, or NULL if controller is not | 24 // Instance of currently running controller, or NULL if controller is not |
23 // running now. | 25 // running now. |
24 chromeos::FirstRunController* g_instance; | 26 chromeos::FirstRunController* g_instance; |
25 | 27 |
28 void RecordCompletion(chromeos::first_run::TutorialCompletion type) { | |
29 UMA_HISTOGRAM_ENUMERATION("CrosFirstRun.TutorialCompletion", | |
30 type, | |
31 chromeos::first_run::kTutorialCompletionSize); | |
32 } | |
33 | |
26 } // namespace | 34 } // namespace |
27 | 35 |
28 namespace chromeos { | 36 namespace chromeos { |
29 | 37 |
30 FirstRunController::~FirstRunController() {} | 38 FirstRunController::~FirstRunController() {} |
31 | 39 |
32 // static | 40 // static |
33 void FirstRunController::Start() { | 41 void FirstRunController::Start() { |
34 if (g_instance) { | 42 if (g_instance) { |
35 LOG(WARNING) << "First-run tutorial is running already."; | 43 LOG(WARNING) << "First-run tutorial is running already."; |
(...skipping 18 matching lines...) Expand all Loading... | |
54 return g_instance; | 62 return g_instance; |
55 } | 63 } |
56 | 64 |
57 FirstRunController::FirstRunController() | 65 FirstRunController::FirstRunController() |
58 : actor_(NULL), | 66 : actor_(NULL), |
59 current_step_index_(NONE_STEP_INDEX), | 67 current_step_index_(NONE_STEP_INDEX), |
60 user_profile_(NULL) { | 68 user_profile_(NULL) { |
61 } | 69 } |
62 | 70 |
63 void FirstRunController::Init() { | 71 void FirstRunController::Init() { |
72 start_time_ = base::Time::Now(); | |
64 UserManager* user_manager = UserManager::Get(); | 73 UserManager* user_manager = UserManager::Get(); |
65 user_profile_ = user_manager->GetProfileByUser(user_manager->GetActiveUser()); | 74 user_profile_ = user_manager->GetProfileByUser(user_manager->GetActiveUser()); |
66 | 75 |
67 shell_helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper()); | 76 shell_helper_.reset(ash::Shell::GetInstance()->CreateFirstRunHelper()); |
68 shell_helper_->AddObserver(this); | 77 shell_helper_->AddObserver(this); |
69 | 78 |
70 FirstRunView* view = new FirstRunView(); | 79 FirstRunView* view = new FirstRunView(); |
71 view->Init(user_profile_); | 80 view->Init(user_profile_); |
72 shell_helper_->GetOverlayWidget()->SetContentsView(view); | 81 shell_helper_->GetOverlayWidget()->SetContentsView(view); |
73 actor_ = view->GetActor(); | 82 actor_ = view->GetActor(); |
74 actor_->set_delegate(this); | 83 actor_->set_delegate(this); |
75 shell_helper_->GetOverlayWidget()->Show(); | 84 shell_helper_->GetOverlayWidget()->Show(); |
76 view->RequestFocus(); | 85 view->RequestFocus(); |
77 web_contents_for_tests_ = view->GetWebContents(); | 86 web_contents_for_tests_ = view->GetWebContents(); |
78 | 87 |
79 if (actor_->IsInitialized()) | 88 if (actor_->IsInitialized()) |
80 OnActorInitialized(); | 89 OnActorInitialized(); |
81 } | 90 } |
82 | 91 |
83 void FirstRunController::Finalize() { | 92 void FirstRunController::Finalize() { |
93 int furthest_step = current_step_index_ == NONE_STEP_INDEX | |
94 ? steps_.size() - 1 | |
95 : current_step_index_; | |
96 UMA_HISTOGRAM_ENUMERATION( | |
97 "CrosFirstRun.FurthestStep", furthest_step, steps_.size()); | |
Alexei Svitkine (slow)
2014/01/15 16:02:38
Nit: Can you wrap this consistently with the next
dzhioev (left Google)
2014/01/15 22:12:54
Done.
| |
98 UMA_HISTOGRAM_MEDIUM_TIMES("CrosFirstRun.TimeSpent", | |
99 base::Time::Now() - start_time_); | |
84 if (GetCurrentStep()) | 100 if (GetCurrentStep()) |
85 GetCurrentStep()->OnBeforeHide(); | 101 GetCurrentStep()->OnBeforeHide(); |
86 steps_.clear(); | 102 steps_.clear(); |
87 if (actor_) | 103 if (actor_) |
88 actor_->set_delegate(NULL); | 104 actor_->set_delegate(NULL); |
89 actor_ = NULL; | 105 actor_ = NULL; |
90 shell_helper_->RemoveObserver(this); | 106 shell_helper_->RemoveObserver(this); |
91 shell_helper_.reset(); | 107 shell_helper_.reset(); |
92 } | 108 } |
93 | 109 |
94 void FirstRunController::OnActorInitialized() { | 110 void FirstRunController::OnActorInitialized() { |
95 RegisterSteps(); | 111 RegisterSteps(); |
96 ShowNextStep(); | 112 ShowNextStep(); |
97 } | 113 } |
98 | 114 |
99 void FirstRunController::OnNextButtonClicked(const std::string& step_name) { | 115 void FirstRunController::OnNextButtonClicked(const std::string& step_name) { |
100 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); | 116 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); |
101 GetCurrentStep()->OnBeforeHide(); | 117 GetCurrentStep()->OnBeforeHide(); |
102 actor_->HideCurrentStep(); | 118 actor_->HideCurrentStep(); |
103 } | 119 } |
104 | 120 |
105 void FirstRunController::OnHelpButtonClicked() { | 121 void FirstRunController::OnHelpButtonClicked() { |
122 RecordCompletion(first_run::kTutorialCompletedWithKeepExploring); | |
106 on_actor_finalized_ = base::Bind(chrome::ShowHelpForProfile, | 123 on_actor_finalized_ = base::Bind(chrome::ShowHelpForProfile, |
107 user_profile_, | 124 user_profile_, |
108 chrome::HOST_DESKTOP_TYPE_ASH, | 125 chrome::HOST_DESKTOP_TYPE_ASH, |
109 chrome::HELP_SOURCE_MENU); | 126 chrome::HELP_SOURCE_MENU); |
110 actor_->Finalize(); | 127 actor_->Finalize(); |
111 } | 128 } |
112 | 129 |
113 void FirstRunController::OnStepHidden(const std::string& step_name) { | 130 void FirstRunController::OnStepHidden(const std::string& step_name) { |
114 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); | 131 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); |
115 GetCurrentStep()->OnAfterHide(); | 132 GetCurrentStep()->OnAfterHide(); |
(...skipping 12 matching lines...) Expand all Loading... | |
128 } | 145 } |
129 | 146 |
130 void FirstRunController::OnActorDestroyed() { | 147 void FirstRunController::OnActorDestroyed() { |
131 // Normally this shouldn't happen because we are implicitly controlling | 148 // Normally this shouldn't happen because we are implicitly controlling |
132 // actor's lifetime. | 149 // actor's lifetime. |
133 NOTREACHED() << | 150 NOTREACHED() << |
134 "FirstRunActor destroyed before FirstRunController::Finalize."; | 151 "FirstRunActor destroyed before FirstRunController::Finalize."; |
135 } | 152 } |
136 | 153 |
137 void FirstRunController::OnCancelled() { | 154 void FirstRunController::OnCancelled() { |
155 RecordCompletion(first_run::kTutorialNotFinished); | |
138 Stop(); | 156 Stop(); |
139 } | 157 } |
140 | 158 |
141 void FirstRunController::RegisterSteps() { | 159 void FirstRunController::RegisterSteps() { |
142 steps_.push_back(make_linked_ptr( | 160 steps_.push_back(make_linked_ptr( |
143 new first_run::AppListStep(shell_helper_.get(), actor_))); | 161 new first_run::AppListStep(shell_helper_.get(), actor_))); |
144 steps_.push_back(make_linked_ptr( | 162 steps_.push_back(make_linked_ptr( |
145 new first_run::TrayStep(shell_helper_.get(), actor_))); | 163 new first_run::TrayStep(shell_helper_.get(), actor_))); |
146 steps_.push_back(make_linked_ptr( | 164 steps_.push_back(make_linked_ptr( |
147 new first_run::HelpStep(shell_helper_.get(), actor_))); | 165 new first_run::HelpStep(shell_helper_.get(), actor_))); |
148 } | 166 } |
149 | 167 |
150 void FirstRunController::ShowNextStep() { | 168 void FirstRunController::ShowNextStep() { |
151 AdvanceStep(); | 169 AdvanceStep(); |
152 if (GetCurrentStep()) | 170 if (!GetCurrentStep()) { |
153 GetCurrentStep()->Show(); | |
154 else | |
155 actor_->Finalize(); | 171 actor_->Finalize(); |
172 RecordCompletion(first_run::kTutorialCompletedWithGotIt); | |
173 return; | |
174 } | |
175 GetCurrentStep()->Show(); | |
156 } | 176 } |
157 | 177 |
158 void FirstRunController::AdvanceStep() { | 178 void FirstRunController::AdvanceStep() { |
159 if (current_step_index_ == NONE_STEP_INDEX) | 179 if (current_step_index_ == NONE_STEP_INDEX) |
160 current_step_index_ = 0; | 180 current_step_index_ = 0; |
161 else | 181 else |
162 ++current_step_index_; | 182 ++current_step_index_; |
163 if (current_step_index_ >= steps_.size()) | 183 if (current_step_index_ >= steps_.size()) |
164 current_step_index_ = NONE_STEP_INDEX; | 184 current_step_index_ = NONE_STEP_INDEX; |
165 } | 185 } |
166 | 186 |
167 first_run::Step* FirstRunController::GetCurrentStep() const { | 187 first_run::Step* FirstRunController::GetCurrentStep() const { |
168 return current_step_index_ != NONE_STEP_INDEX ? | 188 return current_step_index_ != NONE_STEP_INDEX ? |
169 steps_[current_step_index_].get() : NULL; | 189 steps_[current_step_index_].get() : NULL; |
170 } | 190 } |
171 | 191 |
172 } // namespace chromeos | 192 } // namespace chromeos |
173 | 193 |
OLD | NEW |