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/ui/app_list/app_list_service_impl.h" | 5 #include "chrome/browser/ui/app_list/app_list_service_impl.h" |
6 | 6 |
7 #include "apps/pref_names.h" | 7 #include "apps/pref_names.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_details.h" | |
20 #include "content/public/browser/notification_source.h" | |
21 | 18 |
22 namespace { | 19 namespace { |
23 | 20 |
24 void SendAppListAppLaunch(int count) { | 21 void SendAppListAppLaunch(int count) { |
25 UMA_HISTOGRAM_CUSTOM_COUNTS( | 22 UMA_HISTOGRAM_CUSTOM_COUNTS( |
26 "Apps.AppListDailyAppLaunches", count, 1, 1000, 50); | 23 "Apps.AppListDailyAppLaunches", count, 1, 1000, 50); |
27 if (count > 0) | 24 if (count > 0) |
28 UMA_HISTOGRAM_ENUMERATION("Apps.AppListHasLaunchedAppToday", 1, 2); | 25 UMA_HISTOGRAM_ENUMERATION("Apps.AppListHasLaunchedAppToday", 1, 2); |
29 } | 26 } |
30 | 27 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 g_browser_process->local_state()->SetString( | 148 g_browser_process->local_state()->SetString( |
152 prefs::kAppListProfile, | 149 prefs::kAppListProfile, |
153 profile_path.BaseName().MaybeAsASCII()); | 150 profile_path.BaseName().MaybeAsASCII()); |
154 } | 151 } |
155 | 152 |
156 AppListControllerDelegate* AppListServiceImpl::CreateControllerDelegate() { | 153 AppListControllerDelegate* AppListServiceImpl::CreateControllerDelegate() { |
157 return NULL; | 154 return NULL; |
158 } | 155 } |
159 | 156 |
160 void AppListServiceImpl::CreateShortcut() {} | 157 void AppListServiceImpl::CreateShortcut() {} |
161 void AppListServiceImpl::OnSigninStatusChanged() {} | |
162 | 158 |
163 // We need to watch for profile removal to keep kAppListProfile updated. | 159 // We need to watch for profile removal to keep kAppListProfile updated. |
164 void AppListServiceImpl::OnProfileWillBeRemoved( | 160 void AppListServiceImpl::OnProfileWillBeRemoved( |
165 const base::FilePath& profile_path) { | 161 const base::FilePath& profile_path) { |
166 // If the profile the app list uses just got deleted, reset it to the last | 162 // If the profile the app list uses just got deleted, reset it to the last |
167 // used profile. | 163 // used profile. |
168 PrefService* local_state = g_browser_process->local_state(); | 164 PrefService* local_state = g_browser_process->local_state(); |
169 std::string app_list_last_profile = local_state->GetString( | 165 std::string app_list_last_profile = local_state->GetString( |
170 prefs::kAppListProfile); | 166 prefs::kAppListProfile); |
171 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { | 167 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { |
172 local_state->SetString(prefs::kAppListProfile, | 168 local_state->SetString(prefs::kAppListProfile, |
173 local_state->GetString(prefs::kProfileLastUsed)); | 169 local_state->GetString(prefs::kProfileLastUsed)); |
174 } | 170 } |
175 } | 171 } |
176 | 172 |
177 void AppListServiceImpl::Observe( | |
178 int type, | |
179 const content::NotificationSource& source, | |
180 const content::NotificationDetails& details) { | |
181 OnSigninStatusChanged(); | |
182 } | |
183 | |
184 void AppListServiceImpl::Show() { | 173 void AppListServiceImpl::Show() { |
185 profile_loader_.LoadProfileInvalidatingOtherLoads( | 174 profile_loader_.LoadProfileInvalidatingOtherLoads( |
186 GetProfilePath(g_browser_process->profile_manager()->user_data_dir()), | 175 GetProfilePath(g_browser_process->profile_manager()->user_data_dir()), |
187 base::Bind(&AppListServiceImpl::ShowForProfile, | 176 base::Bind(&AppListServiceImpl::ShowForProfile, |
188 weak_factory_.GetWeakPtr())); | 177 weak_factory_.GetWeakPtr())); |
189 } | 178 } |
190 | 179 |
191 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { | 180 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { |
192 SetProfilePath(initial_profile->GetPath()); | 181 SetProfilePath(initial_profile->GetPath()); |
193 if (HasAppListEnabledPreference()) | 182 if (HasAppListEnabledPreference()) |
194 return; | 183 return; |
195 | 184 |
196 SetAppListEnabledPreference(true); | 185 SetAppListEnabledPreference(true); |
197 CreateShortcut(); | 186 CreateShortcut(); |
198 } | 187 } |
199 | 188 |
200 Profile* AppListServiceImpl::GetCurrentAppListProfile() { | 189 Profile* AppListServiceImpl::GetCurrentAppListProfile() { |
201 return profile(); | 190 return profile(); |
202 } | 191 } |
203 | 192 |
204 void AppListServiceImpl::SetProfile(Profile* new_profile) { | 193 void AppListServiceImpl::SetProfile(Profile* new_profile) { |
205 registrar_.RemoveAll(); | |
206 profile_ = new_profile; | 194 profile_ = new_profile; |
207 if (!profile_) | |
208 return; | |
209 | |
210 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | |
211 content::Source<Profile>(profile_)); | |
212 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | |
213 content::Source<Profile>(profile_)); | |
214 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
215 content::Source<Profile>(profile_)); | |
216 } | 195 } |
217 | 196 |
218 void AppListServiceImpl::InvalidatePendingProfileLoads() { | 197 void AppListServiceImpl::InvalidatePendingProfileLoads() { |
219 profile_loader_.InvalidatePendingProfileLoads(); | 198 profile_loader_.InvalidatePendingProfileLoads(); |
220 } | 199 } |
221 | 200 |
222 void AppListServiceImpl::HandleCommandLineFlags(Profile* initial_profile) { | 201 void AppListServiceImpl::HandleCommandLineFlags(Profile* initial_profile) { |
223 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) | 202 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) |
224 EnableAppList(initial_profile); | 203 EnableAppList(initial_profile); |
225 | 204 |
226 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) | 205 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) |
227 SetAppListEnabledPreference(false); | 206 SetAppListEnabledPreference(false); |
228 } | 207 } |
OLD | NEW |