| 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 "content/public/browser/browser_context.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "net/cookies/cookie_monster.h" | 9 #include "net/cookies/cookie_monster.h" |
| 10 #include "net/cookies/cookie_store.h" | 10 #include "net/cookies/cookie_store.h" |
| 11 #include "net/http/http_auth_cache.h" | 11 #include "net/http/http_auth_cache.h" |
| 12 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
| 13 #include "net/http/http_transaction_factory.h" | 13 #include "net/http/http_transaction_factory.h" |
| 14 #include "net/ssl/server_bound_cert_service.h" | 14 #include "net/ssl/server_bound_cert_service.h" |
| 15 #include "net/ssl/server_bound_cert_store.h" | 15 #include "net/ssl/server_bound_cert_store.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 class ProfileAuthDataTransferer { | 25 class ProfileAuthDataTransferer { |
| 26 public: | 26 public: |
| 27 ProfileAuthDataTransferer( | 27 ProfileAuthDataTransferer( |
| 28 Profile* from_profile, | 28 content::BrowserContext* from_context, |
| 29 Profile* to_profile, | 29 content::BrowserContext* to_context, |
| 30 bool transfer_cookies, | 30 bool transfer_cookies, |
| 31 const base::Closure& completion_callback); | 31 const base::Closure& completion_callback); |
| 32 | 32 |
| 33 void BeginTransfer(); | 33 void BeginTransfer(); |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 void BeginTransferOnIOThread(); | 36 void BeginTransferOnIOThread(); |
| 37 void MaybeDoCookieAndCertTransfer(); | 37 void MaybeDoCookieAndCertTransfer(); |
| 38 void Finish(); | 38 void Finish(); |
| 39 | 39 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 base::Closure completion_callback_; | 51 base::Closure completion_callback_; |
| 52 | 52 |
| 53 net::CookieList cookies_to_transfer_; | 53 net::CookieList cookies_to_transfer_; |
| 54 net::ServerBoundCertStore::ServerBoundCertList certs_to_transfer_; | 54 net::ServerBoundCertStore::ServerBoundCertList certs_to_transfer_; |
| 55 | 55 |
| 56 bool got_cookies_; | 56 bool got_cookies_; |
| 57 bool got_server_bound_certs_; | 57 bool got_server_bound_certs_; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 ProfileAuthDataTransferer::ProfileAuthDataTransferer( | 60 ProfileAuthDataTransferer::ProfileAuthDataTransferer( |
| 61 Profile* from_profile, | 61 content::BrowserContext* from_context, |
| 62 Profile* to_profile, | 62 content::BrowserContext* to_context, |
| 63 bool transfer_cookies, | 63 bool transfer_cookies, |
| 64 const base::Closure& completion_callback) | 64 const base::Closure& completion_callback) |
| 65 : from_context_(from_profile->GetRequestContext()), | 65 : from_context_(from_context->GetRequestContext()), |
| 66 to_context_(to_profile->GetRequestContext()), | 66 to_context_(to_context->GetRequestContext()), |
| 67 transfer_cookies_(transfer_cookies), | 67 transfer_cookies_(transfer_cookies), |
| 68 completion_callback_(completion_callback), | 68 completion_callback_(completion_callback), |
| 69 got_cookies_(false), | 69 got_cookies_(false), |
| 70 got_server_bound_certs_(false) { | 70 got_server_bound_certs_(false) { |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ProfileAuthDataTransferer::BeginTransfer() { | 73 void ProfileAuthDataTransferer::BeginTransfer() { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 // If we aren't transferring cookies, post the completion callback | 75 // If we aren't transferring cookies, post the completion callback |
| 76 // immediately. Otherwise, it will be called when both cookies and channel | 76 // immediately. Otherwise, it will be called when both cookies and channel |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 void ProfileAuthDataTransferer::Finish() { | 125 void ProfileAuthDataTransferer::Finish() { |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 127 if (!completion_callback_.is_null()) | 127 if (!completion_callback_.is_null()) |
| 128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion_callback_); | 128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion_callback_); |
| 129 delete this; | 129 delete this; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Callback for transferring |cookies_to_transfer_| into |to_context_|'s | 132 // Callback for transferring |cookies_to_transfer_| into |to_context_|'s |
| 133 // CookieMonster if its jar is completely empty. If authentication was | 133 // CookieMonster if its jar is completely empty. If authentication was |
| 134 // performed by an extension, then the set of cookies that was acquired through | 134 // performed by an extension, then the set of cookies that was acquired through |
| 135 // such that process will be automatically transfered into the profile. | 135 // such that process will be automatically transfered into the BrowserContext. |
| 136 void ProfileAuthDataTransferer::OnTransferCookiesIfEmptyJar( | 136 void ProfileAuthDataTransferer::OnTransferCookiesIfEmptyJar( |
| 137 const net::CookieList& cookies_in_jar) { | 137 const net::CookieList& cookies_in_jar) { |
| 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 139 // Transfer only if the existing cookie jar is empty. | 139 // Transfer only if the existing cookie jar is empty. |
| 140 if (!cookies_in_jar.size()) { | 140 if (!cookies_in_jar.size()) { |
| 141 net::CookieStore* to_store = | 141 net::CookieStore* to_store = |
| 142 to_context_->GetURLRequestContext()->cookie_store(); | 142 to_context_->GetURLRequestContext()->cookie_store(); |
| 143 net::CookieMonster* to_monster = to_store->GetCookieMonster(); | 143 net::CookieMonster* to_monster = to_store->GetCookieMonster(); |
| 144 to_monster->InitializeFrom(cookies_to_transfer_); | 144 to_monster->InitializeFrom(cookies_to_transfer_); |
| 145 | 145 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 205 net::HttpAuthCache* new_cache = to_context_->GetURLRequestContext()-> | 205 net::HttpAuthCache* new_cache = to_context_->GetURLRequestContext()-> |
| 206 http_transaction_factory()->GetSession()->http_auth_cache(); | 206 http_transaction_factory()->GetSession()->http_auth_cache(); |
| 207 new_cache->UpdateAllFrom(*from_context_->GetURLRequestContext()-> | 207 new_cache->UpdateAllFrom(*from_context_->GetURLRequestContext()-> |
| 208 http_transaction_factory()->GetSession()->http_auth_cache()); | 208 http_transaction_factory()->GetSession()->http_auth_cache()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 } // namespace | 211 } // namespace |
| 212 | 212 |
| 213 void ProfileAuthData::Transfer( | 213 void ProfileAuthData::Transfer( |
| 214 Profile* from_profile, | 214 content::BrowserContext* from_context, |
| 215 Profile* to_profile, | 215 content::BrowserContext* to_context, |
| 216 bool transfer_cookies, | 216 bool transfer_cookies, |
| 217 const base::Closure& completion_callback) { | 217 const base::Closure& completion_callback) { |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 219 (new ProfileAuthDataTransferer(from_profile, to_profile, transfer_cookies, | 219 (new ProfileAuthDataTransferer(from_context, to_context, transfer_cookies, |
| 220 completion_callback))->BeginTransfer(); | 220 completion_callback))->BeginTransfer(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace chromeos | 223 } // namespace chromeos |
| OLD | NEW |