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

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

Issue 508813002: Move ownership of the AppListViewDelegate into the AppListService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments Created 6 years, 3 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
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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/browser_shutdown.h" 16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
18 #include "chrome/browser/ui/app_list/profile_loader.h" 19 #include "chrome/browser/ui/app_list/profile_loader.h"
19 #include "chrome/browser/ui/app_list/profile_store.h" 20 #include "chrome/browser/ui/app_list/profile_store.h"
20 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 24
24 namespace { 25 namespace {
25 26
26 const int kDiscoverabilityTimeoutMinutes = 60; 27 const int kDiscoverabilityTimeoutMinutes = 60;
27 28
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 : profile_store_(profile_store.Pass()), 243 : profile_store_(profile_store.Pass()),
243 command_line_(command_line), 244 command_line_(command_line),
244 local_state_(local_state), 245 local_state_(local_state),
245 profile_loader_(new ProfileLoader(profile_store_.get())), 246 profile_loader_(new ProfileLoader(profile_store_.get())),
246 weak_factory_(this) { 247 weak_factory_(this) {
247 profile_store_->AddProfileObserver(this); 248 profile_store_->AddProfileObserver(this);
248 } 249 }
249 250
250 AppListServiceImpl::~AppListServiceImpl() {} 251 AppListServiceImpl::~AppListServiceImpl() {}
251 252
253 AppListViewDelegate* AppListServiceImpl::GetViewDelegate(Profile* profile) {
254 if (!view_delegate_)
255 view_delegate_.reset(new AppListViewDelegate(GetControllerDelegate()));
256 view_delegate_->SetProfile(profile);
257 return view_delegate_.get();
258 }
259
252 void AppListServiceImpl::SetAppListNextPaintCallback(void (*callback)()) {} 260 void AppListServiceImpl::SetAppListNextPaintCallback(void (*callback)()) {}
253 261
254 void AppListServiceImpl::HandleFirstRun() {} 262 void AppListServiceImpl::HandleFirstRun() {}
255 263
256 void AppListServiceImpl::Init(Profile* initial_profile) {} 264 void AppListServiceImpl::Init(Profile* initial_profile) {}
257 265
258 base::FilePath AppListServiceImpl::GetProfilePath( 266 base::FilePath AppListServiceImpl::GetProfilePath(
259 const base::FilePath& user_data_dir) { 267 const base::FilePath& user_data_dir) {
260 std::string app_list_profile; 268 std::string app_list_profile;
261 if (local_state_->HasPrefPath(prefs::kAppListProfile)) 269 if (local_state_->HasPrefPath(prefs::kAppListProfile))
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return; 301 return;
294 302
295 // Switch the app list over to a valid profile. 303 // Switch the app list over to a valid profile.
296 // Before ProfileInfoCache::DeleteProfileFromCache() calls this function, 304 // Before ProfileInfoCache::DeleteProfileFromCache() calls this function,
297 // ProfileManager::ScheduleProfileForDeletion() will have checked to see if 305 // ProfileManager::ScheduleProfileForDeletion() will have checked to see if
298 // the deleted profile was also "last used", and updated that setting with 306 // the deleted profile was also "last used", and updated that setting with
299 // something valid. 307 // something valid.
300 local_state_->SetString(prefs::kAppListProfile, 308 local_state_->SetString(prefs::kAppListProfile,
301 local_state_->GetString(prefs::kProfileLastUsed)); 309 local_state_->GetString(prefs::kProfileLastUsed));
302 310
303 // The Chrome AppListViewDelegate now needs to be torn down, because: 311 // If the app list was never shown, there won't be a |view_delegate_| yet.
312 if (!view_delegate_)
313 return;
314
315 // The Chrome AppListViewDelegate now needs its profile cleared, because:
304 // 1. it has many references to the profile and can't be profile-keyed, and 316 // 1. it has many references to the profile and can't be profile-keyed, and
305 // 2. the last used profile might not be loaded yet. 317 // 2. the last used profile might not be loaded yet.
306 // - this loading is sometimes done by the ProfileManager asynchronously, 318 // - this loading is sometimes done by the ProfileManager asynchronously,
307 // so the app list can't just switch to that. 319 // so the app list can't just switch to that.
308 // Currently, the AppListViewDelegate is owned by the platform-specific 320 // Only Mac supports showing the app list with a NULL profile, so tear down
309 // AppListView, so just force-close the window. 321 // the view.
310 DestroyAppList(); 322 DestroyAppList();
323 view_delegate_->SetProfile(NULL);
311 } 324 }
312 325
313 void AppListServiceImpl::Show() { 326 void AppListServiceImpl::Show() {
314 profile_loader_->LoadProfileInvalidatingOtherLoads( 327 profile_loader_->LoadProfileInvalidatingOtherLoads(
315 GetProfilePath(profile_store_->GetUserDataDir()), 328 GetProfilePath(profile_store_->GetUserDataDir()),
316 base::Bind(&AppListServiceImpl::ShowForProfile, 329 base::Bind(&AppListServiceImpl::ShowForProfile,
317 weak_factory_.GetWeakPtr())); 330 weak_factory_.GetWeakPtr()));
318 } 331 }
319 332
320 void AppListServiceImpl::AutoShowForProfile(Profile* requested_profile) { 333 void AppListServiceImpl::AutoShowForProfile(Profile* requested_profile) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 if (!base::MessageLoop::current()) 386 if (!base::MessageLoop::current())
374 return; // In a unit test. 387 return; // In a unit test.
375 388
376 // Send app list usage stats after a delay. 389 // Send app list usage stats after a delay.
377 const int kSendUsageStatsDelay = 5; 390 const int kSendUsageStatsDelay = 5;
378 base::MessageLoop::current()->PostDelayedTask( 391 base::MessageLoop::current()->PostDelayedTask(
379 FROM_HERE, 392 FROM_HERE,
380 base::Bind(&AppListServiceImpl::SendAppListStats), 393 base::Bind(&AppListServiceImpl::SendAppListStats),
381 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); 394 base::TimeDelta::FromSeconds(kSendUsageStatsDelay));
382 } 395 }
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_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698