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::AnyProfilesLoading() 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_++; |
sail
2013/06/13 15:10:16
Use prefix? ++profile_load_sequence_id_
jackhou1
2013/06/14 09:13:28
Done.
| |
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 Profile* profile = profile_manager_->GetProfileByPath(profile_file_path); |
35 if (profile) { | 35 if (profile) { |
36 callback.Run(profile); | 36 callback.Run(profile); |
37 return; | 37 return; |
38 } | 38 } |
39 | 39 |
40 IncrementPendingProfileLoads(); | 40 IncrementPendingProfileLoads(); |
41 profile_manager_->CreateProfileAsync( | 41 profile_manager_->CreateProfileAsync( |
42 profile_file_path, | 42 profile_file_path, |
43 base::Bind(&ProfileLoader::OnProfileLoaded, | 43 base::Bind(&ProfileLoader::OnProfileLoaded, |
44 weak_factory_.GetWeakPtr(), | 44 weak_factory_.GetWeakPtr(), |
45 profile_load_sequence_id_, | 45 profile_load_sequence_id_, |
sail
2013/06/13 15:10:16
Shouldn't this function increment profile_load_seq
jackhou1
2013/06/14 09:13:28
Done.
| |
46 callback), | 46 callback), |
47 string16(), string16(), false); | 47 string16(), string16(), false); |
48 } | 48 } |
49 | 49 |
50 void ProfileLoader::OnProfileLoaded(int profile_load_sequence_id, | 50 void ProfileLoader::OnProfileLoaded(int profile_load_sequence_id, |
51 base::Callback<void(Profile*)> callback, | 51 base::Callback<void(Profile*)> callback, |
52 Profile* profile, | 52 Profile* profile, |
53 Profile::CreateStatus status) { | 53 Profile::CreateStatus status) { |
54 switch (status) { | 54 switch (status) { |
55 case Profile::CREATE_STATUS_CREATED: | 55 case Profile::CREATE_STATUS_CREATED: |
(...skipping 18 matching lines...) Expand all Loading... | |
74 pending_profile_loads_++; | 74 pending_profile_loads_++; |
75 if (pending_profile_loads_ == 1) | 75 if (pending_profile_loads_ == 1) |
76 chrome::StartKeepAlive(); | 76 chrome::StartKeepAlive(); |
77 } | 77 } |
78 | 78 |
79 void ProfileLoader::DecrementPendingProfileLoads() { | 79 void ProfileLoader::DecrementPendingProfileLoads() { |
80 pending_profile_loads_--; | 80 pending_profile_loads_--; |
81 if (pending_profile_loads_ == 0) | 81 if (pending_profile_loads_ == 0) |
82 chrome::EndKeepAlive(); | 82 chrome::EndKeepAlive(); |
83 } | 83 } |
OLD | NEW |