app_list_service_impl.h revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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 "content/public/browser/notification_observer.h" 18#include "content/public/browser/notification_registrar.h" 19 20namespace base { 21class FilePath; 22} 23 24namespace content { 25class NotificationSource; 26class NotificationDetails; 27} 28 29// Parts of the AppListService implementation shared between platforms. 30class AppListServiceImpl : public AppListService, 31 public ProfileInfoCacheObserver, 32 public content::NotificationObserver { 33 public: 34 static void RecordAppListLaunch(); 35 static void RecordAppListAppLaunch(); 36 static void SendAppListStats(); 37 38 protected: 39 AppListServiceImpl(); 40 virtual ~AppListServiceImpl(); 41 42 Profile* profile() const { return profile_; } 43 void SetProfile(Profile* new_profile); 44 void InvalidatePendingProfileLoads(); 45 46 // Save |profile_file_path| as the app list profile in local state. 47 void SaveProfilePathToLocalState(const base::FilePath& profile_file_path); 48 49 // Perform shared AppListService warmup tasks, possibly calling 50 // DoWarmupForProfile() after loading the configured profile. 51 void ScheduleWarmup(); 52 53 // Return true if there is a current UI view for the app list. 54 virtual bool HasCurrentView() const; 55 56 // Called when |initial_profile| is loaded and ready to use during warmup. 57 virtual void DoWarmupForProfile(Profile* initial_profile); 58 59 // Called in response to observed successful and unsuccessful signin changes. 60 virtual void OnSigninStatusChanged(); 61 62 // AppListService overrides: 63 virtual void Init(Profile* initial_profile) OVERRIDE; 64 virtual base::FilePath GetAppListProfilePath( 65 const base::FilePath& user_data_dir) OVERRIDE; 66 67 virtual void ShowForSavedProfile() OVERRIDE; 68 virtual AppListControllerDelegate* CreateControllerDelegate() OVERRIDE; 69 70 private: 71 // Loads a profile asynchronously and calls OnProfileLoaded() when done. 72 void LoadProfileAsync(const base::FilePath& profile_file_path); 73 74 // Callback for asynchronous profile load. 75 void OnProfileLoaded(int profile_load_sequence_id, 76 Profile* profile, 77 Profile::CreateStatus status); 78 79 // Loads the profile last used with the app list and populates the view from 80 // it without showing it so that the next show is faster. Does nothing if the 81 // view already exists, or another profile is in the middle of being loaded to 82 // be shown. 83 void LoadProfileForInit(); 84 void OnProfileLoadedForInit(int profile_load_sequence_id, 85 Profile* profile, 86 Profile::CreateStatus status); 87 88 // We need to keep the browser alive while we are loading a profile as that 89 // shows intent to show the app list. These two functions track our pending 90 // profile loads and start or end browser keep alive accordingly. 91 void IncrementPendingProfileLoads(); 92 void DecrementPendingProfileLoads(); 93 bool IsInitViewNeeded() const; 94 95 // AppListService overrides: 96 // Update the profile path stored in local prefs, load it (if not already 97 // loaded), and show the app list. 98 virtual void SetAppListProfile( 99 const base::FilePath& profile_file_path) OVERRIDE; 100 101 virtual Profile* GetCurrentAppListProfile() OVERRIDE; 102 103 // ProfileInfoCacheObserver overrides: 104 virtual void OnProfileAdded(const base::FilePath& profilePath) OVERRIDE; 105 virtual void OnProfileWillBeRemoved( 106 const base::FilePath& profile_path) OVERRIDE; 107 virtual void OnProfileWasRemoved(const base::FilePath& profile_path, 108 const string16& profile_name) OVERRIDE; 109 virtual void OnProfileNameChanged(const base::FilePath& profile_path, 110 const string16& profile_name) OVERRIDE; 111 virtual void OnProfileAvatarChanged( 112 const base::FilePath& profile_path) OVERRIDE; 113 114 // content::NotificationObserver 115 virtual void Observe(int type, 116 const content::NotificationSource& source, 117 const content::NotificationDetails& details) OVERRIDE; 118 119 // The profile the AppList is currently displaying. 120 Profile* profile_; 121 122 // Incremented to indicate that pending profile loads are no longer valid. 123 int profile_load_sequence_id_; 124 125 // How many profile loads are pending. 126 int pending_profile_loads_; 127 128 base::WeakPtrFactory<AppListServiceImpl> weak_factory_; 129 content::NotificationRegistrar registrar_; 130 131 DISALLOW_COPY_AND_ASSIGN(AppListServiceImpl); 132}; 133 134#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_IMPL_H_ 135