12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AppListControllerDelegate;
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PrefRegistrySimple;
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Profile;
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class CommandLine;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace gfx {
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ImageSkia;
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class AppListService {
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Source that triggers the app launcher being enabled. This is used for UMA
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // to track discoverability of the app lancher shortcut after install. Also
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // used to provide custom install behavior (e.g. "always" enable).
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  enum AppListEnableSource {
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_NOT_RECORDED,        // Indicates app launcher not recently enabled.
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_FOR_APP_INSTALL,     // Triggered by a webstore packaged app install.
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_VIA_WEBSTORE_LINK,   // Triggered by webstore explicitly via API.
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_VIA_COMMAND_LINE,    // Triggered by --enable-app-list.
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_ON_REINSTALL,        // Triggered by Chrome reinstall finding pref.
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_SHOWN_UNDISCOVERED,  // This overrides a prior ENABLE_FOR_APP_INSTALL
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                // when the launcher is auto-shown without
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                // being "discovered" beforehand.
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ENABLE_NUM_ENABLE_SOURCES
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Get the AppListService for the current platform and specified
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |desktop_type|.
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static AppListService* Get(chrome::HostDesktopType desktop_type);
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Call Init for all AppListService instances on this platform.
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void InitAll(Profile* initial_profile);
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void RegisterPrefs(PrefRegistrySimple* registry);
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Initializes the AppListService, and returns true if |command_line| is for
55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // showing the app list.
56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static bool HandleLaunchCommandLine(const base::CommandLine& command_line,
57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                      Profile* launch_profile);
58ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Indicates that |callback| should be called next time the app list is
603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // painted.
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void SetAppListNextPaintCallback(void (*callback)()) = 0;
623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
63ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Perform Chrome first run logic. This is executed before Chrome's threads
64ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // have been created.
65ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  virtual void HandleFirstRun() = 0;
66ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual base::FilePath GetProfilePath(
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const base::FilePath& user_data_dir) = 0;
69ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  virtual void SetProfilePath(const base::FilePath& profile_path) = 0;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
71ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Show the app list for the profile configured in the user data dir for the
72ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // current browser process.
73ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  virtual void Show() = 0;
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Create the app list UI, and maintain its state, but do not show it.
76ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void CreateForProfile(Profile* requested_profile) = 0;
77ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
78ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Show the app list for the given profile. If it differs from the profile the
79ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // app list is currently showing, repopulate the app list and save the new
80ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // profile to local prefs as the default app list profile.
81ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  virtual void ShowForProfile(Profile* requested_profile) = 0;
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Show the app list due to a trigger which was not an explicit user action
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to show the app list. E.g. the auto-show when installing an app. This
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // permits UMA to distinguish between a user discovering the app list shortcut
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // themselves versus having it shown for them automatically.
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void AutoShowForProfile(Profile* requested_profile) = 0;
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Dismiss the app list.
90a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void DismissAppList() = 0;
91a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Get the profile the app list is currently showing.
93a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual Profile* GetCurrentAppListProfile() = 0;
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the app list is visible.
96a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool IsAppListVisible() const = 0;
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Enable the app list. What this does specifically will depend on the host
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // operating system and shell.
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void EnableAppList(Profile* initial_profile,
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             AppListEnableSource enable_source) = 0;
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Get the window the app list is in, or NULL if the app list isn't visible.
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual gfx::NativeWindow GetAppListWindow() = 0;
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns a pointer to the platform specific AppListControllerDelegate.
107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual AppListControllerDelegate* GetControllerDelegate() = 0;
108a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Create a platform-specific shortcut for the app list.
110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void CreateShortcut() = 0;
111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AppListService() {}
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~AppListService() {}
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Do any once off initialization needed for the app list.
117a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void Init(Profile* initial_profile) = 0;
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AppListService);
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_H_
124