| OLD | NEW |
| 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/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/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_ptr.h" |
| 11 #include "base/singleton.h" |
| 10 #include "chrome/browser/browser_init.h" | 12 #include "chrome/browser/browser_init.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/cros/login_library.h" | 14 #include "chrome/browser/chromeos/cros/login_library.h" |
| 13 #include "chrome/browser/chromeos/external_cookie_handler.h" | 15 #include "chrome/browser/chromeos/external_cookie_handler.h" |
| 14 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 16 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| 15 #include "chrome/browser/chromeos/login/google_authenticator.h" | 17 #include "chrome/browser/chromeos/login/google_authenticator.h" |
| 16 #include "chrome/browser/chromeos/login/pam_google_authenticator.h" | 18 #include "chrome/browser/chromeos/login/pam_google_authenticator.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/net/url_request_context_getter.h" | 20 #include "chrome/browser/net/url_request_context_getter.h" |
| 19 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/profile_manager.h" | 22 #include "chrome/browser/profile_manager.h" |
| 21 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 24 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 25 #include "net/base/cookie_store.h" | 27 #include "net/base/cookie_store.h" |
| 26 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 27 #include "views/widget/widget_gtk.h" | 29 #include "views/widget/widget_gtk.h" |
| 28 | 30 |
| 29 namespace chromeos { | 31 namespace chromeos { |
| 30 | 32 |
| 31 namespace login_utils { | 33 class LoginUtilsImpl : public LoginUtils { |
| 34 public: |
| 35 LoginUtilsImpl() {} |
| 32 | 36 |
| 33 void CompleteLogin(const std::string& username, | 37 // Invoked after the user has successfully logged in. This launches a browser |
| 34 std::vector<std::string> cookies) { | 38 // and does other bookkeeping after logging in. |
| 39 virtual void CompleteLogin(const std::string& username, |
| 40 std::vector<std::string> cookies); |
| 41 |
| 42 // Creates and returns the authenticator to use. The caller owns the returned |
| 43 // Authenticator and must delete it when done. |
| 44 virtual Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer); |
| 45 |
| 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
| 48 }; |
| 49 |
| 50 class LoginUtilsWraper { |
| 51 public: |
| 52 LoginUtilsWraper() : ptr_(new LoginUtilsImpl) { |
| 53 } |
| 54 |
| 55 LoginUtils* get() { |
| 56 return ptr_.get(); |
| 57 } |
| 58 |
| 59 void reset(LoginUtils* ptr) { |
| 60 ptr_.reset(ptr); |
| 61 } |
| 62 |
| 63 private: |
| 64 scoped_ptr<LoginUtils> ptr_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWraper); |
| 67 }; |
| 68 |
| 69 void LoginUtilsImpl::CompleteLogin(const std::string& username, |
| 70 std::vector<std::string> cookies) { |
| 35 LOG(INFO) << "LoginManagerView: OnLoginSuccess()"; | 71 LOG(INFO) << "LoginManagerView: OnLoginSuccess()"; |
| 36 | 72 |
| 37 if (CrosLibrary::Get()->EnsureLoaded()) | 73 if (CrosLibrary::Get()->EnsureLoaded()) |
| 38 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, ""); | 74 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, ""); |
| 39 | 75 |
| 40 UserManager::Get()->UserLoggedIn(username); | 76 UserManager::Get()->UserLoggedIn(username); |
| 41 | 77 |
| 42 // Send notification of success | 78 // Send notification of success |
| 43 AuthenticationNotificationDetails details(true); | 79 AuthenticationNotificationDetails details(true); |
| 44 NotificationService::current()->Notify( | 80 NotificationService::current()->Notify( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 GURL url(ExternalCookieHandler::kGoogleAccountsUrl); | 99 GURL url(ExternalCookieHandler::kGoogleAccountsUrl); |
| 64 net::CookieOptions options; | 100 net::CookieOptions options; |
| 65 options.set_include_httponly(); | 101 options.set_include_httponly(); |
| 66 profile->GetRequestContext()->GetCookieStore()->SetCookiesWithOptions( | 102 profile->GetRequestContext()->GetCookieStore()->SetCookiesWithOptions( |
| 67 url, cookies, options); | 103 url, cookies, options); |
| 68 } | 104 } |
| 69 browser_init.LaunchBrowser(command_line, profile, std::wstring(), true, | 105 browser_init.LaunchBrowser(command_line, profile, std::wstring(), true, |
| 70 &return_code); | 106 &return_code); |
| 71 } | 107 } |
| 72 | 108 |
| 73 Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer) { | 109 Authenticator* LoginUtilsImpl::CreateAuthenticator( |
| 110 LoginStatusConsumer* consumer) { |
| 74 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInChromeAuth)) | 111 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInChromeAuth)) |
| 75 return new GoogleAuthenticator(consumer); | 112 return new GoogleAuthenticator(consumer); |
| 76 return new PamGoogleAuthenticator(consumer); | 113 return new PamGoogleAuthenticator(consumer); |
| 77 } | 114 } |
| 78 | 115 |
| 79 } // namespace login_utils | 116 LoginUtils* LoginUtils::Get() { |
| 117 return Singleton<LoginUtilsWraper>::get()->get(); |
| 118 } |
| 119 |
| 120 void LoginUtils::Set(LoginUtils* mock) { |
| 121 Singleton<LoginUtilsWraper>::get()->reset(mock); |
| 122 } |
| 80 | 123 |
| 81 } // namespace chromeos | 124 } // namespace chromeos |
| OLD | NEW |