Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: chrome/browser/ui/app_list/app_list_service_impl.cc

Issue 492163002: Fix Profile* lifetime issues in Chrome's AppListViewDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reorder functions for a neater diff Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "apps/pref_names.h" 9 #include "apps/pref_names.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 277 }
278 278
279 void AppListServiceImpl::SetProfilePath(const base::FilePath& profile_path) { 279 void AppListServiceImpl::SetProfilePath(const base::FilePath& profile_path) {
280 local_state_->SetString( 280 local_state_->SetString(
281 prefs::kAppListProfile, 281 prefs::kAppListProfile,
282 profile_path.BaseName().MaybeAsASCII()); 282 profile_path.BaseName().MaybeAsASCII());
283 } 283 }
284 284
285 void AppListServiceImpl::CreateShortcut() {} 285 void AppListServiceImpl::CreateShortcut() {}
286 286
287 // We need to watch for profile removal to keep kAppListProfile updated.
288 void AppListServiceImpl::OnProfileWillBeRemoved( 287 void AppListServiceImpl::OnProfileWillBeRemoved(
289 const base::FilePath& profile_path) { 288 const base::FilePath& profile_path) {
290 // If the profile the app list uses just got deleted, reset it to the last 289 // We need to watch for profile removal to keep kAppListProfile updated, for
291 // used profile. 290 // the case that the deleted profile is being used by the app list.
292 std::string app_list_last_profile = local_state_->GetString( 291 std::string app_list_last_profile = local_state_->GetString(
293 prefs::kAppListProfile); 292 prefs::kAppListProfile);
294 if (profile_path.BaseName().MaybeAsASCII() == app_list_last_profile) { 293 if (profile_path.BaseName().MaybeAsASCII() != app_list_last_profile)
295 local_state_->SetString(prefs::kAppListProfile, 294 return;
296 local_state_->GetString(prefs::kProfileLastUsed)); 295
297 } 296 // Switch the app list over to a valid profile.
297 // Before ProfileInfoCache::DeleteProfileFromCache() calls this function,
298 // ProfileManager::ScheduleProfileForDeletion() will have checked to see if
299 // the deleted profile was also "last used", and updated that setting with
300 // something valid.
301 local_state_->SetString(prefs::kAppListProfile,
302 local_state_->GetString(prefs::kProfileLastUsed));
303
304 // The Chrome AppListViewDelegate now needs to be torn down, beacuse:
305 // 1. it has many references to the profile and can't be profile-keyed, and
306 // 2. the last used profile might not be loaded yet.
307 // - this loading is sometimes done by the ProfileManager asynchronously,
308 // so the app list can't just switch to that.
309 // Currently, the AppListViewDelegate is owned by the platform-specific
310 // AppListView, so just force-close the window.
311 DestroyAppList();
298 } 312 }
299 313
300 void AppListServiceImpl::Show() { 314 void AppListServiceImpl::Show() {
301 profile_loader_->LoadProfileInvalidatingOtherLoads( 315 profile_loader_->LoadProfileInvalidatingOtherLoads(
302 GetProfilePath(profile_store_->GetUserDataDir()), 316 GetProfilePath(profile_store_->GetUserDataDir()),
303 base::Bind(&AppListServiceImpl::ShowForProfile, 317 base::Bind(&AppListServiceImpl::ShowForProfile,
304 weak_factory_.GetWeakPtr())); 318 weak_factory_.GetWeakPtr()));
305 } 319 }
306 320
307 void AppListServiceImpl::AutoShowForProfile(Profile* requested_profile) { 321 void AppListServiceImpl::AutoShowForProfile(Profile* requested_profile) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (!base::MessageLoop::current()) 374 if (!base::MessageLoop::current())
361 return; // In a unit test. 375 return; // In a unit test.
362 376
363 // Send app list usage stats after a delay. 377 // Send app list usage stats after a delay.
364 const int kSendUsageStatsDelay = 5; 378 const int kSendUsageStatsDelay = 5;
365 base::MessageLoop::current()->PostDelayedTask( 379 base::MessageLoop::current()->PostDelayedTask(
366 FROM_HERE, 380 FROM_HERE,
367 base::Bind(&AppListServiceImpl::SendAppListStats), 381 base::Bind(&AppListServiceImpl::SendAppListStats),
368 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); 382 base::TimeDelta::FromSeconds(kSendUsageStatsDelay));
369 } 383 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_list_service_impl.h ('k') | chrome/browser/ui/app_list/app_list_service_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698