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

Side by Side Diff: chrome/browser/profiles/profile_manager.h

Issue 8840003: Replace ProfileManagerObserver with callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: weakptr Created 9 years 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This class keeps track of the currently-active profiles in the runtime. 5 // This class keeps track of the currently-active profiles in the runtime.
6 6
7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ 7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_
8 #define CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ 8 #define CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_
9 #pragma once 9 #pragma once
10 10
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
27 27
28 #if defined(OS_WIN) 28 #if defined(OS_WIN)
29 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" 29 #include "chrome/browser/profiles/profile_shortcut_manager_win.h"
30 #endif 30 #endif
31 31
32 class NewProfileLauncher; 32 class NewProfileLauncher;
33 class ProfileInfoCache; 33 class ProfileInfoCache;
34 34
35 class ProfileManagerObserver {
36 public:
37 enum Status {
38 // Asynchronous Profile services were not created.
39 STATUS_FAIL,
40 // Profile created but before initializing extensions and promo resources.
41 STATUS_CREATED,
42 // Profile is created, extensions and promo resources are initialized.
43 STATUS_INITIALIZED
44 };
45
46 // This method is called when profile is ready. If profile already exists,
47 // method is called with pointer to that profile and STATUS_INITIALIZED.
48 // If profile creation has failed, method is called with |profile| equal to
49 // NULL and |status| equal to STATUS_FAIL. If profile has been created
50 // successfully, method is called twice: first with STATUS_CREATED status
51 // (before extensions are initialized) and eventually with STATUS_INITIALIZED.
52 virtual void OnProfileCreated(Profile* profile, Status status) = 0;
53
54 // If true, delete the observer after no more OnProfileCreated calls are
55 // expected. Default is false.
56 virtual bool DeleteAfter();
57
58 virtual ~ProfileManagerObserver() {}
59 };
60
61 class ProfileManager : public base::NonThreadSafe, 35 class ProfileManager : public base::NonThreadSafe,
62 public BrowserList::Observer, 36 public BrowserList::Observer,
63 public content::NotificationObserver, 37 public content::NotificationObserver,
64 public Profile::Delegate { 38 public Profile::Delegate {
65 public: 39 public:
40 typedef base::Callback<void(Profile*, Profile::CreateStatus)> CreateCallback;
41
66 explicit ProfileManager(const FilePath& user_data_dir); 42 explicit ProfileManager(const FilePath& user_data_dir);
67 virtual ~ProfileManager(); 43 virtual ~ProfileManager();
68 44
69 // Invokes SessionServiceFactory::ShutdownForProfile() for all profiles. 45 // Invokes SessionServiceFactory::ShutdownForProfile() for all profiles.
70 static void ShutdownSessionServices(); 46 static void ShutdownSessionServices();
71 47
72 // Physically remove deleted profile directories from disk. 48 // Physically remove deleted profile directories from disk.
73 static void NukeDeletedProfilesFromDisk(); 49 static void NukeDeletedProfilesFromDisk();
74 50
75 // DEPRECATED: DO NOT USE unless in ChromeOS. 51 // DEPRECATED: DO NOT USE unless in ChromeOS.
76 // Returns the default profile. This adds the profile to the 52 // Returns the default profile. This adds the profile to the
77 // ProfileManager if it doesn't already exist. This method returns NULL if 53 // ProfileManager if it doesn't already exist. This method returns NULL if
78 // the profile doesn't exist and we can't create it. 54 // the profile doesn't exist and we can't create it.
79 // The profile used can be overridden by using --login-profile on cros. 55 // The profile used can be overridden by using --login-profile on cros.
80 Profile* GetDefaultProfile(const FilePath& user_data_dir); 56 Profile* GetDefaultProfile(const FilePath& user_data_dir);
81 57
82 // DEPRECATED: DO NOT USE unless in ChromeOS. 58 // DEPRECATED: DO NOT USE unless in ChromeOS.
83 // Same as instance method but provides the default user_data_dir as well. 59 // Same as instance method but provides the default user_data_dir as well.
84 static Profile* GetDefaultProfile(); 60 static Profile* GetDefaultProfile();
85 61
86 // Returns a profile for a specific profile directory within the user data 62 // Returns a profile for a specific profile directory within the user data
87 // dir. This will return an existing profile it had already been created, 63 // dir. This will return an existing profile it had already been created,
88 // otherwise it will create and manage it. 64 // otherwise it will create and manage it.
89 Profile* GetProfile(const FilePath& profile_dir); 65 Profile* GetProfile(const FilePath& profile_dir);
90 66
91 // Returns total number of profiles available on this machine. 67 // Returns total number of profiles available on this machine.
92 size_t GetNumberOfProfiles(); 68 size_t GetNumberOfProfiles();
93 69
94 // Explicit asynchronous creation of the profile. |observer| is called 70 // Explicit asynchronous creation of a profile located at |profile_path|.
95 // when profile is created. If profile has already been created, observer 71 // If the profile has already been created then callback is called
96 // is called immediately. Should be called on the UI thread. 72 // immediately.
97 void CreateProfileAsync(const FilePath& user_data_dir, 73 void CreateProfileAsync(const FilePath& profile_path,
98 ProfileManagerObserver* observer); 74 CreateCallback callback);
Robert Sesek 2011/12/07 16:36:13 const ref
sail 2011/12/07 17:18:13 Done.
99 75
100 // Initiates default profile creation. If default profile has already been 76 // Initiates default profile creation. If default profile has already been
101 // created, observer is called immediately. Should be called on the UI thread. 77 // created then the callback is called immediately. Should be called on the
102 static void CreateDefaultProfileAsync(ProfileManagerObserver* observer); 78 // UI thread.
79 static void CreateDefaultProfileAsync(CreateCallback callback);
Robert Sesek 2011/12/07 16:36:13 const ref
sail 2011/12/07 17:18:13 Done.
103 80
104 // Returns true if the profile pointer is known to point to an existing 81 // Returns true if the profile pointer is known to point to an existing
105 // profile. 82 // profile.
106 bool IsValidProfile(Profile* profile); 83 bool IsValidProfile(Profile* profile);
107 84
108 // Returns the directory where the first created profile is stored, 85 // Returns the directory where the first created profile is stored,
109 // relative to the user data directory currently in use.. 86 // relative to the user data directory currently in use..
110 FilePath GetInitialProfileDir(); 87 FilePath GetInitialProfileDir();
111 88
112 // Get the Profile last used with this Chrome build. If no signed profile has 89 // Get the Profile last used with this Chrome build. If no signed profile has
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 struct ProfileInfo { 205 struct ProfileInfo {
229 ProfileInfo(Profile* profile, bool created) 206 ProfileInfo(Profile* profile, bool created)
230 : profile(profile), created(created) { 207 : profile(profile), created(created) {
231 } 208 }
232 209
233 ~ProfileInfo() {} 210 ~ProfileInfo() {}
234 211
235 scoped_ptr<Profile> profile; 212 scoped_ptr<Profile> profile;
236 // Whether profile has been fully loaded (created and initialized). 213 // Whether profile has been fully loaded (created and initialized).
237 bool created; 214 bool created;
238 // List of observers which should be notified when profile initialization is 215 // List of callbacks which should be notified when profile initialization is
239 // done. Note, when profile is fully loaded this vector will be empty. 216 // done. Note, when profile is fully loaded this vector will be empty.
240 std::vector<ProfileManagerObserver*> observers; 217 std::vector<CreateCallback> callbacks;
241 218
242 private: 219 private:
243 DISALLOW_COPY_AND_ASSIGN(ProfileInfo); 220 DISALLOW_COPY_AND_ASSIGN(ProfileInfo);
244 }; 221 };
245 222
246 // Adds a pre-existing Profile object to the set managed by this 223 // Adds a pre-existing Profile object to the set managed by this
247 // ProfileManager. This ProfileManager takes ownership of the Profile. 224 // ProfileManager. This ProfileManager takes ownership of the Profile.
248 // The Profile should not already be managed by this ProfileManager. 225 // The Profile should not already be managed by this ProfileManager.
249 // Returns true if the profile was added, false otherwise. 226 // Returns true if the profile was added, false otherwise.
250 bool AddProfile(Profile* profile); 227 bool AddProfile(Profile* profile);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 class ProfileManagerWithoutInit : public ProfileManager { 289 class ProfileManagerWithoutInit : public ProfileManager {
313 public: 290 public:
314 explicit ProfileManagerWithoutInit(const FilePath& user_data_dir); 291 explicit ProfileManagerWithoutInit(const FilePath& user_data_dir);
315 292
316 protected: 293 protected:
317 virtual void DoFinalInitForServices(Profile*, bool) OVERRIDE {} 294 virtual void DoFinalInitForServices(Profile*, bool) OVERRIDE {}
318 virtual void DoFinalInitLogging(Profile*) OVERRIDE {} 295 virtual void DoFinalInitLogging(Profile*) OVERRIDE {}
319 }; 296 };
320 297
321 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ 298 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698