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_PROFILE_LOADER_H_
6 #define CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
16 class ProfileLoaderUnittest
;
18 class ScopedKeepAlive
;
20 // This class loads profiles asynchronously and calls the provided callback once
21 // the profile is ready. Only the callback for the most recent load request is
22 // called, and only if the load was successful.
24 // This is useful for loading profiles in response to user interaction where
25 // only the latest requested profile is required.
26 // TODO(koz): Merge this into AppListServiceImpl.
29 explicit ProfileLoader(ProfileStore
* profile_store
);
32 bool IsAnyProfileLoading() const;
33 void InvalidatePendingProfileLoads();
34 void LoadProfileInvalidatingOtherLoads(
35 const base::FilePath
& profile_file_path
,
36 base::Callback
<void(Profile
*)> callback
);
39 friend class ::ProfileLoaderUnittest
;
41 void OnProfileLoaded(int profile_load_sequence_id
,
42 base::Callback
<void(Profile
*)> callback
,
45 void IncrementPendingProfileLoads();
46 void DecrementPendingProfileLoads();
48 ProfileStore
* profile_store_
;
49 scoped_ptr
<ScopedKeepAlive
> keep_alive_
;
50 int profile_load_sequence_id_
;
51 int pending_profile_loads_
;
53 base::WeakPtrFactory
<ProfileLoader
> weak_factory_
;
55 DISALLOW_COPY_AND_ASSIGN(ProfileLoader
);
58 #endif // CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_