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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_H_
6#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "chrome/browser/ui/host_desktop.h"
13#include "ui/gfx/native_widget_types.h"
14
15class AppListControllerDelegate;
16class PrefRegistrySimple;
17class Profile;
18
19namespace base {
20class CommandLine;
21class FilePath;
22}
23
24namespace gfx {
25class ImageSkia;
26}
27
28class AppListService {
29 public:
30  // Source that triggers the app launcher being enabled. This is used for UMA
31  // to track discoverability of the app lancher shortcut after install. Also
32  // used to provide custom install behavior (e.g. "always" enable).
33  enum AppListEnableSource {
34    ENABLE_NOT_RECORDED,        // Indicates app launcher not recently enabled.
35    ENABLE_FOR_APP_INSTALL,     // Triggered by a webstore packaged app install.
36    ENABLE_VIA_WEBSTORE_LINK,   // Triggered by webstore explicitly via API.
37    ENABLE_VIA_COMMAND_LINE,    // Triggered by --enable-app-list.
38    ENABLE_ON_REINSTALL,        // Triggered by Chrome reinstall finding pref.
39    ENABLE_SHOWN_UNDISCOVERED,  // This overrides a prior ENABLE_FOR_APP_INSTALL
40                                // when the launcher is auto-shown without
41                                // being "discovered" beforehand.
42    ENABLE_NUM_ENABLE_SOURCES
43  };
44
45  // Get the AppListService for the current platform and specified
46  // |desktop_type|.
47  static AppListService* Get(chrome::HostDesktopType desktop_type);
48
49  // Call Init for all AppListService instances on this platform.
50  static void InitAll(Profile* initial_profile);
51
52  static void RegisterPrefs(PrefRegistrySimple* registry);
53
54  // Initializes the AppListService, and returns true if |command_line| is for
55  // showing the app list.
56  static bool HandleLaunchCommandLine(const base::CommandLine& command_line,
57                                      Profile* launch_profile);
58
59  // Indicates that |callback| should be called next time the app list is
60  // painted.
61  virtual void SetAppListNextPaintCallback(void (*callback)()) = 0;
62
63  // Perform Chrome first run logic. This is executed before Chrome's threads
64  // have been created.
65  virtual void HandleFirstRun() = 0;
66
67  virtual base::FilePath GetProfilePath(
68      const base::FilePath& user_data_dir) = 0;
69  virtual void SetProfilePath(const base::FilePath& profile_path) = 0;
70
71  // Show the app list for the profile configured in the user data dir for the
72  // current browser process.
73  virtual void Show() = 0;
74
75  // Create the app list UI, and maintain its state, but do not show it.
76  virtual void CreateForProfile(Profile* requested_profile) = 0;
77
78  // Show the app list for the given profile. If it differs from the profile the
79  // app list is currently showing, repopulate the app list and save the new
80  // profile to local prefs as the default app list profile.
81  virtual void ShowForProfile(Profile* requested_profile) = 0;
82
83  // Show the app list due to a trigger which was not an explicit user action
84  // to show the app list. E.g. the auto-show when installing an app. This
85  // permits UMA to distinguish between a user discovering the app list shortcut
86  // themselves versus having it shown for them automatically.
87  virtual void AutoShowForProfile(Profile* requested_profile) = 0;
88
89  // Dismiss the app list.
90  virtual void DismissAppList() = 0;
91
92  // Get the profile the app list is currently showing.
93  virtual Profile* GetCurrentAppListProfile() = 0;
94
95  // Returns true if the app list is visible.
96  virtual bool IsAppListVisible() const = 0;
97
98  // Enable the app list. What this does specifically will depend on the host
99  // operating system and shell.
100  virtual void EnableAppList(Profile* initial_profile,
101                             AppListEnableSource enable_source) = 0;
102
103  // Get the window the app list is in, or NULL if the app list isn't visible.
104  virtual gfx::NativeWindow GetAppListWindow() = 0;
105
106  // Returns a pointer to the platform specific AppListControllerDelegate.
107  virtual AppListControllerDelegate* GetControllerDelegate() = 0;
108
109  // Create a platform-specific shortcut for the app list.
110  virtual void CreateShortcut() = 0;
111
112 protected:
113  AppListService() {}
114  virtual ~AppListService() {}
115
116  // Do any once off initialization needed for the app list.
117  virtual void Init(Profile* initial_profile) = 0;
118
119 private:
120  DISALLOW_COPY_AND_ASSIGN(AppListService);
121};
122
123#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_H_
124