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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 Profile* GetProfileByPath(const base::FilePath& path) override { | 125 Profile* GetProfileByPath(const base::FilePath& path) override { |
126 DCHECK(!IsProfileLocked(path)); | 126 DCHECK(!IsProfileLocked(path)); |
127 return profile_manager_->GetProfileByPath(path); | 127 return profile_manager_->GetProfileByPath(path); |
128 } | 128 } |
129 | 129 |
130 base::FilePath GetUserDataDir() override { | 130 base::FilePath GetUserDataDir() override { |
131 return profile_manager_->user_data_dir(); | 131 return profile_manager_->user_data_dir(); |
132 } | 132 } |
133 | 133 |
| 134 std::string GetLastUsedProfileName() override { |
| 135 return profile_manager_->GetLastUsedProfileName(); |
| 136 } |
| 137 |
134 bool IsProfileSupervised(const base::FilePath& profile_path) override { | 138 bool IsProfileSupervised(const base::FilePath& profile_path) override { |
135 ProfileInfoCache& profile_info = | 139 ProfileInfoCache& profile_info = |
136 g_browser_process->profile_manager()->GetProfileInfoCache(); | 140 g_browser_process->profile_manager()->GetProfileInfoCache(); |
137 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); | 141 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); |
138 return profile_index != std::string::npos && | 142 return profile_index != std::string::npos && |
139 profile_info.ProfileIsSupervisedAtIndex(profile_index); | 143 profile_info.ProfileIsSupervisedAtIndex(profile_index); |
140 } | 144 } |
141 | 145 |
142 bool IsProfileLocked(const base::FilePath& profile_path) override { | 146 bool IsProfileLocked(const base::FilePath& profile_path) override { |
143 ProfileInfoCache& profile_info = | 147 ProfileInfoCache& profile_info = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 view_delegate_->SetProfile(profile); | 282 view_delegate_->SetProfile(profile); |
279 return view_delegate_.get(); | 283 return view_delegate_.get(); |
280 } | 284 } |
281 | 285 |
282 void AppListServiceImpl::SetAppListNextPaintCallback(void (*callback)()) {} | 286 void AppListServiceImpl::SetAppListNextPaintCallback(void (*callback)()) {} |
283 | 287 |
284 void AppListServiceImpl::Init(Profile* initial_profile) {} | 288 void AppListServiceImpl::Init(Profile* initial_profile) {} |
285 | 289 |
286 base::FilePath AppListServiceImpl::GetProfilePath( | 290 base::FilePath AppListServiceImpl::GetProfilePath( |
287 const base::FilePath& user_data_dir) { | 291 const base::FilePath& user_data_dir) { |
288 std::string app_list_profile; | 292 return user_data_dir.AppendASCII(GetProfileName()); |
289 if (local_state_->HasPrefPath(prefs::kAppListProfile)) | |
290 app_list_profile = local_state_->GetString(prefs::kAppListProfile); | |
291 | |
292 // If the user has no profile preference for the app launcher, default to the | |
293 // last browser profile used. | |
294 if (app_list_profile.empty() && | |
295 local_state_->HasPrefPath(prefs::kProfileLastUsed)) { | |
296 app_list_profile = local_state_->GetString(prefs::kProfileLastUsed); | |
297 } | |
298 | |
299 // If there is no last used profile recorded, use the initial profile. | |
300 if (app_list_profile.empty()) | |
301 app_list_profile = chrome::kInitialProfile; | |
302 | |
303 return user_data_dir.AppendASCII(app_list_profile); | |
304 } | 293 } |
305 | 294 |
306 void AppListServiceImpl::SetProfilePath(const base::FilePath& profile_path) { | 295 void AppListServiceImpl::SetProfilePath(const base::FilePath& profile_path) { |
307 local_state_->SetString( | 296 local_state_->SetString( |
308 prefs::kAppListProfile, | 297 prefs::kAppListProfile, |
309 profile_path.BaseName().MaybeAsASCII()); | 298 profile_path.BaseName().MaybeAsASCII()); |
310 } | 299 } |
311 | 300 |
312 void AppListServiceImpl::CreateShortcut() {} | 301 void AppListServiceImpl::CreateShortcut() {} |
313 | 302 |
| 303 std::string AppListServiceImpl::GetProfileName() { |
| 304 const std::string app_list_profile = |
| 305 local_state_->GetString(prefs::kAppListProfile); |
| 306 if (!app_list_profile.empty()) |
| 307 return app_list_profile; |
| 308 |
| 309 // If the user has no profile preference for the app launcher, default to the |
| 310 // last browser profile used. |
| 311 return profile_store_->GetLastUsedProfileName(); |
| 312 } |
| 313 |
314 void AppListServiceImpl::OnProfileWillBeRemoved( | 314 void AppListServiceImpl::OnProfileWillBeRemoved( |
315 const base::FilePath& profile_path) { | 315 const base::FilePath& profile_path) { |
316 // We need to watch for profile removal to keep kAppListProfile updated, for | 316 // We need to watch for profile removal to keep kAppListProfile updated, for |
317 // the case that the deleted profile is being used by the app list. | 317 // the case that the deleted profile is being used by the app list. |
318 std::string app_list_last_profile = local_state_->GetString( | 318 std::string app_list_last_profile = local_state_->GetString( |
319 prefs::kAppListProfile); | 319 prefs::kAppListProfile); |
320 if (profile_path.BaseName().MaybeAsASCII() != app_list_last_profile) | 320 if (profile_path.BaseName().MaybeAsASCII() != app_list_last_profile) |
321 return; | 321 return; |
322 | 322 |
323 // Switch the app list over to a valid profile. | 323 // Switch the app list over to a valid profile. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 if (!base::MessageLoop::current()) | 430 if (!base::MessageLoop::current()) |
431 return; // In a unit test. | 431 return; // In a unit test. |
432 | 432 |
433 // Send app list usage stats after a delay. | 433 // Send app list usage stats after a delay. |
434 const int kSendUsageStatsDelay = 5; | 434 const int kSendUsageStatsDelay = 5; |
435 base::MessageLoop::current()->PostDelayedTask( | 435 base::MessageLoop::current()->PostDelayedTask( |
436 FROM_HERE, | 436 FROM_HERE, |
437 base::Bind(&AppListServiceImpl::SendAppListStats), | 437 base::Bind(&AppListServiceImpl::SendAppListStats), |
438 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); | 438 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); |
439 } | 439 } |
OLD | NEW |