Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / app_list / app_list_service_views.cc
blob2f1df8ab016e86df5f5e48f41cca1d0506d6496b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/app_list/app_list_service_views.h"
7 #include "chrome/browser/apps/scoped_keep_alive.h"
8 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
9 #include "ui/app_list/app_list_switches.h"
10 #include "ui/app_list/views/app_list_main_view.h"
11 #include "ui/app_list/views/app_list_view.h"
12 #include "ui/app_list/views/contents_view.h"
14 AppListServiceViews::AppListServiceViews(
15 scoped_ptr<AppListControllerDelegate> controller_delegate)
16 : shower_(this),
17 can_dismiss_(true),
18 controller_delegate_(controller_delegate.Pass()) {
21 AppListServiceViews::~AppListServiceViews() {}
23 void AppListServiceViews::OnViewBeingDestroyed() {
24 can_dismiss_ = true;
25 shower_.HandleViewBeingDestroyed();
28 void AppListServiceViews::Init(Profile* initial_profile) {
29 PerformStartupChecks(initial_profile);
32 void AppListServiceViews::ShowForProfile(Profile* requested_profile) {
33 // App list profiles should not be off-the-record.
34 DCHECK(!requested_profile->IsOffTheRecord());
35 DCHECK(!requested_profile->IsGuestSession());
37 ShowForProfileInternal(requested_profile,
38 app_list::AppListModel::INVALID_STATE);
41 void AppListServiceViews::ShowForAppInstall(Profile* profile,
42 const std::string& extension_id,
43 bool start_discovery_tracking) {
44 if (app_list::switches::IsExperimentalAppListEnabled())
45 ShowForProfileInternal(profile, app_list::AppListModel::STATE_APPS);
47 AppListServiceImpl::ShowForAppInstall(profile, extension_id,
48 start_discovery_tracking);
51 void AppListServiceViews::ShowForCustomLauncherPage(Profile* profile) {
52 ShowForProfileInternal(profile,
53 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE);
56 void AppListServiceViews::HideCustomLauncherPage() {
57 if (!shower_.IsAppListVisible())
58 return;
60 app_list::ContentsView* contents_view =
61 shower_.app_list()->app_list_main_view()->contents_view();
63 if (contents_view->IsStateActive(
64 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) {
65 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true);
69 void AppListServiceViews::DismissAppList() {
70 if (!can_dismiss_)
71 return;
73 shower_.DismissAppList();
76 bool AppListServiceViews::IsAppListVisible() const {
77 return shower_.IsAppListVisible();
80 gfx::NativeWindow AppListServiceViews::GetAppListWindow() {
81 return shower_.GetWindow();
84 Profile* AppListServiceViews::GetCurrentAppListProfile() {
85 return shower_.profile();
88 AppListControllerDelegate* AppListServiceViews::GetControllerDelegate() {
89 return controller_delegate_.get();
92 void AppListServiceViews::CreateForProfile(Profile* requested_profile) {
93 DCHECK(requested_profile);
94 InvalidatePendingProfileLoads();
95 shower_.CreateViewForProfile(requested_profile);
96 SetProfilePath(shower_.profile()->GetPath());
99 void AppListServiceViews::DestroyAppList() {
100 if (!shower_.HasView())
101 return;
103 // Use CloseNow(). This can't be asynchronous because the profile will be
104 // deleted once this function returns.
105 shower_.app_list()->GetWidget()->CloseNow();
106 DCHECK(!shower_.HasView());
109 AppListViewDelegate* AppListServiceViews::GetViewDelegateForCreate() {
110 return GetViewDelegate(shower_.profile());
113 void AppListServiceViews::ShowForProfileInternal(
114 Profile* profile,
115 app_list::AppListModel::State state) {
116 DCHECK(profile);
118 ScopedKeepAlive keep_alive;
120 CreateForProfile(profile);
122 if (state != app_list::AppListModel::INVALID_STATE) {
123 app_list::ContentsView* contents_view =
124 shower_.app_list()->app_list_main_view()->contents_view();
125 contents_view->SetActiveState(state,
126 shower_.IsAppListVisible() /* animate */);
129 shower_.ShowForCurrentProfile();
130 RecordAppListLaunch();