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 #include <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "chrome/browser/profile_manager.h" | 9 #include "chrome/browser/profile_manager.h" |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/navigation_controller.h" | 17 #include "chrome/browser/navigation_controller.h" |
18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/l10n_util.h" | 20 #include "chrome/common/l10n_util.h" |
21 #include "chrome/common/logging_chrome.h" | 21 #include "chrome/common/logging_chrome.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
| 24 #include "net/url_request/url_request_job.h" |
| 25 #include "net/url_request/url_request_job_tracker.h" |
24 | 26 |
25 #include "generated_resources.h" | 27 #include "generated_resources.h" |
26 | 28 |
27 // static | 29 // static |
28 void ProfileManager::RegisterUserPrefs(PrefService* prefs) { | 30 void ProfileManager::RegisterUserPrefs(PrefService* prefs) { |
29 prefs->RegisterStringPref(prefs::kProfileName, L""); | 31 prefs->RegisterStringPref(prefs::kProfileName, L""); |
30 prefs->RegisterStringPref(prefs::kProfileNickname, L""); | 32 prefs->RegisterStringPref(prefs::kProfileNickname, L""); |
31 prefs->RegisterStringPref(prefs::kProfileID, L""); | 33 prefs->RegisterStringPref(prefs::kProfileID, L""); |
32 } | 34 } |
33 | 35 |
34 // static | 36 // static |
35 void ProfileManager::ShutdownSessionServices() { | 37 void ProfileManager::ShutdownSessionServices() { |
36 ProfileManager* pm = g_browser_process->profile_manager(); | 38 ProfileManager* pm = g_browser_process->profile_manager(); |
37 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) | 39 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) |
38 (*i)->ShutdownSessionService(); | 40 (*i)->ShutdownSessionService(); |
39 } | 41 } |
40 | 42 |
41 ProfileManager::ProfileManager() { | 43 ProfileManager::ProfileManager() { |
| 44 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
| 45 if (monitor) |
| 46 monitor->AddObserver(this); |
42 } | 47 } |
43 | 48 |
44 ProfileManager::~ProfileManager() { | 49 ProfileManager::~ProfileManager() { |
| 50 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
| 51 if (monitor) |
| 52 monitor->RemoveObserver(this); |
| 53 |
45 // Destroy all profiles that we're keeping track of. | 54 // Destroy all profiles that we're keeping track of. |
46 for (ProfileVector::const_iterator iter = profiles_.begin(); | 55 for (ProfileVector::const_iterator iter = profiles_.begin(); |
47 iter != profiles_.end(); ++iter) { | 56 iter != profiles_.end(); ++iter) { |
48 delete *iter; | 57 delete *iter; |
49 } | 58 } |
50 profiles_.clear(); | 59 profiles_.clear(); |
51 | 60 |
52 // Get rid of available profile list | 61 // Get rid of available profile list |
53 for (AvailableProfileVector::const_iterator iter = | 62 for (AvailableProfileVector::const_iterator iter = |
54 available_profiles_.begin(); | 63 available_profiles_.begin(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { | 217 Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { |
209 for (ProfileVector::const_iterator iter = profiles_.begin(); | 218 for (ProfileVector::const_iterator iter = profiles_.begin(); |
210 iter != profiles_.end(); ++iter) { | 219 iter != profiles_.end(); ++iter) { |
211 if ((*iter)->GetID() == id) | 220 if ((*iter)->GetID() == id) |
212 return *iter; | 221 return *iter; |
213 } | 222 } |
214 | 223 |
215 return NULL; | 224 return NULL; |
216 } | 225 } |
217 | 226 |
| 227 void ProfileManager::OnSuspend(base::SystemMonitor* monitor) { |
| 228 DCHECK(CalledOnValidThread()); |
| 229 |
| 230 ProfileManager::const_iterator it = begin(); |
| 231 while(it != end()) { |
| 232 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 233 NewRunnableFunction(&ProfileManager::SuspendProfile, *it)); |
| 234 it++; |
| 235 } |
| 236 } |
| 237 |
| 238 void ProfileManager::OnResume(base::SystemMonitor* monitor) { |
| 239 DCHECK(CalledOnValidThread()); |
| 240 ProfileManager::const_iterator it = begin(); |
| 241 while (it != end()) { |
| 242 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 243 NewRunnableFunction(&ProfileManager::ResumeProfile, *it)); |
| 244 it++; |
| 245 } |
| 246 } |
| 247 |
| 248 void ProfileManager::SuspendProfile(Profile* profile) { |
| 249 DCHECK(profile); |
| 250 DCHECK(MessageLoop::current() == |
| 251 ChromeThread::GetMessageLoop(ChromeThread::IO)); |
| 252 |
| 253 URLRequestJobTracker::JobIterator it = g_url_request_job_tracker.begin(); |
| 254 for (;it != g_url_request_job_tracker.end(); ++it) |
| 255 (*it)->Kill(); |
| 256 |
| 257 profile->GetRequestContext()->http_transaction_factory()->Suspend(true); |
| 258 } |
| 259 |
| 260 void ProfileManager::ResumeProfile(Profile* profile) { |
| 261 DCHECK(profile); |
| 262 DCHECK(MessageLoop::current() == |
| 263 ChromeThread::GetMessageLoop(ChromeThread::IO)); |
| 264 profile->GetRequestContext()->http_transaction_factory()->Suspend(false); |
| 265 } |
| 266 |
| 267 |
218 | 268 |
219 // static | 269 // static |
220 bool ProfileManager::IsProfile(const std::wstring& path) { | 270 bool ProfileManager::IsProfile(const std::wstring& path) { |
221 std::wstring prefs_path = GetDefaultProfilePath(path); | 271 std::wstring prefs_path = GetDefaultProfilePath(path); |
222 | 272 |
223 std::wstring history_path = path; | 273 std::wstring history_path = path; |
224 file_util::AppendToPath(&history_path, chrome::kHistoryFilename); | 274 file_util::AppendToPath(&history_path, chrome::kHistoryFilename); |
225 | 275 |
226 return file_util::PathExists(prefs_path) && | 276 return file_util::PathExists(prefs_path) && |
227 file_util::PathExists(history_path); | 277 file_util::PathExists(history_path); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 return profile; | 347 return profile; |
298 } | 348 } |
299 | 349 |
300 // static | 350 // static |
301 std::wstring ProfileManager::CanonicalizeID(const std::wstring& id) { | 351 std::wstring ProfileManager::CanonicalizeID(const std::wstring& id) { |
302 std::wstring no_whitespace; | 352 std::wstring no_whitespace; |
303 TrimWhitespace(id, TRIM_ALL, &no_whitespace); | 353 TrimWhitespace(id, TRIM_ALL, &no_whitespace); |
304 return StringToLowerASCII(no_whitespace); | 354 return StringToLowerASCII(no_whitespace); |
305 } | 355 } |
306 | 356 |
OLD | NEW |