| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 g_browser_process->local_state()->SetString( | 143 g_browser_process->local_state()->SetString( |
| 147 prefs::kAppListProfile, | 144 prefs::kAppListProfile, |
| 148 profile_path.BaseName().MaybeAsASCII()); | 145 profile_path.BaseName().MaybeAsASCII()); |
| 149 } | 146 } |
| 150 | 147 |
| 151 AppListControllerDelegate* AppListServiceImpl::CreateControllerDelegate() { | 148 AppListControllerDelegate* AppListServiceImpl::CreateControllerDelegate() { |
| 152 return NULL; | 149 return NULL; |
| 153 } | 150 } |
| 154 | 151 |
| 155 void AppListServiceImpl::CreateShortcut() {} | 152 void AppListServiceImpl::CreateShortcut() {} |
| 156 void AppListServiceImpl::OnSigninStatusChanged() {} | |
| 157 | 153 |
| 158 // We need to watch for profile removal to keep kAppListProfile updated. | 154 // We need to watch for profile removal to keep kAppListProfile updated. |
| 159 void AppListServiceImpl::OnProfileWillBeRemoved( | 155 void AppListServiceImpl::OnProfileWillBeRemoved( |
| 160 const base::FilePath& profile_path) { | 156 const base::FilePath& profile_path) { |
| 161 // If the profile the app list uses just got deleted, reset it to the last | 157 // If the profile the app list uses just got deleted, reset it to the last |
| 162 // used profile. | 158 // used profile. |
| 163 PrefService* local_state = g_browser_process->local_state(); | 159 PrefService* local_state = g_browser_process->local_state(); |
| 164 std::string app_list_last_profile = local_state->GetString( | 160 std::string app_list_last_profile = local_state->GetString( |
| 165 prefs::kAppListProfile); | 161 prefs::kAppListProfile); |
| 166 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { | 162 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { |
| 167 local_state->SetString(prefs::kAppListProfile, | 163 local_state->SetString(prefs::kAppListProfile, |
| 168 local_state->GetString(prefs::kProfileLastUsed)); | 164 local_state->GetString(prefs::kProfileLastUsed)); |
| 169 } | 165 } |
| 170 } | 166 } |
| 171 | 167 |
| 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() { | 168 void AppListServiceImpl::Show() { |
| 180 profile_loader_.LoadProfileInvalidatingOtherLoads( | 169 profile_loader_.LoadProfileInvalidatingOtherLoads( |
| 181 GetProfilePath(g_browser_process->profile_manager()->user_data_dir()), | 170 GetProfilePath(g_browser_process->profile_manager()->user_data_dir()), |
| 182 base::Bind(&AppListServiceImpl::ShowForProfile, | 171 base::Bind(&AppListServiceImpl::ShowForProfile, |
| 183 weak_factory_.GetWeakPtr())); | 172 weak_factory_.GetWeakPtr())); |
| 184 } | 173 } |
| 185 | 174 |
| 186 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { | 175 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { |
| 187 SetAppListEnabledPreference(true); | 176 SetAppListEnabledPreference(true); |
| 188 SetProfilePath(initial_profile->GetPath()); | 177 SetProfilePath(initial_profile->GetPath()); |
| 189 CreateShortcut(); | 178 CreateShortcut(); |
| 190 } | 179 } |
| 191 | 180 |
| 192 Profile* AppListServiceImpl::GetCurrentAppListProfile() { | 181 Profile* AppListServiceImpl::GetCurrentAppListProfile() { |
| 193 return profile(); | 182 return profile(); |
| 194 } | 183 } |
| 195 | 184 |
| 196 void AppListServiceImpl::SetProfile(Profile* new_profile) { | 185 void AppListServiceImpl::SetProfile(Profile* new_profile) { |
| 197 registrar_.RemoveAll(); | |
| 198 profile_ = new_profile; | 186 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 } | 187 } |
| 209 | 188 |
| 210 void AppListServiceImpl::InvalidatePendingProfileLoads() { | 189 void AppListServiceImpl::InvalidatePendingProfileLoads() { |
| 211 profile_loader_.InvalidatePendingProfileLoads(); | 190 profile_loader_.InvalidatePendingProfileLoads(); |
| 212 } | 191 } |
| 213 | 192 |
| 214 void AppListServiceImpl::HandleCommandLineFlags(Profile* initial_profile) { | 193 void AppListServiceImpl::HandleCommandLineFlags(Profile* initial_profile) { |
| 215 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) | 194 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) |
| 216 EnableAppList(initial_profile); | 195 EnableAppList(initial_profile); |
| 217 | 196 |
| 218 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) | 197 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) |
| 219 SetAppListEnabledPreference(false); | 198 SetAppListEnabledPreference(false); |
| 220 } | 199 } |
| OLD | NEW |