| 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" |
| 8 #include "base/command_line.h" |
| 7 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 15 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 void SendAppListAppLaunch(int count) { | 24 void SendAppListAppLaunch(int count) { |
| 22 UMA_HISTOGRAM_CUSTOM_COUNTS( | 25 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 23 "Apps.AppListDailyAppLaunches", count, 1, 1000, 50); | 26 "Apps.AppListDailyAppLaunches", count, 1, 1000, 50); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 void (*send_callback)(int count)) { | 62 void (*send_callback)(int count)) { |
| 60 PrefService* local_state = g_browser_process->local_state(); | 63 PrefService* local_state = g_browser_process->local_state(); |
| 61 | 64 |
| 62 int count = local_state->GetInteger(count_pref); | 65 int count = local_state->GetInteger(count_pref); |
| 63 local_state->SetInteger(count_pref, count + 1); | 66 local_state->SetInteger(count_pref, count + 1); |
| 64 if (SendDailyEventFrequency(last_ping_pref, count_pref, send_callback)) { | 67 if (SendDailyEventFrequency(last_ping_pref, count_pref, send_callback)) { |
| 65 local_state->SetInteger(count_pref, 1); | 68 local_state->SetInteger(count_pref, 1); |
| 66 } | 69 } |
| 67 } | 70 } |
| 68 | 71 |
| 72 void SetAppListEnabledPreference(bool enabled) { |
| 73 PrefService* local_state = g_browser_process->local_state(); |
| 74 local_state->SetBoolean(apps::prefs::kAppLauncherHasBeenEnabled, enabled); |
| 75 } |
| 76 |
| 69 } // namespace | 77 } // namespace |
| 70 | 78 |
| 71 // static | 79 // static |
| 72 void AppListServiceImpl::RecordAppListLaunch() { | 80 void AppListServiceImpl::RecordAppListLaunch() { |
| 73 RecordDailyEventFrequency(prefs::kLastAppListLaunchPing, | 81 RecordDailyEventFrequency(prefs::kLastAppListLaunchPing, |
| 74 prefs::kAppListLaunchCount, | 82 prefs::kAppListLaunchCount, |
| 75 &SendAppListLaunch); | 83 &SendAppListLaunch); |
| 76 } | 84 } |
| 77 | 85 |
| 78 // static | 86 // static |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // If the user has no profile preference for the app launcher, default to the | 129 // If the user has no profile preference for the app launcher, default to the |
| 122 // last browser profile used. | 130 // last browser profile used. |
| 123 if (app_list_profile.empty() && | 131 if (app_list_profile.empty() && |
| 124 local_state->HasPrefPath(prefs::kProfileLastUsed)) | 132 local_state->HasPrefPath(prefs::kProfileLastUsed)) |
| 125 app_list_profile = local_state->GetString(prefs::kProfileLastUsed); | 133 app_list_profile = local_state->GetString(prefs::kProfileLastUsed); |
| 126 | 134 |
| 127 std::string profile_path = app_list_profile.empty() ? | 135 std::string profile_path = app_list_profile.empty() ? |
| 128 chrome::kInitialProfile : | 136 chrome::kInitialProfile : |
| 129 app_list_profile; | 137 app_list_profile; |
| 130 | 138 |
| 131 return user_data_dir.AppendASCII(profile_path); | 139 if (!user_data_dir.empty()) |
| 140 return user_data_dir.AppendASCII(profile_path); |
| 141 |
| 142 return g_browser_process->profile_manager()-> |
| 143 user_data_dir().AppendASCII(profile_path); |
| 144 } |
| 145 |
| 146 void AppListServiceImpl::SetProfilePath(const base::FilePath& profile_path) { |
| 147 g_browser_process->local_state()->SetString( |
| 148 prefs::kAppListProfile, |
| 149 profile_path.BaseName().MaybeAsASCII()); |
| 132 } | 150 } |
| 133 | 151 |
| 134 AppListControllerDelegate* AppListServiceImpl::CreateControllerDelegate() { | 152 AppListControllerDelegate* AppListServiceImpl::CreateControllerDelegate() { |
| 135 return NULL; | 153 return NULL; |
| 136 } | 154 } |
| 137 | 155 |
| 156 void AppListServiceImpl::CreateShortcut() {} |
| 138 void AppListServiceImpl::OnSigninStatusChanged() {} | 157 void AppListServiceImpl::OnSigninStatusChanged() {} |
| 139 | 158 |
| 140 // We need to watch for profile removal to keep kAppListProfile updated. | 159 // We need to watch for profile removal to keep kAppListProfile updated. |
| 141 void AppListServiceImpl::OnProfileWillBeRemoved( | 160 void AppListServiceImpl::OnProfileWillBeRemoved( |
| 142 const base::FilePath& profile_path) { | 161 const base::FilePath& profile_path) { |
| 143 // 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 |
| 144 // used profile. | 163 // used profile. |
| 145 PrefService* local_state = g_browser_process->local_state(); | 164 PrefService* local_state = g_browser_process->local_state(); |
| 146 std::string app_list_last_profile = local_state->GetString( | 165 std::string app_list_last_profile = local_state->GetString( |
| 147 prefs::kAppListProfile); | 166 prefs::kAppListProfile); |
| 148 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { | 167 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { |
| 149 local_state->SetString(prefs::kAppListProfile, | 168 local_state->SetString(prefs::kAppListProfile, |
| 150 local_state->GetString(prefs::kProfileLastUsed)); | 169 local_state->GetString(prefs::kProfileLastUsed)); |
| 151 } | 170 } |
| 152 } | 171 } |
| 153 | 172 |
| 154 void AppListServiceImpl::Observe( | 173 void AppListServiceImpl::Observe( |
| 155 int type, | 174 int type, |
| 156 const content::NotificationSource& source, | 175 const content::NotificationSource& source, |
| 157 const content::NotificationDetails& details) { | 176 const content::NotificationDetails& details) { |
| 158 OnSigninStatusChanged(); | 177 OnSigninStatusChanged(); |
| 159 } | 178 } |
| 160 | 179 |
| 161 void AppListServiceImpl::SetAppListProfile( | 180 void AppListServiceImpl::ShowForSavedProfile() { |
| 162 const base::FilePath& profile_file_path) { | |
| 163 profile_loader_.LoadProfileInvalidatingOtherLoads( | 181 profile_loader_.LoadProfileInvalidatingOtherLoads( |
| 164 profile_file_path, base::Bind(&AppListServiceImpl::ShowAppList, | 182 GetProfilePath(base::FilePath()), |
| 165 weak_factory_.GetWeakPtr())); | 183 base::Bind(&AppListServiceImpl::ShowAppList, weak_factory_.GetWeakPtr())); |
| 166 } | 184 } |
| 167 | 185 |
| 168 void AppListServiceImpl::ShowForSavedProfile() { | 186 void AppListServiceImpl::EnableAppList(Profile* initial_profile) { |
| 169 SetAppListProfile(GetProfilePath( | 187 SetAppListEnabledPreference(true); |
| 170 g_browser_process->profile_manager()->user_data_dir())); | 188 SetProfilePath(initial_profile->GetPath()); |
| 189 CreateShortcut(); |
| 171 } | 190 } |
| 172 | 191 |
| 173 Profile* AppListServiceImpl::GetCurrentAppListProfile() { | 192 Profile* AppListServiceImpl::GetCurrentAppListProfile() { |
| 174 return profile(); | 193 return profile(); |
| 175 } | 194 } |
| 176 | 195 |
| 177 void AppListServiceImpl::SetProfile(Profile* new_profile) { | 196 void AppListServiceImpl::SetProfile(Profile* new_profile) { |
| 178 registrar_.RemoveAll(); | 197 registrar_.RemoveAll(); |
| 179 profile_ = new_profile; | 198 profile_ = new_profile; |
| 180 if (!profile_) | 199 if (!profile_) |
| 181 return; | 200 return; |
| 182 | 201 |
| 183 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 202 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 184 content::Source<Profile>(profile_)); | 203 content::Source<Profile>(profile_)); |
| 185 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 204 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| 186 content::Source<Profile>(profile_)); | 205 content::Source<Profile>(profile_)); |
| 187 } | 206 } |
| 188 | 207 |
| 189 void AppListServiceImpl::InvalidatePendingProfileLoads() { | 208 void AppListServiceImpl::InvalidatePendingProfileLoads() { |
| 190 profile_loader_.InvalidatePendingProfileLoads(); | 209 profile_loader_.InvalidatePendingProfileLoads(); |
| 191 } | 210 } |
| 192 | 211 |
| 193 void AppListServiceImpl::SaveProfilePathToLocalState( | 212 void AppListServiceImpl::SharedDesktopInit(Profile* initial_profile) { |
| 194 const base::FilePath& profile_file_path) { | 213 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppList)) |
| 195 g_browser_process->local_state()->SetString( | 214 EnableAppList(initial_profile); |
| 196 prefs::kAppListProfile, | 215 |
| 197 profile_file_path.BaseName().MaybeAsASCII()); | 216 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAppList)) |
| 217 SetAppListEnabledPreference(false); |
| 198 } | 218 } |
| OLD | NEW |