app_list_service_impl.h revision 3551c9c881056c480085172ff9840cab31610854
1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/basictypes.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/compiler_specific.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/weak_ptr.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/profiles/profile_info_cache_observer.h"
16a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "chrome/browser/profiles/profile_loader.h"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_service.h"
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace base {
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class FilePath;
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Parts of the AppListService implementation shared between platforms.
24a3f7b4e666c476898878fa745f637129375cd889Ben Murdochclass AppListServiceImpl : public AppListService,
2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                           public ProfileInfoCacheObserver {
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static void RecordAppListLaunch();
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static void RecordAppListAppLaunch();
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static void SendAppListStats();
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected:
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AppListServiceImpl();
33d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  virtual ~AppListServiceImpl();
34d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
35d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  Profile* profile() const { return profile_; }
36d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  void SetProfile(Profile* new_profile);
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void InvalidatePendingProfileLoads();
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ProfileLoader& profile_loader() { return profile_loader_; }
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const ProfileLoader& profile_loader() const { return profile_loader_; }
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Process command line flags shared between desktop implementations of the
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // app list. Currently this allows for enabling or disabling the app list.
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void HandleCommandLineFlags(Profile* initial_profile);
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Create a platform-specific shortcut for the app list.
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void CreateShortcut();
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
48d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  // AppListService overrides:
49d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  virtual void SetAppListNextPaintCallback(
50d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch      const base::Closure& callback) OVERRIDE;
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void HandleFirstRun() OVERRIDE;
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void Init(Profile* initial_profile) OVERRIDE;
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Returns the app list path configured in BrowserProcess::local_state().
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual base::FilePath GetProfilePath(
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const base::FilePath& user_data_dir) OVERRIDE;
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void SetProfilePath(const base::FilePath& profile_path) OVERRIDE;
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void Show() OVERRIDE;
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void EnableAppList(Profile* initial_profile) OVERRIDE;
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual AppListControllerDelegate* CreateControllerDelegate() OVERRIDE;
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
62a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch private:
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Loads a profile asynchronously and calls OnProfileLoaded() when done.
643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  void LoadProfileAsync(const base::FilePath& profile_file_path);
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Callback for asynchronous profile load.
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void OnProfileLoaded(int profile_load_sequence_id,
68                       Profile* profile,
69                       Profile::CreateStatus status);
70
71  virtual Profile* GetCurrentAppListProfile() OVERRIDE;
72
73  // ProfileInfoCacheObserver overrides:
74  virtual void OnProfileWillBeRemoved(
75      const base::FilePath& profile_path) OVERRIDE;
76
77  // The profile the AppList is currently displaying.
78  Profile* profile_;
79
80  // Incremented to indicate that pending profile loads are no longer valid.
81  int profile_load_sequence_id_;
82
83  // How many profile loads are pending.
84  int pending_profile_loads_;
85
86  base::WeakPtrFactory<AppListServiceImpl> weak_factory_;
87
88  ProfileLoader profile_loader_;
89
90  DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl);
91};
92
93#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
94