app_list_service_impl.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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/ui/app_list/app_list_service.h"
17#include "chrome/browser/ui/app_list/profile_loader.h"
18#include "content/public/browser/notification_observer.h"
19#include "content/public/browser/notification_registrar.h"
20
21namespace base {
22class FilePath;
23}
24
25namespace content {
26class NotificationSource;
27class NotificationDetails;
28}
29
30// Parts of the AppListService implementation shared between platforms.
31class AppListServiceImpl : public AppListService,
32                           public ProfileInfoCacheObserver,
33                           public content::NotificationObserver {
34 public:
35  static void RecordAppListLaunch();
36  static void RecordAppListAppLaunch();
37  static void SendAppListStats();
38
39 protected:
40  AppListServiceImpl();
41  virtual ~AppListServiceImpl();
42
43  Profile* profile() const { return profile_; }
44  void SetProfile(Profile* new_profile);
45  void InvalidatePendingProfileLoads();
46  ProfileLoader& profile_loader() { return profile_loader_; }
47  const ProfileLoader& profile_loader() const { return profile_loader_; }
48
49  // Save |profile_file_path| as the app list profile in local state.
50  void SaveProfilePathToLocalState(const base::FilePath& profile_file_path);
51
52  // Called in response to observed successful and unsuccessful signin changes.
53  virtual void OnSigninStatusChanged();
54
55  // AppListService overrides:
56  virtual void Init(Profile* initial_profile) OVERRIDE;
57  virtual base::FilePath GetProfilePath(
58      const base::FilePath& user_data_dir) OVERRIDE;
59
60  virtual void ShowForSavedProfile() OVERRIDE;
61  virtual AppListControllerDelegate* CreateControllerDelegate() OVERRIDE;
62
63 private:
64  // Loads a profile asynchronously and calls OnProfileLoaded() when done.
65  void LoadProfileAsync(const base::FilePath& profile_file_path);
66
67  // Callback for asynchronous profile load.
68  void OnProfileLoaded(int profile_load_sequence_id,
69                       Profile* profile,
70                       Profile::CreateStatus status);
71
72  // AppListService overrides:
73  // Update the profile path stored in local prefs, load it (if not already
74  // loaded), and show the app list.
75  virtual void SetAppListProfile(
76      const base::FilePath& profile_file_path) OVERRIDE;
77
78  virtual Profile* GetCurrentAppListProfile() OVERRIDE;
79
80  // ProfileInfoCacheObserver overrides:
81  virtual void OnProfileAdded(const base::FilePath& profilePath) OVERRIDE;
82  virtual void OnProfileWillBeRemoved(
83      const base::FilePath& profile_path) OVERRIDE;
84  virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
85                                   const string16& profile_name) OVERRIDE;
86  virtual void OnProfileNameChanged(const base::FilePath& profile_path,
87                                    const string16& profile_name) OVERRIDE;
88  virtual void OnProfileAvatarChanged(
89      const base::FilePath& profile_path) OVERRIDE;
90
91  // content::NotificationObserver
92  virtual void Observe(int type,
93                       const content::NotificationSource& source,
94                       const content::NotificationDetails& details) OVERRIDE;
95
96  // The profile the AppList is currently displaying.
97  Profile* profile_;
98
99  // Incremented to indicate that pending profile loads are no longer valid.
100  int profile_load_sequence_id_;
101
102  // How many profile loads are pending.
103  int pending_profile_loads_;
104
105  base::WeakPtrFactory<AppListServiceImpl> weak_factory_;
106  content::NotificationRegistrar registrar_;
107
108  ProfileLoader profile_loader_;
109
110  DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl);
111};
112
113#endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
114