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 #include "chrome/browser/ui/app_list/profile_loader.h" | 5 #include "chrome/browser/profiles/profile_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
12 | 12 |
13 ProfileLoader::ProfileLoader(ProfileManager* profile_manager) | 13 ProfileLoader::ProfileLoader(ProfileManager* profile_manager) |
14 : profile_manager_(profile_manager), | 14 : profile_manager_(profile_manager), |
15 profile_load_sequence_id_(0), | 15 profile_load_sequence_id_(0), |
16 pending_profile_loads_(0), | 16 pending_profile_loads_(0), |
17 weak_factory_(this) { | 17 weak_factory_(this) { |
18 } | 18 } |
19 | 19 |
20 ProfileLoader::~ProfileLoader() { | 20 ProfileLoader::~ProfileLoader() { |
21 } | 21 } |
22 | 22 |
23 bool ProfileLoader::AnyProfilesLoading() const { | 23 bool ProfileLoader::IsAnyProfileLoading() const { |
24 return pending_profile_loads_ > 0; | 24 return pending_profile_loads_ > 0; |
25 } | 25 } |
26 | 26 |
27 void ProfileLoader::InvalidatePendingProfileLoads() { | 27 void ProfileLoader::InvalidatePendingProfileLoads() { |
28 profile_load_sequence_id_++; | 28 ++profile_load_sequence_id_; |
29 } | 29 } |
30 | 30 |
31 void ProfileLoader::LoadProfileInvalidatingOtherLoads( | 31 void ProfileLoader::LoadProfileInvalidatingOtherLoads( |
32 const base::FilePath& profile_file_path, | 32 const base::FilePath& profile_file_path, |
33 base::Callback<void(Profile*)> callback) { | 33 base::Callback<void(Profile*)> callback) { |
34 Profile* profile = profile_manager_->GetProfileByPath(profile_file_path); | 34 InvalidatePendingProfileLoads(); |
| 35 |
| 36 Profile* profile = GetProfileByPath(profile_file_path); |
35 if (profile) { | 37 if (profile) { |
36 callback.Run(profile); | 38 callback.Run(profile); |
37 return; | 39 return; |
38 } | 40 } |
39 | 41 |
40 IncrementPendingProfileLoads(); | 42 IncrementPendingProfileLoads(); |
41 profile_manager_->CreateProfileAsync( | 43 CreateProfileAsync( |
42 profile_file_path, | 44 profile_file_path, |
43 base::Bind(&ProfileLoader::OnProfileLoaded, | 45 base::Bind(&ProfileLoader::OnProfileLoaded, |
44 weak_factory_.GetWeakPtr(), | 46 weak_factory_.GetWeakPtr(), |
45 profile_load_sequence_id_, | 47 profile_load_sequence_id_, |
46 callback), | 48 callback), |
47 string16(), string16(), false); | 49 string16(), string16(), false); |
48 } | 50 } |
49 | 51 |
| 52 Profile* ProfileLoader::GetProfileByPath(const base::FilePath& path) { |
| 53 return profile_manager_->GetProfileByPath(path); |
| 54 } |
| 55 |
| 56 void ProfileLoader::CreateProfileAsync( |
| 57 const base::FilePath& profile_path, |
| 58 const ProfileManager::CreateCallback& callback, |
| 59 const string16& name, |
| 60 const string16& icon_url, |
| 61 bool is_managed) { |
| 62 profile_manager_->CreateProfileAsync( |
| 63 profile_path, callback, name, icon_url, is_managed); |
| 64 } |
| 65 |
50 void ProfileLoader::OnProfileLoaded(int profile_load_sequence_id, | 66 void ProfileLoader::OnProfileLoaded(int profile_load_sequence_id, |
51 base::Callback<void(Profile*)> callback, | 67 base::Callback<void(Profile*)> callback, |
52 Profile* profile, | 68 Profile* profile, |
53 Profile::CreateStatus status) { | 69 Profile::CreateStatus status) { |
54 switch (status) { | 70 switch (status) { |
55 case Profile::CREATE_STATUS_CREATED: | 71 case Profile::CREATE_STATUS_CREATED: |
56 break; | 72 break; |
57 case Profile::CREATE_STATUS_INITIALIZED: | 73 case Profile::CREATE_STATUS_INITIALIZED: |
58 if (profile_load_sequence_id == profile_load_sequence_id_) | 74 if (profile_load_sequence_id == profile_load_sequence_id_) |
59 callback.Run(profile); | 75 callback.Run(profile); |
(...skipping 14 matching lines...) Expand all Loading... |
74 pending_profile_loads_++; | 90 pending_profile_loads_++; |
75 if (pending_profile_loads_ == 1) | 91 if (pending_profile_loads_ == 1) |
76 chrome::StartKeepAlive(); | 92 chrome::StartKeepAlive(); |
77 } | 93 } |
78 | 94 |
79 void ProfileLoader::DecrementPendingProfileLoads() { | 95 void ProfileLoader::DecrementPendingProfileLoads() { |
80 pending_profile_loads_--; | 96 pending_profile_loads_--; |
81 if (pending_profile_loads_ == 0) | 97 if (pending_profile_loads_ == 0) |
82 chrome::EndKeepAlive(); | 98 chrome::EndKeepAlive(); |
83 } | 99 } |
OLD | NEW |