Skip to content

Commit

Permalink
Merge 199372 "Make AppListController::InitView() act on the righ..."
Browse files Browse the repository at this point in the history
> Make AppListController::InitView() act on the right profile.
> 
> It is currently using whatever profile is around at startup, which may be an
> incognito window (and so get deleted at any time). This change initializes the
> view with the app list's previous profile, and cancels itself if there's
> a profile in the process of being shown already.
> 
> This also separates the sending of UMA stats into its own deferred task.
> 
> BUG=236487
> R=benwells@chromium.org
> 
> Review URL: https://codereview.chromium.org/14587005

TBR=koz@chromium.org
Review URL: https://codereview.chromium.org/14783011

git-svn-id: svn://svn.chromium.org/chrome/branches/1500/src@199486 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
laforge@chromium.org committed May 10, 2013
1 parent 9abc39c commit 6b729c0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ui/app_list/app_list_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void AppListService::RecordAppListAppLaunch() {

// static
void AppListService::SendAppListStats() {
if (!g_browser_process || g_browser_process->IsShuttingDown())
return;
SendDailyEventFrequency(prefs::kLastAppListLaunchPing,
prefs::kAppListLaunchCount,
&SendAppListLaunch);
Expand Down
75 changes: 59 additions & 16 deletions chrome/browser/ui/views/app_list/app_list_controller_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ class AppListController : public AppListService,
bool can_close() { return can_close_app_list_; }
Profile* profile() const { return profile_; }

// Creates the app list view and populates it from |profile|, but doesn't
// show it. Does nothing if the view already exists.
void InitView(Profile* profile);

void AppListClosing();
void AppListActivationChanged(bool active);
void ShowAppListDuringModeSwitch(Profile* profile);
Expand Down Expand Up @@ -378,6 +374,16 @@ class AppListController : public AppListService,
void EnsureHaveKeepAliveForView();
void FreeAnyKeepAliveForView();

// Loads the profile last used with the app list and populates the view from
// it without showing it so that the next show is faster. Does nothing if the
// view already exists, or another profile is in the middle of being loaded to
// be shown.
void InitView();
bool IsInitViewNeeded();
void InitViewFromProfile(int profile_load_sequence_id,
Profile* profile,
Profile::CreateStatus status);

// Weak pointer. The view manages its own lifetime.
app_list::AppListView* current_view_;

Expand Down Expand Up @@ -604,7 +610,6 @@ void AppListController::OnProfileLoaded(int profile_load_sequence_id,
DecrementPendingProfileLoads();
break;
}

}

void AppListController::IncrementPendingProfileLoads() {
Expand Down Expand Up @@ -661,14 +666,6 @@ void AppListController::ShowAppList(Profile* profile) {
RecordAppListLaunch();
}

void AppListController::InitView(Profile* profile) {
if (current_view_)
return;
AppListService::SendAppListStats();
PopulateViewFromProfile(profile);
current_view_->Prerender();
}

void AppListController::ShowAppListDuringModeSwitch(Profile* profile) {
regain_first_lost_focus_ = true;
ShowAppList(profile);
Expand Down Expand Up @@ -981,10 +978,49 @@ void AppListController::FreeAnyKeepAliveForView() {
keep_alive_.reset(NULL);
}

void InitView(Profile* profile) {
void AppListController::InitView() {
if (!IsInitViewNeeded())
return;

base::FilePath user_data_dir(
g_browser_process->profile_manager()->user_data_dir());
base::FilePath profile_file_path(GetAppListProfilePath(user_data_dir));

ProfileManager* profile_manager = g_browser_process->profile_manager();
Profile* profile = profile_manager->GetProfileByPath(profile_file_path);

if (!profile) {
profile_manager->CreateProfileAsync(
profile_file_path,
base::Bind(&AppListController::InitViewFromProfile,
weak_factory_.GetWeakPtr(), profile_load_sequence_id_),
string16(), string16(), false);
return;
}
InitViewFromProfile(
profile_load_sequence_id_, profile, Profile::CREATE_STATUS_INITIALIZED);
}

bool AppListController::IsInitViewNeeded() {
if (!g_browser_process || g_browser_process->IsShuttingDown())
return false;

// We only need to initialize the view if there's no view already created and
// there's no profile loading to be shown.
return !current_view_ && profile_load_sequence_id_ == 0;
}

void AppListController::InitViewFromProfile(int profile_load_sequence_id,
Profile* profile,
Profile::CreateStatus status) {
if (!IsInitViewNeeded())
return;
AppListController::GetInstance()->InitView(profile);

if (status != Profile::CREATE_STATUS_INITIALIZED)
return;

PopulateViewFromProfile(profile);
current_view_->Prerender();
}

void AppListController::Init(Profile* initial_profile) {
Expand All @@ -1009,9 +1045,16 @@ void AppListController::Init(Profile* initial_profile) {
const int kInitWindowDelay = 5;
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&::InitView, initial_profile),
base::Bind(&AppListController::InitView, weak_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kInitWindowDelay));

// Send app list usage stats after a delay.
const int kSendUsageStatsDelay = 5;
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&AppListService::SendAppListStats),
base::TimeDelta::FromSeconds(kSendUsageStatsDelay));

MigrateAppLauncherEnabledPref();

if (CommandLine::ForCurrentProcess()->HasSwitch(
Expand Down

0 comments on commit 6b729c0

Please sign in to comment.