Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/browser/ui/app_list/profile_loader.cc

Issue 16766003: Move ProfileLoader to chrome/browser/profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gyp-def out profile_loader* on android Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/app_list/profile_loader.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/lifetime/application_lifetime.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12
13 ProfileLoader::ProfileLoader(ProfileManager* profile_manager)
14 : profile_manager_(profile_manager),
15 profile_load_sequence_id_(0),
16 pending_profile_loads_(0),
17 weak_factory_(this) {
18 }
19
20 ProfileLoader::~ProfileLoader() {
21 }
22
23 bool ProfileLoader::AnyProfilesLoading() const {
24 return pending_profile_loads_ > 0;
25 }
26
27 void ProfileLoader::InvalidatePendingProfileLoads() {
28 profile_load_sequence_id_++;
29 }
30
31 void ProfileLoader::LoadProfileInvalidatingOtherLoads(
32 const base::FilePath& profile_file_path,
33 base::Callback<void(Profile*)> callback) {
34 Profile* profile = profile_manager_->GetProfileByPath(profile_file_path);
35 if (profile) {
36 callback.Run(profile);
37 return;
38 }
39
40 IncrementPendingProfileLoads();
41 profile_manager_->CreateProfileAsync(
42 profile_file_path,
43 base::Bind(&ProfileLoader::OnProfileLoaded,
44 weak_factory_.GetWeakPtr(),
45 profile_load_sequence_id_,
46 callback),
47 string16(), string16(), false);
48 }
49
50 void ProfileLoader::OnProfileLoaded(int profile_load_sequence_id,
51 base::Callback<void(Profile*)> callback,
52 Profile* profile,
53 Profile::CreateStatus status) {
54 switch (status) {
55 case Profile::CREATE_STATUS_CREATED:
56 break;
57 case Profile::CREATE_STATUS_INITIALIZED:
58 if (profile_load_sequence_id == profile_load_sequence_id_)
59 callback.Run(profile);
60 DecrementPendingProfileLoads();
61 break;
62 case Profile::CREATE_STATUS_LOCAL_FAIL:
63 case Profile::CREATE_STATUS_REMOTE_FAIL:
64 case Profile::CREATE_STATUS_CANCELED:
65 DecrementPendingProfileLoads();
66 break;
67 case Profile::MAX_CREATE_STATUS:
68 NOTREACHED();
69 break;
70 }
71 }
72
73 void ProfileLoader::IncrementPendingProfileLoads() {
74 pending_profile_loads_++;
75 if (pending_profile_loads_ == 1)
76 chrome::StartKeepAlive();
77 }
78
79 void ProfileLoader::DecrementPendingProfileLoads() {
80 pending_profile_loads_--;
81 if (pending_profile_loads_ == 0)
82 chrome::EndKeepAlive();
83 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/profile_loader.h ('k') | chrome/browser/ui/views/app_list/app_list_controller_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698