Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / profile_loader.h
blobeb3f3385e7a0471461fc6d5d82799ba98ec4cafe
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/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"
16 namespace base {
17 class FilePath;
20 class ProfileManager;
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.
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.
29 class ProfileLoader {
30 public:
31 explicit ProfileLoader(ProfileStore* profile_store,
32 scoped_ptr<KeepAliveService> keep_alive_service);
33 ~ProfileLoader();
35 bool IsAnyProfileLoading() const;
36 void InvalidatePendingProfileLoads();
37 void LoadProfileInvalidatingOtherLoads(
38 const base::FilePath& profile_file_path,
39 base::Callback<void(Profile*)> callback);
41 private:
42 void OnProfileLoaded(int profile_load_sequence_id,
43 base::Callback<void(Profile*)> callback,
44 Profile* profile);
46 void IncrementPendingProfileLoads();
47 void DecrementPendingProfileLoads();
49 ProfileStore* profile_store_;
50 scoped_ptr<KeepAliveService> keep_alive_service_;
51 int profile_load_sequence_id_;
52 int pending_profile_loads_;
54 base::WeakPtrFactory<ProfileLoader> weak_factory_;
56 DISALLOW_COPY_AND_ASSIGN(ProfileLoader);
59 #endif // CHROME_BROWSER_UI_APP_LIST_PROFILE_LOADER_H_