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.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_
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"
20 class AppListViewDelegate;
28 class AppListServiceImplTestApi;
31 // Parts of the AppListService implementation shared between platforms.
32 class AppListServiceImpl : public AppListService,
33 public ProfileInfoCacheObserver {
35 ~AppListServiceImpl() override;
37 // Constructor used for testing.
38 AppListServiceImpl(const base::CommandLine& command_line,
39 PrefService* local_state,
40 scoped_ptr<ProfileStore> profile_store);
42 // Lazily create the Chrome AppListViewDelegate and ensure it is set to the
44 AppListViewDelegate* GetViewDelegate(Profile* profile);
46 void RecordAppListLaunch();
47 static void RecordAppListAppLaunch();
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;
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;
67 // Create the app list UI, and maintain its state, but do not show it.
68 virtual void CreateForProfile(Profile* requested_profile) = 0;
70 // Destroy the app list. Called when the profile that the app list is showing
72 virtual void DestroyAppList() = 0;
74 void InvalidatePendingProfileLoads();
75 ProfileLoader& profile_loader() { return *profile_loader_; }
76 const ProfileLoader& profile_loader() const { return *profile_loader_; }
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);
84 friend class test::AppListServiceImplTestApi;
85 static void SendAppListStats();
87 // Loads a profile asynchronously and calls OnProfileLoaded() when done.
88 void LoadProfileAsync(const base::FilePath& profile_file_path);
90 // Callback for asynchronous profile load.
91 void OnProfileLoaded(int profile_load_sequence_id,
93 Profile::CreateStatus status);
95 // ProfileInfoCacheObserver overrides:
96 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override;
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_;
104 base::WeakPtrFactory<AppListServiceImpl> weak_factory_;
106 DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl);
109 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_