app_list_service_impl.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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_IMPL_H_
6#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/weak_ptr.h"
14#include "chrome/browser/profiles/profile.h"
15#include "chrome/browser/profiles/profile_info_cache_observer.h"
16#include "chrome/browser/profiles/profile_loader.h"
17#include "chrome/browser/ui/app_list/app_list_service.h"
18
19namespace base {
20class FilePath;
21}
22
23// Parts of the AppListService implementation shared between platforms.
24class AppListServiceImpl : public AppListService,
25                           public ProfileInfoCacheObserver {
26 public:
27  static void RecordAppListLaunch();
28  static void RecordAppListAppLaunch();
29
30 protected:
31  AppListServiceImpl();
32  virtual ~AppListServiceImpl();
33
34  Profile* profile() const { return profile_; }
35  void SetProfile(Profile* new_profile);
36  void InvalidatePendingProfileLoads();
37  ProfileLoader& profile_loader() { return profile_loader_; }
38  const ProfileLoader& profile_loader() const { return profile_loader_; }
39
40  // Process command line flags shared between desktop implementations of the
41  // app list. Currently this allows for enabling or disabling the app list.
42  void HandleCommandLineFlags(Profile* initial_profile);
43
44  // Create a platform-specific shortcut for the app list.
45  virtual void CreateShortcut();
46
47  // AppListService overrides:
48  virtual void SetAppListNextPaintCallback(
49      const base::Closure& callback) OVERRIDE;
50  virtual void HandleFirstRun() OVERRIDE;
51  virtual void Init(Profile* initial_profile) OVERRIDE;
52
53  // Returns the app list path configured in BrowserProcess::local_state().
54  virtual base::FilePath GetProfilePath(
55      const base::FilePath& user_data_dir) OVERRIDE;
56  virtual void SetProfilePath(const base::FilePath& profile_path) OVERRIDE;
57  virtual void Show() OVERRIDE;
58  virtual void EnableAppList(Profile* initial_profile) OVERRIDE;
59
60 private:
61  static void SendAppListStats();
62
63  // Loads a profile asynchronously and calls OnProfileLoaded() when done.
64  void LoadProfileAsync(const base::FilePath& profile_file_path);
65
66  // Callback for asynchronous profile load.
67  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