app_list_service_impl.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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/command_line.h"
12#include "base/compiler_specific.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/memory/weak_ptr.h"
15#include "chrome/browser/profiles/profile.h"
16#include "chrome/browser/profiles/profile_info_cache_observer.h"
17#include "chrome/browser/ui/app_list/app_list_service.h"
18#include "chrome/browser/ui/app_list/keep_alive_service.h"
19#include "chrome/browser/ui/app_list/profile_loader.h"
20
21class ProfileStore;
22
23namespace base {
24class FilePath;
25}
26
27// Parts of the AppListService implementation shared between platforms.
28class AppListServiceImpl : public AppListService,
29                           public ProfileInfoCacheObserver {
30 public:
31  static void RecordAppListLaunch();
32  static void RecordAppListAppLaunch();
33  virtual ~AppListServiceImpl();
34
35  // Constructor used for testing.
36  AppListServiceImpl(const CommandLine& command_line,
37                     PrefService* local_state,
38                     scoped_ptr<ProfileStore> profile_store,
39                     scoped_ptr<KeepAliveService> keep_alive_service);
40
41  // AppListService overrides:
42  virtual void SetAppListNextPaintCallback(
43      const base::Closure& callback) OVERRIDE;
44  virtual void HandleFirstRun() OVERRIDE;
45  virtual void Init(Profile* initial_profile) OVERRIDE;
46  virtual base::FilePath GetProfilePath(
47      const base::FilePath& user_data_dir) OVERRIDE;
48  virtual void SetProfilePath(const base::FilePath& profile_path) OVERRIDE;
49  virtual void Show() OVERRIDE;
50  virtual void EnableAppList(Profile* initial_profile) OVERRIDE;
51
52 protected:
53  AppListServiceImpl();
54
55  Profile* profile() const { return profile_; }
56  void SetProfile(Profile* new_profile);
57  void InvalidatePendingProfileLoads();
58  ProfileLoader& profile_loader() { return *profile_loader_; }
59  const ProfileLoader& profile_loader() const { return *profile_loader_; }
60
61  // Process command line flags shared between desktop implementations of the
62  // app list. Currently this allows for enabling or disabling the app list.
63  void HandleCommandLineFlags(Profile* initial_profile);
64
65  // Records UMA stats that try to approximate usage after a delay.
66  void SendUsageStats();
67
68  // Create a platform-specific shortcut for the app list.
69  virtual void CreateShortcut();
70
71 private:
72  static void SendAppListStats();
73
74  // Loads a profile asynchronously and calls OnProfileLoaded() when done.
75  void LoadProfileAsync(const base::FilePath& profile_file_path);
76
77  // Callback for asynchronous profile load.
78  void OnProfileLoaded(int profile_load_sequence_id,
79                       Profile* profile,
80                       Profile::CreateStatus status);
81
82  virtual Profile* GetCurrentAppListProfile() OVERRIDE;
83
84  // ProfileInfoCacheObserver overrides:
85  virtual void OnProfileWillBeRemoved(
86      const base::FilePath& profile_path) OVERRIDE;
87
88  // The profile the AppList is currently displaying.
89  Profile* profile_;
90  scoped_ptr<ProfileStore> profile_store_;
91
92  base::WeakPtrFactory<AppListServiceImpl> weak_factory_;
93
94  CommandLine command_line_;
95  PrefService* local_state_;
96  scoped_ptr<ProfileLoader> profile_loader_;
97
98  DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl);
99};
100
101#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
102