| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // used profile. | 159 // used profile. |
| 163 PrefService* local_state = g_browser_process->local_state(); | 160 PrefService* local_state = g_browser_process->local_state(); |
| 164 std::string app_list_last_profile = local_state->GetString( | 161 std::string app_list_last_profile = local_state->GetString( |
| 165 prefs::kAppListProfile); | 162 prefs::kAppListProfile); |
| 166 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { | 163 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { |
| 167 local_state->SetString(prefs::kAppListProfile, | 164 local_state->SetString(prefs::kAppListProfile, |
| 168 local_state->GetString(prefs::kProfileLastUsed)); | 165 local_state->GetString(prefs::kProfileLastUsed)); |
| 169 } | 166 } |
| 170 } | 167 } |
| 171 | 168 |
| 172 void AppListServiceImpl::Observe( | |
| 173 int type, | |
| 174 const content::NotificationSource& source, | |
| 175 const content::NotificationDetails& details) { | |
| 176 OnSigninStatusChanged(); | |
| 177 } | |
| 178 | |
| 179 void AppListServiceImpl::Show() { | 169 void AppListServiceImpl::Show() { |
| 180 profile_loader_.LoadProfileInvalidatingOtherLoads( | 170 profile_loader_.LoadProfileInvalidatingOtherLoads( |
| 181 GetProfilePath(g_browser_process->profile_manager()->user_data_dir()), | 171 GetProfilePath(g_browser_process->profile_manager()->user_data_dir()), |
| 182 base::Bind(&AppListServiceImpl::ShowForProfile, | 172 base::Bind(&AppListServiceImpl::ShowForProfile, |
| 183 weak_factory_.GetWeakPtr())); | 173 weak_factory_.GetWeakPtr())); |
| 184 } | 174 } |
| 185 | 175 |
| 186 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { | 176 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { |
| 187 SetAppListEnabledPreference(true); | 177 SetAppListEnabledPreference(true); |
| 188 SetProfilePath(initial_profile->GetPath()); | 178 SetProfilePath(initial_profile->GetPath()); |
| 189 CreateShortcut(); | 179 CreateShortcut(); |
| 190 } | 180 } |
| 191 | 181 |
| 192 Profile* AppListServiceImpl::GetCurrentAppListProfile() { | 182 Profile* AppListServiceImpl::GetCurrentAppListProfile() { |
| 193 return profile(); | 183 return profile(); |
| 194 } | 184 } |
| 195 | 185 |
| 196 void AppListServiceImpl::SetProfile(Profile* new_profile) { | 186 void AppListServiceImpl::SetProfile(Profile* new_profile) { |
| 197 registrar_.RemoveAll(); | |
| 198 profile_ = new_profile; | 187 profile_ = new_profile; |
| 199 if (!profile_) | |
| 200 return; | |
| 201 | |
| 202 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | |
| 203 content::Source<Profile>(profile_)); | |
| 204 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | |
| 205 content::Source<Profile>(profile_)); | |
| 206 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
| 207 content::Source<Profile>(profile_)); | |
| 208 } | 188 } |
| 209 | 189 |
| 210 void AppListServiceImpl::InvalidatePendingProfileLoads() { | 190 void AppListServiceImpl::InvalidatePendingProfileLoads() { |
| 211 profile_loader_.InvalidatePendingProfileLoads(); | 191 profile_loader_.InvalidatePendingProfileLoads(); |
| 212 } | 192 } |
| 213 | 193 |
| 214 void AppListServiceImpl::HandleCommandLineFlags(Profile* initial_profile) { | 194 void AppListServiceImpl::HandleCommandLineFlags(Profile* initial_profile) { |
| 215 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) | 195 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) |
| 216 EnableAppList(initial_profile); | 196 EnableAppList(initial_profile); |
| 217 | 197 |
| 218 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) | 198 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) |
| 219 SetAppListEnabledPreference(false); | 199 SetAppListEnabledPreference(false); |
| 220 } | 200 } |
| OLD | NEW |