Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profile_auth_data.h" | 5 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "net/base/server_bound_cert_service.h" | 9 #include "net/base/server_bound_cert_service.h" |
| 10 #include "net/base/server_bound_cert_store.h" | 10 #include "net/base/server_bound_cert_store.h" |
| 11 #include "net/cookies/cookie_monster.h" | 11 #include "net/cookies/cookie_monster.h" |
| 12 #include "net/cookies/cookie_store.h" | 12 #include "net/cookies/cookie_store.h" |
| 13 #include "net/http/http_auth_cache.h" | 13 #include "net/http/http_auth_cache.h" |
| 14 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
| 15 #include "net/http/http_transaction_factory.h" | 15 #include "net/http/http_transaction_factory.h" |
| 16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 namespace chromeos { | 21 namespace chromeos { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kGaiaSidCookie[] = "SID"; | |
| 26 const char kGaiaLsidCookie[] = "LSID"; | |
| 27 const char kGoogleDomain[] = ".google.com"; | |
| 28 const char kGoogleAccountsDomain[] = "accounts.google.com"; | |
|
xiyuan
2012/12/20 01:57:45
Those 4 consts are not used. Remove them?
| |
| 29 | |
| 30 // Callback for transferring |cookies_to_transfer| into |cookie_monster| if | |
| 31 // its jar is completely empty. | |
| 32 void OnTransferCookiesIfEmptyJar( | |
| 33 net::CookieMonster* cookie_monster, | |
| 34 const net::CookieList& cookies_to_transfer, | |
| 35 const base::Callback<void()>& cookies_transfered_callback, | |
| 36 const net::CookieList& cookies_in_jar) { | |
| 37 std::string sid; | |
| 38 std::string lsid; | |
| 39 // Transfer only if the existing cookie jar is empty. | |
| 40 if (!cookies_in_jar.size()) | |
| 41 cookie_monster->InitializeFrom(cookies_to_transfer); | |
| 42 | |
| 43 BrowserThread::PostTask( | |
| 44 BrowserThread::UI, FROM_HERE, cookies_transfered_callback); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 // Callback for receiving |cookies_to_transfer| from the authentication profile | |
| 49 // cookie jar. | |
| 50 void OnGetCookiesToTransfer( | |
| 51 net::CookieMonster* cookie_monster, | |
| 52 const base::Callback<void()>& cookies_transfered_callback, | |
| 53 const net::CookieList& cookies_to_transfer) { | |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 55 | |
| 56 // Nothing to transfer over? | |
| 57 if (!cookies_to_transfer.size()) { | |
| 58 BrowserThread::PostTask( | |
| 59 BrowserThread::UI, FROM_HERE, cookies_transfered_callback); | |
| 60 return; | |
| 61 } | |
| 62 // Now let's see if the target cookie monster's jar is even empty. | |
| 63 cookie_monster->GetAllCookiesAsync( | |
| 64 base::Bind(&OnTransferCookiesIfEmptyJar, | |
| 65 make_scoped_refptr(cookie_monster), | |
| 66 cookies_to_transfer, | |
| 67 cookies_transfered_callback)); | |
| 68 } | |
| 69 | |
| 25 // Transfers initial set of Profile cookies from the |from_context| to cookie | 70 // Transfers initial set of Profile cookies from the |from_context| to cookie |
| 26 // jar of |to_context|. | 71 // jar of |to_context|. |
| 27 void TransferDefaultCookiesOnIOThread( | 72 void TransferDefaultCookiesOnIOThread( |
| 28 net::URLRequestContextGetter* from_context, | 73 net::URLRequestContextGetter* from_context, |
| 29 net::URLRequestContextGetter* to_context) { | 74 net::URLRequestContextGetter* to_context, |
| 75 const base::Callback<void()>& | |
| 76 cookies_transfered_callback) { | |
|
xiyuan
2012/12/20 01:57:45
nit: Could this fit on previous line?
zel
2012/12/20 16:56:19
Done.
| |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 31 net::CookieStore* new_store = | 78 net::CookieStore* to_store = |
| 32 to_context->GetURLRequestContext()->cookie_store(); | 79 to_context->GetURLRequestContext()->cookie_store(); |
| 33 net::CookieMonster* new_monster = new_store->GetCookieMonster(); | 80 net::CookieMonster* to_monster = to_store->GetCookieMonster(); |
| 34 | 81 |
| 35 net::CookieStore* default_store = | 82 net::CookieStore* from_store = |
| 36 from_context->GetURLRequestContext()->cookie_store(); | 83 from_context->GetURLRequestContext()->cookie_store(); |
| 37 net::CookieMonster* default_monster = default_store->GetCookieMonster(); | 84 net::CookieMonster* from_monster = from_store->GetCookieMonster(); |
| 38 default_monster->SetKeepExpiredCookies(); | 85 from_monster->SetKeepExpiredCookies(); |
| 39 default_monster->GetAllCookiesAsync( | 86 from_monster->GetAllCookiesAsync(base::Bind(&OnGetCookiesToTransfer, |
| 40 base::Bind(base::IgnoreResult(&net::CookieMonster::InitializeFrom), | 87 make_scoped_refptr(to_monster), |
| 41 new_monster)); | 88 cookies_transfered_callback)); |
| 42 } | 89 } |
| 43 | 90 |
| 44 // Transfers default server bound certs of |from_context| to server bound certs | 91 // Transfers default server bound certs of |from_context| to server bound certs |
| 45 // storage of |to_context|. | 92 // storage of |to_context|. |
| 46 void TransferDefaultServerBoundCertsIOThread( | 93 void TransferDefaultServerBoundCertsIOThread( |
| 47 net::URLRequestContextGetter* from_context, | 94 net::URLRequestContextGetter* from_context, |
| 48 net::URLRequestContextGetter* to_context) { | 95 net::URLRequestContextGetter* to_context) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 50 net::ServerBoundCertService* default_service = | 97 net::ServerBoundCertService* default_service = |
| 51 from_context->GetURLRequestContext()->server_bound_cert_service(); | 98 from_context->GetURLRequestContext()->server_bound_cert_service(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 69 new_cache->UpdateAllFrom(*from_context->GetURLRequestContext()-> | 116 new_cache->UpdateAllFrom(*from_context->GetURLRequestContext()-> |
| 70 http_transaction_factory()->GetSession()->http_auth_cache()); | 117 http_transaction_factory()->GetSession()->http_auth_cache()); |
| 71 } | 118 } |
| 72 | 119 |
| 73 // Transfers cookies and server bound certs from the |from_profile| into | 120 // Transfers cookies and server bound certs from the |from_profile| into |
| 74 // the |to_profile|. If authentication was performed by an extension, then | 121 // the |to_profile|. If authentication was performed by an extension, then |
| 75 // the set of cookies that was acquired through such that process will be | 122 // the set of cookies that was acquired through such that process will be |
| 76 // automatically transfered into the profile. | 123 // automatically transfered into the profile. |
| 77 void TransferDefaultCookiesAndServerBoundCerts( | 124 void TransferDefaultCookiesAndServerBoundCerts( |
| 78 Profile* from_profile, | 125 Profile* from_profile, |
| 79 Profile* to_profile) { | 126 Profile* to_profile, |
| 127 const base::Callback<void()>& | |
| 128 cookies_transfered_callback) { | |
|
xiyuan
2012/12/20 01:57:45
nit: Could this fit on previous line?
zel
2012/12/20 16:56:19
Done.
| |
| 80 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
| 81 BrowserThread::IO, FROM_HERE, | 130 BrowserThread::IO, FROM_HERE, |
| 82 base::Bind(&TransferDefaultCookiesOnIOThread, | 131 base::Bind(&TransferDefaultCookiesOnIOThread, |
| 83 make_scoped_refptr(from_profile->GetRequestContext()), | 132 make_scoped_refptr(from_profile->GetRequestContext()), |
| 84 make_scoped_refptr(to_profile->GetRequestContext()))); | 133 make_scoped_refptr(to_profile->GetRequestContext()), |
| 134 cookies_transfered_callback)); | |
| 85 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 86 BrowserThread::IO, FROM_HERE, | 136 BrowserThread::IO, FROM_HERE, |
| 87 base::Bind(&TransferDefaultServerBoundCertsIOThread, | 137 base::Bind(&TransferDefaultServerBoundCertsIOThread, |
| 88 make_scoped_refptr(from_profile->GetRequestContext()), | 138 make_scoped_refptr(from_profile->GetRequestContext()), |
| 89 make_scoped_refptr(to_profile->GetRequestContext()))); | 139 make_scoped_refptr(to_profile->GetRequestContext()))); |
| 90 } | 140 } |
| 91 | 141 |
| 92 // Transfers HTTP authentication cache from the |from_profile| | 142 // Transfers HTTP authentication cache from the |from_profile| |
| 93 // into the |to_profile|. If user was required to authenticate with a proxy | 143 // into the |to_profile|. If user was required to authenticate with a proxy |
| 94 // during the login, this authentication information will be transferred | 144 // during the login, this authentication information will be transferred |
| 95 // into the new session. | 145 // into the new session. |
| 96 void TransferDefaultAuthCache(Profile* from_profile, | 146 void TransferDefaultAuthCache(Profile* from_profile, |
| 97 Profile* to_profile) { | 147 Profile* to_profile) { |
| 98 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
| 99 BrowserThread::IO, FROM_HERE, | 149 BrowserThread::IO, FROM_HERE, |
| 100 base::Bind(&TransferDefaultAuthCacheOnIOThread, | 150 base::Bind(&TransferDefaultAuthCacheOnIOThread, |
| 101 make_scoped_refptr(from_profile->GetRequestContext()), | 151 make_scoped_refptr(from_profile->GetRequestContext()), |
| 102 make_scoped_refptr(to_profile->GetRequestContext()))); | 152 make_scoped_refptr(to_profile->GetRequestContext()))); |
| 103 } | 153 } |
| 104 | 154 |
| 105 } // namespace | 155 } // namespace |
| 106 | 156 |
| 107 void ProfileAuthData::Transfer(Profile* from_profile, | 157 void ProfileAuthData::Transfer( |
| 108 Profile* to_profile, | 158 Profile* from_profile, |
| 109 bool transfer_cookies) { | 159 Profile* to_profile, |
| 160 bool transfer_cookies, | |
| 161 const base::Callback<void()>& cookies_transfered_callback) { | |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 111 if (transfer_cookies) | 163 if (transfer_cookies) { |
| 112 TransferDefaultCookiesAndServerBoundCerts(from_profile, to_profile); | 164 TransferDefaultCookiesAndServerBoundCerts(from_profile, |
| 165 to_profile, | |
| 166 cookies_transfered_callback); | |
| 167 } else { | |
| 168 BrowserThread::PostTask( | |
| 169 BrowserThread::IO, FROM_HERE, cookies_transfered_callback); | |
|
xiyuan
2012/12/20 01:57:45
Should |cookies_transfered_callback| be invoked on
zel
2012/12/20 16:56:19
Nope. Good catch!
| |
| 170 } | |
| 113 | 171 |
| 114 TransferDefaultAuthCache(from_profile, to_profile); | 172 TransferDefaultAuthCache(from_profile, to_profile); |
| 115 } | 173 } |
| 116 } // namespace chromeos | 174 } // namespace chromeos |
| OLD | NEW |