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 virtual ~AppListServiceImpl();
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 virtual void SetAppListNextPaintCallback(void (*callback)()) OVERRIDE;
51 virtual void HandleFirstRun() OVERRIDE;
52 virtual void Init(Profile* initial_profile) OVERRIDE;
53 virtual base::FilePath GetProfilePath(
54 const base::FilePath& user_data_dir) OVERRIDE;
55 virtual void SetProfilePath(const base::FilePath& profile_path) OVERRIDE;
56 virtual void Show() OVERRIDE;
57 virtual void AutoShowForProfile(Profile* requested_profile) OVERRIDE;
58 virtual void EnableAppList(Profile* initial_profile,
59 AppListEnableSource enable_source) OVERRIDE;
60 virtual void CreateShortcut() OVERRIDE;
65 // Destroy the app list. Called when the profile that the app list is showing
67 virtual void DestroyAppList() = 0;
69 void InvalidatePendingProfileLoads();
70 ProfileLoader& profile_loader() { return *profile_loader_; }
71 const ProfileLoader& profile_loader() const { return *profile_loader_; }
73 // Perform startup checks shared between desktop implementations of the app
74 // list. Currently this checks command line flags to enable or disable the app
75 // list, and records UMA stats delayed from a previous Chrome process.
76 void PerformStartupChecks(Profile* initial_profile);
79 friend class test::AppListServiceImplTestApi;
80 static void SendAppListStats();
82 // Loads a profile asynchronously and calls OnProfileLoaded() when done.
83 void LoadProfileAsync(const base::FilePath& profile_file_path);
85 // Callback for asynchronous profile load.
86 void OnProfileLoaded(int profile_load_sequence_id,
88 Profile::CreateStatus status);
90 // ProfileInfoCacheObserver overrides:
91 virtual void OnProfileWillBeRemoved(
92 const base::FilePath& profile_path) OVERRIDE;
94 scoped_ptr<ProfileStore> profile_store_;
95 base::CommandLine command_line_;
96 PrefService* local_state_;
97 scoped_ptr<ProfileLoader> profile_loader_;
98 scoped_ptr<AppListViewDelegate> view_delegate_;
100 base::WeakPtrFactory<AppListServiceImpl> weak_factory_;
102 DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl);
105 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_