d1284dd23c6a45027f1525e6bed093391d73d70b
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / app_list_service_views.cc
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.
4
5 #include "chrome/browser/ui/app_list/app_list_service_views.h"
6
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/views/app_list_view.h"
10
11 AppListServiceViews::AppListServiceViews(
12     scoped_ptr<AppListControllerDelegate> controller_delegate)
13     : shower_(this),
14       can_dismiss_(true),
15       controller_delegate_(controller_delegate.Pass()) {
16 }
17
18 AppListServiceViews::~AppListServiceViews() {}
19
20 void AppListServiceViews::OnViewBeingDestroyed() {
21   can_dismiss_ = true;
22   shower_.HandleViewBeingDestroyed();
23 }
24
25 void AppListServiceViews::Init(Profile* initial_profile) {
26   PerformStartupChecks(initial_profile);
27 }
28
29 void AppListServiceViews::ShowForProfile(Profile* requested_profile) {
30   DCHECK(requested_profile);
31
32   ScopedKeepAlive keep_alive;
33
34   CreateForProfile(requested_profile);
35   shower_.ShowForCurrentProfile();
36   RecordAppListLaunch();
37 }
38
39 void AppListServiceViews::DismissAppList() {
40   if (!can_dismiss_)
41     return;
42
43   shower_.DismissAppList();
44 }
45
46 bool AppListServiceViews::IsAppListVisible() const {
47   return shower_.IsAppListVisible();
48 }
49
50 gfx::NativeWindow AppListServiceViews::GetAppListWindow() {
51   return shower_.GetWindow();
52 }
53
54 Profile* AppListServiceViews::GetCurrentAppListProfile() {
55   return shower_.profile();
56 }
57
58 AppListControllerDelegate* AppListServiceViews::GetControllerDelegate() {
59   return controller_delegate_.get();
60 }
61
62 void AppListServiceViews::CreateForProfile(Profile* requested_profile) {
63   DCHECK(requested_profile);
64   InvalidatePendingProfileLoads();
65   shower_.CreateViewForProfile(requested_profile);
66   SetProfilePath(shower_.profile()->GetPath());
67 }
68
69 void AppListServiceViews::DestroyAppList() {
70   if (!shower_.HasView())
71     return;
72
73   // Use CloseNow(). This can't be asynchronous because the profile will be
74   // deleted once this function returns.
75   shower_.app_list()->GetWidget()->CloseNow();
76   DCHECK(!shower_.HasView());
77 }
78
79 AppListViewDelegate* AppListServiceViews::GetViewDelegateForCreate() {
80   return GetViewDelegate(shower_.profile());
81 }