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" | |
26 | 24 |
27 #include "generated_resources.h" | 25 #include "generated_resources.h" |
28 | 26 |
29 // static | 27 // static |
30 void ProfileManager::RegisterUserPrefs(PrefService* prefs) { | 28 void ProfileManager::RegisterUserPrefs(PrefService* prefs) { |
31 prefs->RegisterStringPref(prefs::kProfileName, L""); | 29 prefs->RegisterStringPref(prefs::kProfileName, L""); |
32 prefs->RegisterStringPref(prefs::kProfileNickname, L""); | 30 prefs->RegisterStringPref(prefs::kProfileNickname, L""); |
33 prefs->RegisterStringPref(prefs::kProfileID, L""); | 31 prefs->RegisterStringPref(prefs::kProfileID, L""); |
34 } | 32 } |
35 | 33 |
36 // static | 34 // static |
37 void ProfileManager::ShutdownSessionServices() { | 35 void ProfileManager::ShutdownSessionServices() { |
38 ProfileManager* pm = g_browser_process->profile_manager(); | 36 ProfileManager* pm = g_browser_process->profile_manager(); |
39 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) | 37 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) |
40 (*i)->ShutdownSessionService(); | 38 (*i)->ShutdownSessionService(); |
41 } | 39 } |
42 | 40 |
43 ProfileManager::ProfileManager() { | 41 ProfileManager::ProfileManager() { |
44 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | |
45 if (monitor) | |
46 monitor->AddObserver(this); | |
47 } | 42 } |
48 | 43 |
49 ProfileManager::~ProfileManager() { | 44 ProfileManager::~ProfileManager() { |
50 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | |
51 if (monitor) | |
52 monitor->RemoveObserver(this); | |
53 | |
54 // Destroy all profiles that we're keeping track of. | 45 // Destroy all profiles that we're keeping track of. |
55 for (ProfileVector::const_iterator iter = profiles_.begin(); | 46 for (ProfileVector::const_iterator iter = profiles_.begin(); |
56 iter != profiles_.end(); ++iter) { | 47 iter != profiles_.end(); ++iter) { |
57 delete *iter; | 48 delete *iter; |
58 } | 49 } |
59 profiles_.clear(); | 50 profiles_.clear(); |
60 | 51 |
61 // Get rid of available profile list | 52 // Get rid of available profile list |
62 for (AvailableProfileVector::const_iterator iter = | 53 for (AvailableProfileVector::const_iterator iter = |
63 available_profiles_.begin(); | 54 available_profiles_.begin(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { | 208 Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { |
218 for (ProfileVector::const_iterator iter = profiles_.begin(); | 209 for (ProfileVector::const_iterator iter = profiles_.begin(); |
219 iter != profiles_.end(); ++iter) { | 210 iter != profiles_.end(); ++iter) { |
220 if ((*iter)->GetID() == id) | 211 if ((*iter)->GetID() == id) |
221 return *iter; | 212 return *iter; |
222 } | 213 } |
223 | 214 |
224 return NULL; | 215 return NULL; |
225 } | 216 } |
226 | 217 |
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 | |
268 | 218 |
269 // static | 219 // static |
270 bool ProfileManager::IsProfile(const std::wstring& path) { | 220 bool ProfileManager::IsProfile(const std::wstring& path) { |
271 std::wstring prefs_path = GetDefaultProfilePath(path); | 221 std::wstring prefs_path = GetDefaultProfilePath(path); |
272 | 222 |
273 std::wstring history_path = path; | 223 std::wstring history_path = path; |
274 file_util::AppendToPath(&history_path, chrome::kHistoryFilename); | 224 file_util::AppendToPath(&history_path, chrome::kHistoryFilename); |
275 | 225 |
276 return file_util::PathExists(prefs_path) && | 226 return file_util::PathExists(prefs_path) && |
277 file_util::PathExists(history_path); | 227 file_util::PathExists(history_path); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 return profile; | 297 return profile; |
348 } | 298 } |
349 | 299 |
350 // static | 300 // static |
351 std::wstring ProfileManager::CanonicalizeID(const std::wstring& id) { | 301 std::wstring ProfileManager::CanonicalizeID(const std::wstring& id) { |
352 std::wstring no_whitespace; | 302 std::wstring no_whitespace; |
353 TrimWhitespace(id, TRIM_ALL, &no_whitespace); | 303 TrimWhitespace(id, TRIM_ALL, &no_whitespace); |
354 return StringToLowerASCII(no_whitespace); | 304 return StringToLowerASCII(no_whitespace); |
355 } | 305 } |
356 | 306 |
OLD | NEW |