profile_loader.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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_PROFILE_LOADER_H_ 6#define CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_ 7 8#include "base/callback.h" 9#include "base/memory/scoped_ptr.h" 10#include "base/memory/weak_ptr.h" 11#include "chrome/browser/profiles/profile.h" 12#include "chrome/browser/profiles/profile_manager.h" 13#include "chrome/browser/ui/app_list/keep_alive_service.h" 14#include "chrome/browser/ui/app_list/profile_store.h" 15 16namespace base { 17class FilePath; 18} 19 20class ProfileManager; 21 22// This class loads profiles asynchronously and calls the provided callback once 23// the profile is ready. Only the callback for the most recent load request is 24// called, and only if the load was successful. 25// 26// This is useful for loading profiles in response to user interaction where 27// only the latest requested profile is required. 28// TODO(koz): Merge this into AppListServiceImpl. 29class ProfileLoader { 30 public: 31 explicit ProfileLoader(ProfileStore* profile_store, 32 scoped_ptr<KeepAliveService> keep_alive_service); 33 ~ProfileLoader(); 34 35 bool IsAnyProfileLoading() const; 36 void InvalidatePendingProfileLoads(); 37 void LoadProfileInvalidatingOtherLoads( 38 const base::FilePath& profile_file_path, 39 base::Callback<void(Profile*)> callback); 40 41 private: 42 void OnProfileLoaded(int profile_load_sequence_id, 43 base::Callback<void(Profile*)> callback, 44 Profile* profile); 45 46 void IncrementPendingProfileLoads(); 47 void DecrementPendingProfileLoads(); 48 49 ProfileStore* profile_store_; 50 scoped_ptr<KeepAliveService> keep_alive_service_; 51 int profile_load_sequence_id_; 52 int pending_profile_loads_; 53 54 base::WeakPtrFactory<ProfileLoader> weak_factory_; 55 56 DISALLOW_COPY_AND_ASSIGN(ProfileLoader); 57}; 58 59#endif // CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_ 60