Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_LOADER_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 class FilePath; | 14 class FilePath; |
| 14 } | 15 } |
| 15 | 16 |
| 16 class ProfileManager; | 17 class ProfileManager; |
| 17 | 18 |
| 19 // This class loads profiles asynchronously and calls the provided callback once | |
| 20 // the profile is ready. Only the callback for the most recent load request is | |
|
sail
2013/06/14 17:05:46
Maybe mention that the callback is not called if l
jackhou1
2013/06/17 04:40:15
Done.
| |
| 21 // called. I.e. calling LoadProfileInvalidatingOtherLoads assumes you no longer | |
| 22 // care about previous load requests. | |
| 18 class ProfileLoader { | 23 class ProfileLoader { |
| 19 public: | 24 public: |
| 20 explicit ProfileLoader(ProfileManager* profile_manager); | 25 explicit ProfileLoader(ProfileManager* profile_manager); |
| 21 ~ProfileLoader(); | 26 ~ProfileLoader(); |
| 22 | 27 |
| 23 bool AnyProfilesLoading() const; | 28 bool IsAnyProfileLoading() const; |
| 24 void InvalidatePendingProfileLoads(); | 29 void InvalidatePendingProfileLoads(); |
| 25 void LoadProfileInvalidatingOtherLoads( | 30 void LoadProfileInvalidatingOtherLoads( |
| 26 const base::FilePath& profile_file_path, | 31 const base::FilePath& profile_file_path, |
| 27 base::Callback<void(Profile*)> callback); | 32 base::Callback<void(Profile*)> callback); |
| 28 | 33 |
| 34 protected: | |
| 35 // These just call through to the ProfileManager. | |
| 36 // Virtual so they can be mocked out in tests. | |
| 37 virtual Profile* GetProfileByPath(const base::FilePath& path); | |
| 38 virtual void CreateProfileAsync( | |
| 39 const base::FilePath& profile_path, | |
| 40 const ProfileManager::CreateCallback& callback, | |
| 41 const string16& name, | |
| 42 const string16& icon_url, | |
| 43 bool is_managed); | |
| 44 | |
| 29 private: | 45 private: |
| 30 void OnProfileLoaded(int profile_load_sequence_id, | 46 void OnProfileLoaded(int profile_load_sequence_id, |
| 31 base::Callback<void(Profile*)> callback, | 47 base::Callback<void(Profile*)> callback, |
| 32 Profile* profile, | 48 Profile* profile, |
| 33 Profile::CreateStatus status); | 49 Profile::CreateStatus status); |
| 34 | 50 |
| 35 void IncrementPendingProfileLoads(); | 51 void IncrementPendingProfileLoads(); |
| 36 void DecrementPendingProfileLoads(); | 52 void DecrementPendingProfileLoads(); |
| 37 | 53 |
| 38 private: | |
| 39 ProfileManager* profile_manager_; | 54 ProfileManager* profile_manager_; |
| 40 int profile_load_sequence_id_; | 55 int profile_load_sequence_id_; |
| 41 int pending_profile_loads_; | 56 int pending_profile_loads_; |
| 42 | 57 |
| 43 base::WeakPtrFactory<ProfileLoader> weak_factory_; | 58 base::WeakPtrFactory<ProfileLoader> weak_factory_; |
| 44 | 59 |
| 45 DISALLOW_COPY_AND_ASSIGN(ProfileLoader); | 60 DISALLOW_COPY_AND_ASSIGN(ProfileLoader); |
| 46 }; | 61 }; |
| 47 | 62 |
| 48 #endif // CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_ | 63 #endif // CHROME_BROWSER_PROFILES_PROFILE_LOADER_H_ |
| OLD | NEW |