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 17:03:32
These seem unused. Remove them?
zel
2012/12/20 17:44:18
Done.
| |
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()>& cookies_transfered_callback) { | |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
31 net::CookieStore* new_store = | 77 net::CookieStore* to_store = |
32 to_context->GetURLRequestContext()->cookie_store(); | 78 to_context->GetURLRequestContext()->cookie_store(); |
33 net::CookieMonster* new_monster = new_store->GetCookieMonster(); | 79 net::CookieMonster* to_monster = to_store->GetCookieMonster(); |
34 | 80 |
35 net::CookieStore* default_store = | 81 net::CookieStore* from_store = |
36 from_context->GetURLRequestContext()->cookie_store(); | 82 from_context->GetURLRequestContext()->cookie_store(); |
37 net::CookieMonster* default_monster = default_store->GetCookieMonster(); | 83 net::CookieMonster* from_monster = from_store->GetCookieMonster(); |
38 default_monster->SetKeepExpiredCookies(); | 84 from_monster->SetKeepExpiredCookies(); |
39 default_monster->GetAllCookiesAsync( | 85 from_monster->GetAllCookiesAsync(base::Bind(&OnGetCookiesToTransfer, |
40 base::Bind(base::IgnoreResult(&net::CookieMonster::InitializeFrom), | 86 make_scoped_refptr(to_monster), |
41 new_monster)); | 87 cookies_transfered_callback)); |
42 } | 88 } |
43 | 89 |
44 // Transfers default server bound certs of |from_context| to server bound certs | 90 // Transfers default server bound certs of |from_context| to server bound certs |
45 // storage of |to_context|. | 91 // storage of |to_context|. |
46 void TransferDefaultServerBoundCertsIOThread( | 92 void TransferDefaultServerBoundCertsIOThread( |
47 net::URLRequestContextGetter* from_context, | 93 net::URLRequestContextGetter* from_context, |
48 net::URLRequestContextGetter* to_context) { | 94 net::URLRequestContextGetter* to_context) { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
50 net::ServerBoundCertService* default_service = | 96 net::ServerBoundCertService* default_service = |
51 from_context->GetURLRequestContext()->server_bound_cert_service(); | 97 from_context->GetURLRequestContext()->server_bound_cert_service(); |
(...skipping 17 matching lines...) Expand all Loading... | |
69 new_cache->UpdateAllFrom(*from_context->GetURLRequestContext()-> | 115 new_cache->UpdateAllFrom(*from_context->GetURLRequestContext()-> |
70 http_transaction_factory()->GetSession()->http_auth_cache()); | 116 http_transaction_factory()->GetSession()->http_auth_cache()); |
71 } | 117 } |
72 | 118 |
73 // Transfers cookies and server bound certs from the |from_profile| into | 119 // Transfers cookies and server bound certs from the |from_profile| into |
74 // the |to_profile|. If authentication was performed by an extension, then | 120 // 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 | 121 // the set of cookies that was acquired through such that process will be |
76 // automatically transfered into the profile. | 122 // automatically transfered into the profile. |
77 void TransferDefaultCookiesAndServerBoundCerts( | 123 void TransferDefaultCookiesAndServerBoundCerts( |
78 Profile* from_profile, | 124 Profile* from_profile, |
79 Profile* to_profile) { | 125 Profile* to_profile, |
126 const base::Callback<void()>& cookies_transfered_callback) { | |
80 BrowserThread::PostTask( | 127 BrowserThread::PostTask( |
81 BrowserThread::IO, FROM_HERE, | 128 BrowserThread::IO, FROM_HERE, |
82 base::Bind(&TransferDefaultCookiesOnIOThread, | 129 base::Bind(&TransferDefaultCookiesOnIOThread, |
83 make_scoped_refptr(from_profile->GetRequestContext()), | 130 make_scoped_refptr(from_profile->GetRequestContext()), |
84 make_scoped_refptr(to_profile->GetRequestContext()))); | 131 make_scoped_refptr(to_profile->GetRequestContext()), |
132 cookies_transfered_callback)); | |
85 BrowserThread::PostTask( | 133 BrowserThread::PostTask( |
86 BrowserThread::IO, FROM_HERE, | 134 BrowserThread::IO, FROM_HERE, |
87 base::Bind(&TransferDefaultServerBoundCertsIOThread, | 135 base::Bind(&TransferDefaultServerBoundCertsIOThread, |
88 make_scoped_refptr(from_profile->GetRequestContext()), | 136 make_scoped_refptr(from_profile->GetRequestContext()), |
89 make_scoped_refptr(to_profile->GetRequestContext()))); | 137 make_scoped_refptr(to_profile->GetRequestContext()))); |
90 } | 138 } |
91 | 139 |
92 // Transfers HTTP authentication cache from the |from_profile| | 140 // Transfers HTTP authentication cache from the |from_profile| |
93 // into the |to_profile|. If user was required to authenticate with a proxy | 141 // into the |to_profile|. If user was required to authenticate with a proxy |
94 // during the login, this authentication information will be transferred | 142 // during the login, this authentication information will be transferred |
95 // into the new session. | 143 // into the new session. |
96 void TransferDefaultAuthCache(Profile* from_profile, | 144 void TransferDefaultAuthCache(Profile* from_profile, |
97 Profile* to_profile) { | 145 Profile* to_profile) { |
98 BrowserThread::PostTask( | 146 BrowserThread::PostTask( |
99 BrowserThread::IO, FROM_HERE, | 147 BrowserThread::IO, FROM_HERE, |
100 base::Bind(&TransferDefaultAuthCacheOnIOThread, | 148 base::Bind(&TransferDefaultAuthCacheOnIOThread, |
101 make_scoped_refptr(from_profile->GetRequestContext()), | 149 make_scoped_refptr(from_profile->GetRequestContext()), |
102 make_scoped_refptr(to_profile->GetRequestContext()))); | 150 make_scoped_refptr(to_profile->GetRequestContext()))); |
103 } | 151 } |
104 | 152 |
105 } // namespace | 153 } // namespace |
106 | 154 |
107 void ProfileAuthData::Transfer(Profile* from_profile, | 155 void ProfileAuthData::Transfer( |
108 Profile* to_profile, | 156 Profile* from_profile, |
109 bool transfer_cookies) { | 157 Profile* to_profile, |
158 bool transfer_cookies, | |
159 const base::Callback<void()>& cookies_transfered_callback) { | |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
111 if (transfer_cookies) | 161 if (transfer_cookies) { |
112 TransferDefaultCookiesAndServerBoundCerts(from_profile, to_profile); | 162 TransferDefaultCookiesAndServerBoundCerts(from_profile, |
163 to_profile, | |
164 cookies_transfered_callback); | |
165 } else { | |
166 BrowserThread::PostTask( | |
167 BrowserThread::UI, FROM_HERE, cookies_transfered_callback); | |
168 } | |
113 | 169 |
114 TransferDefaultAuthCache(from_profile, to_profile); | 170 TransferDefaultAuthCache(from_profile, to_profile); |
115 } | 171 } |
116 } // namespace chromeos | 172 } // namespace chromeos |
OLD | NEW |