OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_PROFILE_MANAGER_H__ | 7 #ifndef CHROME_BROWSER_PROFILE_MANAGER_H__ |
8 #define CHROME_BROWSER_PROFILE_MANAGER_H__ | 8 #define CHROME_BROWSER_PROFILE_MANAGER_H__ |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/message_loop.h" |
| 16 #include "base/non_thread_safe.h" |
| 17 #include "base/system_monitor.h" |
15 #include "base/values.h" | 18 #include "base/values.h" |
16 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
17 | 20 |
18 // This is a small storage class that simply represents some metadata about | 21 // This is a small storage class that simply represents some metadata about |
19 // profiles that are available in the current user data directory. | 22 // profiles that are available in the current user data directory. |
20 // These are cached in local state so profiles don't need to be scanned | 23 // These are cached in local state so profiles don't need to be scanned |
21 // for their metadata on every launch. | 24 // for their metadata on every launch. |
22 class AvailableProfile { | 25 class AvailableProfile { |
23 public: | 26 public: |
24 AvailableProfile(const std::wstring& name, | 27 AvailableProfile(const std::wstring& name, |
(...skipping 25 matching lines...) Expand all Loading... |
50 std::wstring directory() const { return directory_; } | 53 std::wstring directory() const { return directory_; } |
51 | 54 |
52 private: | 55 private: |
53 std::wstring name_; // User-visible profile name | 56 std::wstring name_; // User-visible profile name |
54 std::wstring id_; // Profile identifier | 57 std::wstring id_; // Profile identifier |
55 std::wstring directory_; // Subdirectory containing profile (not full path) | 58 std::wstring directory_; // Subdirectory containing profile (not full path) |
56 | 59 |
57 DISALLOW_EVIL_CONSTRUCTORS(AvailableProfile); | 60 DISALLOW_EVIL_CONSTRUCTORS(AvailableProfile); |
58 }; | 61 }; |
59 | 62 |
60 class ProfileManager { | 63 class ProfileManager : public NonThreadSafe, |
| 64 public base::SystemMonitor::PowerObserver { |
61 public: | 65 public: |
62 ProfileManager(); | 66 ProfileManager(); |
63 virtual ~ProfileManager(); | 67 virtual ~ProfileManager(); |
64 | 68 |
65 // ProfileManager prefs are loaded as soon as the profile is created. | 69 // ProfileManager prefs are loaded as soon as the profile is created. |
66 static void RegisterUserPrefs(PrefService* prefs); | 70 static void RegisterUserPrefs(PrefService* prefs); |
67 | 71 |
68 // Invokes ShutdownSessionService() on all profiles. | 72 // Invokes ShutdownSessionService() on all profiles. |
69 static void ShutdownSessionServices(); | 73 static void ShutdownSessionServices(); |
70 | 74 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 const_iterator end() { return profiles_.end(); } | 119 const_iterator end() { return profiles_.end(); } |
116 | 120 |
117 typedef std::vector<AvailableProfile*> AvailableProfileVector; | 121 typedef std::vector<AvailableProfile*> AvailableProfileVector; |
118 const AvailableProfileVector& available_profiles() const { | 122 const AvailableProfileVector& available_profiles() const { |
119 return available_profiles_; | 123 return available_profiles_; |
120 } | 124 } |
121 | 125 |
122 // Creates a new window with the given profile. | 126 // Creates a new window with the given profile. |
123 void NewWindowWithProfile(Profile* profile); | 127 void NewWindowWithProfile(Profile* profile); |
124 | 128 |
| 129 // PowerObserver notifications |
| 130 void OnPowerStateChange(base::SystemMonitor*) {} |
| 131 void OnSuspend(base::SystemMonitor*); |
| 132 void OnResume(base::SystemMonitor*); |
| 133 |
125 // ------------------ static utility functions ------------------- | 134 // ------------------ static utility functions ------------------- |
126 | 135 |
127 // Returns the path to the profile directory based on the user data directory. | 136 // Returns the path to the profile directory based on the user data directory. |
128 static std::wstring GetDefaultProfileDir(const std::wstring& user_data_dir); | 137 static std::wstring GetDefaultProfileDir(const std::wstring& user_data_dir); |
129 | 138 |
130 // Returns the path to the profile given the user profile directory. | 139 // Returns the path to the profile given the user profile directory. |
131 static std::wstring GetDefaultProfilePath(const std::wstring& profile_dir); | 140 static std::wstring GetDefaultProfilePath(const std::wstring& profile_dir); |
132 | 141 |
133 // Tries to determine whether the given path represents a profile | 142 // Tries to determine whether the given path represents a profile |
134 // directory, and returns true if it thinks it does. | 143 // directory, and returns true if it thinks it does. |
(...skipping 15 matching lines...) Expand all Loading... |
150 const std::wstring& id); | 159 const std::wstring& id); |
151 | 160 |
152 // Returns the canonical form of the given ID string. | 161 // Returns the canonical form of the given ID string. |
153 static std::wstring CanonicalizeID(const std::wstring& id); | 162 static std::wstring CanonicalizeID(const std::wstring& id); |
154 | 163 |
155 private: | 164 private: |
156 // Returns the AvailableProfile entry associated with the given ID, | 165 // Returns the AvailableProfile entry associated with the given ID, |
157 // or NULL if no match is found. | 166 // or NULL if no match is found. |
158 AvailableProfile* GetAvailableProfileByID(const std::wstring& id); | 167 AvailableProfile* GetAvailableProfileByID(const std::wstring& id); |
159 | 168 |
| 169 // Hooks to suspend/resume per-profile network traffic. |
| 170 // These must be called on the IO thread. |
| 171 static void SuspendProfile(Profile*); |
| 172 static void ResumeProfile(Profile*); |
| 173 |
160 // We keep a simple vector of profiles rather than something fancier | 174 // We keep a simple vector of profiles rather than something fancier |
161 // because we expect there to be a small number of profiles active. | 175 // because we expect there to be a small number of profiles active. |
162 ProfileVector profiles_; | 176 ProfileVector profiles_; |
163 | 177 |
164 AvailableProfileVector available_profiles_; | 178 AvailableProfileVector available_profiles_; |
165 | 179 |
166 DISALLOW_EVIL_CONSTRUCTORS(ProfileManager); | 180 DISALLOW_EVIL_CONSTRUCTORS(ProfileManager); |
167 }; | 181 }; |
168 | 182 |
169 #endif // CHROME_BROWSER_PROFILE_MANAGER_H__ | 183 #endif // CHROME_BROWSER_PROFILE_MANAGER_H__ |
170 | 184 |
OLD | NEW |