OLD | NEW |
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 #include <set> | 5 #include <set> |
6 | 6 |
7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/common/logging_chrome.h" | 25 #include "chrome/common/logging_chrome.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.h" |
28 #include "content/common/notification_service.h" | 28 #include "content/common/notification_service.h" |
29 #include "content/common/notification_type.h" | 29 #include "content/common/notification_type.h" |
30 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
31 #include "net/http/http_transaction_factory.h" | 31 #include "net/http/http_transaction_factory.h" |
32 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
33 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
34 #include "net/url_request/url_request_job.h" | 34 #include "net/url_request/url_request_job.h" |
35 #include "net/url_request/url_request_job_tracker.h" | |
36 | 35 |
37 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
38 #include "chrome/browser/chromeos/cros/cros_library.h" | 37 #include "chrome/browser/chromeos/cros/cros_library.h" |
39 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 38 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
40 #endif | 39 #endif |
41 | 40 |
42 namespace { | |
43 | |
44 void SuspendURLRequestJobs() { | |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
46 for (net::URLRequestJobTracker::JobIterator i = | |
47 net::g_url_request_job_tracker.begin(); | |
48 i != net::g_url_request_job_tracker.end(); ++i) | |
49 (*i)->Kill(); | |
50 } | |
51 | |
52 void SuspendRequestContext( | |
53 net::URLRequestContextGetter* request_context_getter) { | |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
55 | |
56 scoped_refptr<net::URLRequestContext> request_context = | |
57 request_context_getter->GetURLRequestContext(); | |
58 | |
59 request_context->http_transaction_factory()->Suspend(true); | |
60 } | |
61 | |
62 void ResumeRequestContext( | |
63 net::URLRequestContextGetter* request_context_getter) { | |
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
65 | |
66 scoped_refptr<net::URLRequestContext> request_context = | |
67 request_context_getter->GetURLRequestContext(); | |
68 request_context->http_transaction_factory()->Suspend(false); | |
69 } | |
70 | |
71 } // namespace | |
72 | |
73 | |
74 bool ProfileManagerObserver::DeleteAfterCreation() { | 41 bool ProfileManagerObserver::DeleteAfterCreation() { |
75 return false; | 42 return false; |
76 } | 43 } |
77 | 44 |
78 // The NewProfileLauncher class is created when to wait for a multi-profile | 45 // The NewProfileLauncher class is created when to wait for a multi-profile |
79 // to be created asynchronously. Upon completion of profile creation, the | 46 // to be created asynchronously. Upon completion of profile creation, the |
80 // NPL takes care of launching a new browser window and signing the user | 47 // NPL takes care of launching a new browser window and signing the user |
81 // in to their Google account. | 48 // in to their Google account. |
82 class NewProfileLauncher : public ProfileManagerObserver { | 49 class NewProfileLauncher : public ProfileManagerObserver { |
83 public: | 50 public: |
(...skipping 20 matching lines...) Expand all Loading... |
104 | 71 |
105 // static | 72 // static |
106 Profile* ProfileManager::GetDefaultProfile() { | 73 Profile* ProfileManager::GetDefaultProfile() { |
107 FilePath user_data_dir; | 74 FilePath user_data_dir; |
108 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 75 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
109 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 76 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
110 return profile_manager->GetDefaultProfile(user_data_dir); | 77 return profile_manager->GetDefaultProfile(user_data_dir); |
111 } | 78 } |
112 | 79 |
113 ProfileManager::ProfileManager() : logged_in_(false) { | 80 ProfileManager::ProfileManager() : logged_in_(false) { |
114 base::SystemMonitor::Get()->AddObserver(this); | |
115 BrowserList::AddObserver(this); | 81 BrowserList::AddObserver(this); |
116 #if defined(OS_CHROMEOS) | 82 #if defined(OS_CHROMEOS) |
117 registrar_.Add( | 83 registrar_.Add( |
118 this, | 84 this, |
119 NotificationType::LOGIN_USER_CHANGED, | 85 NotificationType::LOGIN_USER_CHANGED, |
120 NotificationService::AllSources()); | 86 NotificationService::AllSources()); |
121 #endif | 87 #endif |
122 } | 88 } |
123 | 89 |
124 ProfileManager::~ProfileManager() { | 90 ProfileManager::~ProfileManager() { |
125 base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); | |
126 if (system_monitor) | |
127 system_monitor->RemoveObserver(this); | |
128 BrowserList::RemoveObserver(this); | 91 BrowserList::RemoveObserver(this); |
129 } | 92 } |
130 | 93 |
131 FilePath ProfileManager::GetDefaultProfileDir( | 94 FilePath ProfileManager::GetDefaultProfileDir( |
132 const FilePath& user_data_dir) { | 95 const FilePath& user_data_dir) { |
133 FilePath default_profile_dir(user_data_dir); | 96 FilePath default_profile_dir(user_data_dir); |
134 default_profile_dir = | 97 default_profile_dir = |
135 default_profile_dir.AppendASCII(chrome::kNotSignedInProfile); | 98 default_profile_dir.AppendASCII(chrome::kNotSignedInProfile); |
136 return default_profile_dir; | 99 return default_profile_dir; |
137 } | 100 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 ProfilesInfoMap::iterator new_elem = | 303 ProfilesInfoMap::iterator new_elem = |
341 (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first; | 304 (profiles_info_.insert(std::make_pair(profile->GetPath(), info))).first; |
342 return info; | 305 return info; |
343 } | 306 } |
344 | 307 |
345 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { | 308 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { |
346 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 309 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
347 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); | 310 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); |
348 } | 311 } |
349 | 312 |
350 void ProfileManager::OnSuspend() { | |
351 DCHECK(CalledOnValidThread()); | |
352 | |
353 bool posted = BrowserThread::PostTask( | |
354 BrowserThread::IO, FROM_HERE, | |
355 NewRunnableFunction(&SuspendURLRequestJobs)); | |
356 DCHECK(posted); | |
357 | |
358 scoped_refptr<net::URLRequestContextGetter> request_context; | |
359 std::vector<Profile*> profiles(GetLoadedProfiles()); | |
360 for (size_t i = 0; i < profiles.size(); ++i) { | |
361 request_context = profiles[i]->GetRequestContext(); | |
362 posted = BrowserThread::PostTask( | |
363 BrowserThread::IO, FROM_HERE, | |
364 NewRunnableFunction(&SuspendRequestContext, request_context)); | |
365 DCHECK(posted); | |
366 request_context = profiles[i]->GetRequestContextForMedia(); | |
367 posted = BrowserThread::PostTask( | |
368 BrowserThread::IO, FROM_HERE, | |
369 NewRunnableFunction(&SuspendRequestContext, request_context)); | |
370 DCHECK(posted); | |
371 } | |
372 } | |
373 | |
374 void ProfileManager::OnResume() { | |
375 DCHECK(CalledOnValidThread()); | |
376 | |
377 scoped_refptr<net::URLRequestContextGetter> request_context; | |
378 std::vector<Profile*> profiles(GetLoadedProfiles()); | |
379 for (size_t i = 0; i < profiles.size(); ++i) { | |
380 request_context = profiles[i]->GetRequestContext(); | |
381 bool posted = BrowserThread::PostTask( | |
382 BrowserThread::IO, FROM_HERE, | |
383 NewRunnableFunction(&ResumeRequestContext, request_context)); | |
384 DCHECK(posted); | |
385 request_context = profiles[i]->GetRequestContextForMedia(); | |
386 posted = BrowserThread::PostTask( | |
387 BrowserThread::IO, FROM_HERE, | |
388 NewRunnableFunction(&ResumeRequestContext, request_context)); | |
389 DCHECK(posted); | |
390 } | |
391 } | |
392 | |
393 void ProfileManager::Observe( | 313 void ProfileManager::Observe( |
394 NotificationType type, | 314 NotificationType type, |
395 const NotificationSource& source, | 315 const NotificationSource& source, |
396 const NotificationDetails& details) { | 316 const NotificationDetails& details) { |
397 #if defined(OS_CHROMEOS) | 317 #if defined(OS_CHROMEOS) |
398 if (type == NotificationType::LOGIN_USER_CHANGED) { | 318 if (type == NotificationType::LOGIN_USER_CHANGED) { |
399 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 319 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
400 if (!command_line.HasSwitch(switches::kTestType)) { | 320 if (!command_line.HasSwitch(switches::kTestType)) { |
401 // This will fail when running on non cros os. | 321 // This will fail when running on non cros os. |
402 // TODO(davemoore) Need to mock this enough to enable testing. | 322 // TODO(davemoore) Need to mock this enough to enable testing. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 NewProfileLauncher* launcher = new NewProfileLauncher(); | 422 NewProfileLauncher* launcher = new NewProfileLauncher(); |
503 profile_manager->CreateProfileAsync(new_path, launcher); | 423 profile_manager->CreateProfileAsync(new_path, launcher); |
504 } | 424 } |
505 | 425 |
506 // static | 426 // static |
507 void ProfileManager::RegisterPrefs(PrefService* prefs) { | 427 void ProfileManager::RegisterPrefs(PrefService* prefs) { |
508 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); | 428 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); |
509 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); | 429 prefs->RegisterDictionaryPref(prefs::kProfileDirectoryMap); |
510 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 430 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
511 } | 431 } |
OLD | NEW |