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

Side by Side Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 1730001: Enable Chrome OS to load the user's nssdb later. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months 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
« no previous file with comments | « base/nss_util_internal.h ('k') | net/base/keygen_handler_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/lock.h"
10 #include "base/nss_util.h"
9 #include "base/path_service.h" 11 #include "base/path_service.h"
10 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
11 #include "base/singleton.h" 13 #include "base/singleton.h"
12 #include "chrome/browser/browser_init.h" 14 #include "chrome/browser/browser_init.h"
13 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/cros/login_library.h" 16 #include "chrome/browser/chromeos/cros/login_library.h"
15 #include "chrome/browser/chromeos/external_cookie_handler.h" 17 #include "chrome/browser/chromeos/external_cookie_handler.h"
16 #include "chrome/browser/chromeos/login/cookie_fetcher.h" 18 #include "chrome/browser/chromeos/login/cookie_fetcher.h"
17 #include "chrome/browser/chromeos/login/google_authenticator.h" 19 #include "chrome/browser/chromeos/login/google_authenticator.h"
18 #include "chrome/browser/chromeos/login/pam_google_authenticator.h" 20 #include "chrome/browser/chromeos/login/pam_google_authenticator.h"
19 #include "chrome/browser/chromeos/login/user_manager.h" 21 #include "chrome/browser/chromeos/login/user_manager.h"
20 #include "chrome/browser/net/url_request_context_getter.h" 22 #include "chrome/browser/net/url_request_context_getter.h"
21 #include "chrome/browser/profile.h" 23 #include "chrome/browser/profile.h"
22 #include "chrome/browser/profile_manager.h" 24 #include "chrome/browser/profile_manager.h"
23 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/notification_observer.h"
28 #include "chrome/common/notification_registrar.h"
29 #include "chrome/common/notification_service.h"
30 #include "chrome/common/notification_type.h"
25 #include "googleurl/src/gurl.h" 31 #include "googleurl/src/gurl.h"
26 #include "net/base/cookie_store.h" 32 #include "net/base/cookie_store.h"
27 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
28 #include "views/widget/widget_gtk.h" 34 #include "views/widget/widget_gtk.h"
29 35
30 namespace chromeos { 36 namespace chromeos {
31 37
32 class LoginUtilsImpl : public LoginUtils { 38 class LoginUtilsImpl : public LoginUtils,
39 public NotificationObserver {
33 public: 40 public:
34 LoginUtilsImpl() {} 41 LoginUtilsImpl() {
42 registrar_.Add(
43 this,
44 NotificationType::LOGIN_USER_CHANGED,
45 NotificationService::AllSources());
46 }
35 47
36 // Invoked after the user has successfully logged in. This launches a browser 48 // Invoked after the user has successfully logged in. This launches a browser
37 // and does other bookkeeping after logging in. 49 // and does other bookkeeping after logging in.
38 virtual void CompleteLogin(const std::string& username, 50 virtual void CompleteLogin(const std::string& username,
39 const std::string& credentials); 51 const std::string& credentials);
40 52
41 // Creates and returns the authenticator to use. The caller owns the returned 53 // Creates and returns the authenticator to use. The caller owns the returned
42 // Authenticator and must delete it when done. 54 // Authenticator and must delete it when done.
43 virtual Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer); 55 virtual Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer);
44 56
57 // NotificationObserver implementation.
58 virtual void Observe(NotificationType type,
59 const NotificationSource& source,
60 const NotificationDetails& details);
61
45 private: 62 private:
63 NotificationRegistrar registrar_;
64
46 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); 65 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl);
47 }; 66 };
48 67
49 class LoginUtilsWrapper { 68 class LoginUtilsWrapper {
50 public: 69 public:
51 LoginUtilsWrapper() : ptr_(new LoginUtilsImpl) { 70 LoginUtilsWrapper() {}
52 }
53 71
54 LoginUtils* get() { 72 LoginUtils* get() {
73 AutoLock create(create_lock_);
74 if (!ptr_.get())
75 reset(new LoginUtilsImpl);
55 return ptr_.get(); 76 return ptr_.get();
56 } 77 }
57 78
58 void reset(LoginUtils* ptr) { 79 void reset(LoginUtils* ptr) {
59 ptr_.reset(ptr); 80 ptr_.reset(ptr);
60 } 81 }
61 82
62 private: 83 private:
84 Lock create_lock_;
63 scoped_ptr<LoginUtils> ptr_; 85 scoped_ptr<LoginUtils> ptr_;
64 86
65 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); 87 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper);
66 }; 88 };
67 89
68 void LoginUtilsImpl::CompleteLogin(const std::string& username, 90 void LoginUtilsImpl::CompleteLogin(const std::string& username,
69 const std::string& credentials) { 91 const std::string& credentials) {
70 LOG(INFO) << "Completing login for " << username; 92 LOG(INFO) << "Completing login for " << username;
71 93
72 if (CrosLibrary::Get()->EnsureLoaded()) 94 if (CrosLibrary::Get()->EnsureLoaded())
(...skipping 25 matching lines...) Expand all
98 } 120 }
99 } 121 }
100 122
101 Authenticator* LoginUtilsImpl::CreateAuthenticator( 123 Authenticator* LoginUtilsImpl::CreateAuthenticator(
102 LoginStatusConsumer* consumer) { 124 LoginStatusConsumer* consumer) {
103 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInChromeAuth)) 125 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInChromeAuth))
104 return new GoogleAuthenticator(consumer); 126 return new GoogleAuthenticator(consumer);
105 return new PamGoogleAuthenticator(consumer); 127 return new PamGoogleAuthenticator(consumer);
106 } 128 }
107 129
130 void LoginUtilsImpl::Observe(NotificationType type,
131 const NotificationSource& source,
132 const NotificationDetails& details) {
133 if (type == NotificationType::LOGIN_USER_CHANGED)
134 base::OpenPersistentNSSDB();
135 }
136
108 LoginUtils* LoginUtils::Get() { 137 LoginUtils* LoginUtils::Get() {
109 return Singleton<LoginUtilsWrapper>::get()->get(); 138 return Singleton<LoginUtilsWrapper>::get()->get();
110 } 139 }
111 140
112 void LoginUtils::Set(LoginUtils* mock) { 141 void LoginUtils::Set(LoginUtils* mock) {
113 Singleton<LoginUtilsWrapper>::get()->reset(mock); 142 Singleton<LoginUtilsWrapper>::get()->reset(mock);
114 } 143 }
115 144
116 void LoginUtils::DoBrowserLaunch(Profile* profile) { 145 void LoginUtils::DoBrowserLaunch(Profile* profile) {
117 std::vector<UserManager::User> users = UserManager::Get()->GetUsers(); 146 std::vector<UserManager::User> users = UserManager::Get()->GetUsers();
118 if (!users.empty()) 147 if (!users.empty())
119 UserManager::Get()->DownloadUserImage(users[0].email()); 148 UserManager::Get()->DownloadUserImage(users[0].email());
120 LOG(INFO) << "Launching browser..."; 149 LOG(INFO) << "Launching browser...";
121 BrowserInit browser_init; 150 BrowserInit browser_init;
122 int return_code; 151 int return_code;
123 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), 152 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(),
124 profile, 153 profile,
125 std::wstring(), 154 std::wstring(),
126 true, 155 true,
127 &return_code); 156 &return_code);
128 } 157 }
129 158
130 } // namespace chromeos 159 } // namespace chromeos
OLDNEW
« no previous file with comments | « base/nss_util_internal.h ('k') | net/base/keygen_handler_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698