#include <string>
-#include "apps/pref_names.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
#include "chrome/browser/ui/app_list/profile_loader.h"
#include "chrome/browser/ui/app_list/profile_store.h"
#include "chrome/common/chrome_constants.h"
AppListServiceImpl::AppListServiceImpl()
: profile_store_(
new ProfileStoreImpl(g_browser_process->profile_manager())),
- weak_factory_(this),
command_line_(*CommandLine::ForCurrentProcess()),
local_state_(g_browser_process->local_state()),
- profile_loader_(new ProfileLoader(profile_store_.get())) {
+ profile_loader_(new ProfileLoader(profile_store_.get())),
+ weak_factory_(this) {
profile_store_->AddProfileObserver(this);
}
PrefService* local_state,
scoped_ptr<ProfileStore> profile_store)
: profile_store_(profile_store.Pass()),
- weak_factory_(this),
command_line_(command_line),
local_state_(local_state),
- profile_loader_(new ProfileLoader(profile_store_.get())) {
+ profile_loader_(new ProfileLoader(profile_store_.get())),
+ weak_factory_(this) {
profile_store_->AddProfileObserver(this);
}
AppListServiceImpl::~AppListServiceImpl() {}
+AppListViewDelegate* AppListServiceImpl::GetViewDelegate(Profile* profile) {
+ if (!view_delegate_)
+ view_delegate_.reset(new AppListViewDelegate(GetControllerDelegate()));
+ view_delegate_->SetProfile(profile);
+ return view_delegate_.get();
+}
+
void AppListServiceImpl::SetAppListNextPaintCallback(void (*callback)()) {}
void AppListServiceImpl::HandleFirstRun() {}
}
void AppListServiceImpl::SetProfilePath(const base::FilePath& profile_path) {
- // Ensure we don't set the pref to a supervised user's profile path.
- // TODO(calamity): Filter out supervised profiles from the settings app so
- // this can't get hit, so we can remove it.
- if (profile_store_->IsProfileSupervised(profile_path))
- return;
-
local_state_->SetString(
prefs::kAppListProfile,
profile_path.BaseName().MaybeAsASCII());
void AppListServiceImpl::CreateShortcut() {}
-// We need to watch for profile removal to keep kAppListProfile updated.
void AppListServiceImpl::OnProfileWillBeRemoved(
const base::FilePath& profile_path) {
- // If the profile the app list uses just got deleted, reset it to the last
- // used profile.
+ // We need to watch for profile removal to keep kAppListProfile updated, for
+ // the case that the deleted profile is being used by the app list.
std::string app_list_last_profile = local_state_->GetString(
prefs::kAppListProfile);
- if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) {
- local_state_->SetString(prefs::kAppListProfile,
- local_state_->GetString(prefs::kProfileLastUsed));
- }
+ if (profile_path.BaseName().MaybeAsASCII() != app_list_last_profile)
+ return;
+
+ // Switch the app list over to a valid profile.
+ // Before ProfileInfoCache::DeleteProfileFromCache() calls this function,
+ // ProfileManager::ScheduleProfileForDeletion() will have checked to see if
+ // the deleted profile was also "last used", and updated that setting with
+ // something valid.
+ local_state_->SetString(prefs::kAppListProfile,
+ local_state_->GetString(prefs::kProfileLastUsed));
+
+ // If the app list was never shown, there won't be a |view_delegate_| yet.
+ if (!view_delegate_)
+ return;
+
+ // The Chrome AppListViewDelegate now needs its profile cleared, because:
+ // 1. it has many references to the profile and can't be profile-keyed, and
+ // 2. the last used profile might not be loaded yet.
+ // - this loading is sometimes done by the ProfileManager asynchronously,
+ // so the app list can't just switch to that.
+ // Only Mac supports showing the app list with a NULL profile, so tear down
+ // the view.
+ DestroyAppList();
+ view_delegate_->SetProfile(NULL);
}
void AppListServiceImpl::Show() {