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("CrosFirstRun.FurthestStep", |
| 97 furthest_step, |
| 98 steps_.size()); |
| 99 UMA_HISTOGRAM_MEDIUM_TIMES("CrosFirstRun.TimeSpent", |
| 100 base::Time::Now() - start_time_); |
84 if (GetCurrentStep()) | 101 if (GetCurrentStep()) |
85 GetCurrentStep()->OnBeforeHide(); | 102 GetCurrentStep()->OnBeforeHide(); |
86 steps_.clear(); | 103 steps_.clear(); |
87 if (actor_) | 104 if (actor_) |
88 actor_->set_delegate(NULL); | 105 actor_->set_delegate(NULL); |
89 actor_ = NULL; | 106 actor_ = NULL; |
90 shell_helper_->RemoveObserver(this); | 107 shell_helper_->RemoveObserver(this); |
91 shell_helper_.reset(); | 108 shell_helper_.reset(); |
92 } | 109 } |
93 | 110 |
94 void FirstRunController::OnActorInitialized() { | 111 void FirstRunController::OnActorInitialized() { |
95 RegisterSteps(); | 112 RegisterSteps(); |
96 ShowNextStep(); | 113 ShowNextStep(); |
97 } | 114 } |
98 | 115 |
99 void FirstRunController::OnNextButtonClicked(const std::string& step_name) { | 116 void FirstRunController::OnNextButtonClicked(const std::string& step_name) { |
100 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); | 117 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); |
101 GetCurrentStep()->OnBeforeHide(); | 118 GetCurrentStep()->OnBeforeHide(); |
102 actor_->HideCurrentStep(); | 119 actor_->HideCurrentStep(); |
103 } | 120 } |
104 | 121 |
105 void FirstRunController::OnHelpButtonClicked() { | 122 void FirstRunController::OnHelpButtonClicked() { |
| 123 RecordCompletion(first_run::kTutorialCompletedWithKeepExploring); |
106 on_actor_finalized_ = base::Bind(chrome::ShowHelpForProfile, | 124 on_actor_finalized_ = base::Bind(chrome::ShowHelpForProfile, |
107 user_profile_, | 125 user_profile_, |
108 chrome::HOST_DESKTOP_TYPE_ASH, | 126 chrome::HOST_DESKTOP_TYPE_ASH, |
109 chrome::HELP_SOURCE_MENU); | 127 chrome::HELP_SOURCE_MENU); |
110 actor_->Finalize(); | 128 actor_->Finalize(); |
111 } | 129 } |
112 | 130 |
113 void FirstRunController::OnStepHidden(const std::string& step_name) { | 131 void FirstRunController::OnStepHidden(const std::string& step_name) { |
114 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); | 132 DCHECK(GetCurrentStep() && GetCurrentStep()->name() == step_name); |
115 GetCurrentStep()->OnAfterHide(); | 133 GetCurrentStep()->OnAfterHide(); |
(...skipping 12 matching lines...) Expand all Loading... |
128 } | 146 } |
129 | 147 |
130 void FirstRunController::OnActorDestroyed() { | 148 void FirstRunController::OnActorDestroyed() { |
131 // Normally this shouldn't happen because we are implicitly controlling | 149 // Normally this shouldn't happen because we are implicitly controlling |
132 // actor's lifetime. | 150 // actor's lifetime. |
133 NOTREACHED() << | 151 NOTREACHED() << |
134 "FirstRunActor destroyed before FirstRunController::Finalize."; | 152 "FirstRunActor destroyed before FirstRunController::Finalize."; |
135 } | 153 } |
136 | 154 |
137 void FirstRunController::OnCancelled() { | 155 void FirstRunController::OnCancelled() { |
| 156 RecordCompletion(first_run::kTutorialNotFinished); |
138 Stop(); | 157 Stop(); |
139 } | 158 } |
140 | 159 |
141 void FirstRunController::RegisterSteps() { | 160 void FirstRunController::RegisterSteps() { |
142 steps_.push_back(make_linked_ptr( | 161 steps_.push_back(make_linked_ptr( |
143 new first_run::AppListStep(shell_helper_.get(), actor_))); | 162 new first_run::AppListStep(shell_helper_.get(), actor_))); |
144 steps_.push_back(make_linked_ptr( | 163 steps_.push_back(make_linked_ptr( |
145 new first_run::TrayStep(shell_helper_.get(), actor_))); | 164 new first_run::TrayStep(shell_helper_.get(), actor_))); |
146 steps_.push_back(make_linked_ptr( | 165 steps_.push_back(make_linked_ptr( |
147 new first_run::HelpStep(shell_helper_.get(), actor_))); | 166 new first_run::HelpStep(shell_helper_.get(), actor_))); |
148 } | 167 } |
149 | 168 |
150 void FirstRunController::ShowNextStep() { | 169 void FirstRunController::ShowNextStep() { |
151 AdvanceStep(); | 170 AdvanceStep(); |
152 if (GetCurrentStep()) | 171 if (!GetCurrentStep()) { |
153 GetCurrentStep()->Show(); | |
154 else | |
155 actor_->Finalize(); | 172 actor_->Finalize(); |
| 173 RecordCompletion(first_run::kTutorialCompletedWithGotIt); |
| 174 return; |
| 175 } |
| 176 GetCurrentStep()->Show(); |
156 } | 177 } |
157 | 178 |
158 void FirstRunController::AdvanceStep() { | 179 void FirstRunController::AdvanceStep() { |
159 if (current_step_index_ == NONE_STEP_INDEX) | 180 if (current_step_index_ == NONE_STEP_INDEX) |
160 current_step_index_ = 0; | 181 current_step_index_ = 0; |
161 else | 182 else |
162 ++current_step_index_; | 183 ++current_step_index_; |
163 if (current_step_index_ >= steps_.size()) | 184 if (current_step_index_ >= steps_.size()) |
164 current_step_index_ = NONE_STEP_INDEX; | 185 current_step_index_ = NONE_STEP_INDEX; |
165 } | 186 } |
166 | 187 |
167 first_run::Step* FirstRunController::GetCurrentStep() const { | 188 first_run::Step* FirstRunController::GetCurrentStep() const { |
168 return current_step_index_ != NONE_STEP_INDEX ? | 189 return current_step_index_ != NONE_STEP_INDEX ? |
169 steps_[current_step_index_].get() : NULL; | 190 steps_[current_step_index_].get() : NULL; |
170 } | 191 } |
171 | 192 |
172 } // namespace chromeos | 193 } // namespace chromeos |
173 | 194 |
OLD | NEW |