app_list_service_impl.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 20class AppListViewDelegate; 21class ProfileStore; 22 23namespace base { 24class FilePath; 25} 26 27namespace test { 28class AppListServiceImplTestApi; 29} 30 31// Parts of the AppListService implementation shared between platforms. 32class AppListServiceImpl : public AppListService, 33 public ProfileInfoCacheObserver { 34 public: 35 virtual ~AppListServiceImpl(); 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 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; 61 62 protected: 63 AppListServiceImpl(); 64 65 // Destroy the app list. Called when the profile that the app list is showing 66 // is being deleted. 67 virtual void DestroyAppList() = 0; 68 69 void InvalidatePendingProfileLoads(); 70 ProfileLoader& profile_loader() { return *profile_loader_; } 71 const ProfileLoader& profile_loader() const { return *profile_loader_; } 72 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); 77 78 private: 79 friend class test::AppListServiceImplTestApi; 80 static void SendAppListStats(); 81 82 // Loads a profile asynchronously and calls OnProfileLoaded() when done. 83 void LoadProfileAsync(const base::FilePath& profile_file_path); 84 85 // Callback for asynchronous profile load. 86 void OnProfileLoaded(int profile_load_sequence_id, 87 Profile* profile, 88 Profile::CreateStatus status); 89 90 // ProfileInfoCacheObserver overrides: 91 virtual void OnProfileWillBeRemoved( 92 const base::FilePath& profile_path) OVERRIDE; 93 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_; 99 100 base::WeakPtrFactory<AppListServiceImpl> weak_factory_; 101 102 DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl); 103}; 104 105#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_ 106