Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / app_list_service_impl.h
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/profile_loader.h"
19
20 class AppListViewDelegate;
21 class ProfileStore;
22
23 namespace base {
24 class FilePath;
25 }
26
27 namespace test {
28 class AppListServiceImplTestApi;
29 }
30
31 // Parts of the AppListService implementation shared between platforms.
32 class AppListServiceImpl : public AppListService,
33                            public ProfileInfoCacheObserver {
34  public:
35   ~AppListServiceImpl() override;
36
37   // Constructor used for testing.
38   AppListServiceImpl(const base::CommandLine& command_line,
39                      PrefService* local_state,
40                      scoped_ptr<ProfileStore> profile_store);
41
42   // Lazily create the Chrome AppListViewDelegate and ensure it is set to the
43   // given |profile|.
44   AppListViewDelegate* GetViewDelegate(Profile* profile);
45
46   void RecordAppListLaunch();
47   static void RecordAppListAppLaunch();
48
49   // AppListService overrides:
50   void SetAppListNextPaintCallback(void (*callback)()) override;
51   void HandleFirstRun() override;
52   void Init(Profile* initial_profile) override;
53   base::FilePath GetProfilePath(const base::FilePath& user_data_dir) override;
54   void SetProfilePath(const base::FilePath& profile_path) override;
55   void Show() override;
56   void ShowForVoiceSearch(Profile* profile) override;
57   void ShowForAppInstall(Profile* profile,
58                          const std::string& extension_id,
59                          bool start_discovery_tracking) override;
60   void EnableAppList(Profile* initial_profile,
61                      AppListEnableSource enable_source) override;
62   void CreateShortcut() override;
63
64  protected:
65   AppListServiceImpl();
66
67   // Create the app list UI, and maintain its state, but do not show it.
68   virtual void CreateForProfile(Profile* requested_profile) = 0;
69
70   // Destroy the app list. Called when the profile that the app list is showing
71   // is being deleted.
72   virtual void DestroyAppList() = 0;
73
74   void InvalidatePendingProfileLoads();
75   ProfileLoader& profile_loader() { return *profile_loader_; }
76   const ProfileLoader& profile_loader() const { return *profile_loader_; }
77
78   // Perform startup checks shared between desktop implementations of the app
79   // list. Currently this checks command line flags to enable or disable the app
80   // list, and records UMA stats delayed from a previous Chrome process.
81   void PerformStartupChecks(Profile* initial_profile);
82
83  private:
84   friend class test::AppListServiceImplTestApi;
85   static void SendAppListStats();
86
87   // Loads a profile asynchronously and calls OnProfileLoaded() when done.
88   void LoadProfileAsync(const base::FilePath& profile_file_path);
89
90   // Callback for asynchronous profile load.
91   void OnProfileLoaded(int profile_load_sequence_id,
92                        Profile* profile,
93                        Profile::CreateStatus status);
94
95   // ProfileInfoCacheObserver overrides:
96   void OnProfileWillBeRemoved(const base::FilePath& profile_path) override;
97
98   scoped_ptr<ProfileStore> profile_store_;
99   base::CommandLine command_line_;
100   PrefService* local_state_;
101   scoped_ptr<ProfileLoader> profile_loader_;
102   scoped_ptr<AppListViewDelegate> view_delegate_;
103
104   base::WeakPtrFactory<AppListServiceImpl> weak_factory_;
105
106   DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl);
107 };
108
109 #endif  // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_