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

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

Issue 11576065: Improved GAIA cookie retrieval logic in ChromeOS login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | « chrome/browser/chromeos/login/profile_auth_data.h ('k') | no next file » | 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) 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 // Callback for transferring |cookies_to_transfer| into |cookie_monster| if
26 // its jar is completely empty.
27 void OnTransferCookiesIfEmptyJar(
28 net::CookieMonster* cookie_monster,
29 const net::CookieList& cookies_to_transfer,
30 const base::Callback<void()>& cookies_transfered_callback,
31 const net::CookieList& cookies_in_jar) {
32 std::string sid;
33 std::string lsid;
34 // Transfer only if the existing cookie jar is empty.
35 if (!cookies_in_jar.size())
36 cookie_monster->InitializeFrom(cookies_to_transfer);
37
38 BrowserThread::PostTask(
39 BrowserThread::UI, FROM_HERE, cookies_transfered_callback);
40 return;
41 }
42
43 // Callback for receiving |cookies_to_transfer| from the authentication profile
44 // cookie jar.
45 void OnGetCookiesToTransfer(
46 net::CookieMonster* cookie_monster,
47 const base::Callback<void()>& cookies_transfered_callback,
48 const net::CookieList& cookies_to_transfer) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
50
51 // Nothing to transfer over?
52 if (!cookies_to_transfer.size()) {
53 BrowserThread::PostTask(
54 BrowserThread::UI, FROM_HERE, cookies_transfered_callback);
55 return;
56 }
57 // Now let's see if the target cookie monster's jar is even empty.
58 cookie_monster->GetAllCookiesAsync(
59 base::Bind(&OnTransferCookiesIfEmptyJar,
60 make_scoped_refptr(cookie_monster),
61 cookies_to_transfer,
62 cookies_transfered_callback));
63 }
64
25 // Transfers initial set of Profile cookies from the |from_context| to cookie 65 // Transfers initial set of Profile cookies from the |from_context| to cookie
26 // jar of |to_context|. 66 // jar of |to_context|.
27 void TransferDefaultCookiesOnIOThread( 67 void TransferDefaultCookiesOnIOThread(
28 net::URLRequestContextGetter* from_context, 68 net::URLRequestContextGetter* from_context,
29 net::URLRequestContextGetter* to_context) { 69 net::URLRequestContextGetter* to_context,
70 const base::Callback<void()>& cookies_transfered_callback) {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
31 net::CookieStore* new_store = 72 net::CookieStore* to_store =
32 to_context->GetURLRequestContext()->cookie_store(); 73 to_context->GetURLRequestContext()->cookie_store();
33 net::CookieMonster* new_monster = new_store->GetCookieMonster(); 74 net::CookieMonster* to_monster = to_store->GetCookieMonster();
34 75
35 net::CookieStore* default_store = 76 net::CookieStore* from_store =
36 from_context->GetURLRequestContext()->cookie_store(); 77 from_context->GetURLRequestContext()->cookie_store();
37 net::CookieMonster* default_monster = default_store->GetCookieMonster(); 78 net::CookieMonster* from_monster = from_store->GetCookieMonster();
38 default_monster->SetKeepExpiredCookies(); 79 from_monster->SetKeepExpiredCookies();
39 default_monster->GetAllCookiesAsync( 80 from_monster->GetAllCookiesAsync(base::Bind(&OnGetCookiesToTransfer,
40 base::Bind(base::IgnoreResult(&net::CookieMonster::InitializeFrom), 81 make_scoped_refptr(to_monster),
41 new_monster)); 82 cookies_transfered_callback));
42 } 83 }
43 84
44 // Transfers default server bound certs of |from_context| to server bound certs 85 // Transfers default server bound certs of |from_context| to server bound certs
45 // storage of |to_context|. 86 // storage of |to_context|.
46 void TransferDefaultServerBoundCertsIOThread( 87 void TransferDefaultServerBoundCertsIOThread(
47 net::URLRequestContextGetter* from_context, 88 net::URLRequestContextGetter* from_context,
48 net::URLRequestContextGetter* to_context) { 89 net::URLRequestContextGetter* to_context) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
50 net::ServerBoundCertService* default_service = 91 net::ServerBoundCertService* default_service =
51 from_context->GetURLRequestContext()->server_bound_cert_service(); 92 from_context->GetURLRequestContext()->server_bound_cert_service();
(...skipping 17 matching lines...) Expand all
69 new_cache->UpdateAllFrom(*from_context->GetURLRequestContext()-> 110 new_cache->UpdateAllFrom(*from_context->GetURLRequestContext()->
70 http_transaction_factory()->GetSession()->http_auth_cache()); 111 http_transaction_factory()->GetSession()->http_auth_cache());
71 } 112 }
72 113
73 // Transfers cookies and server bound certs from the |from_profile| into 114 // Transfers cookies and server bound certs from the |from_profile| into
74 // the |to_profile|. If authentication was performed by an extension, then 115 // 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 116 // the set of cookies that was acquired through such that process will be
76 // automatically transfered into the profile. 117 // automatically transfered into the profile.
77 void TransferDefaultCookiesAndServerBoundCerts( 118 void TransferDefaultCookiesAndServerBoundCerts(
78 Profile* from_profile, 119 Profile* from_profile,
79 Profile* to_profile) { 120 Profile* to_profile,
121 const base::Callback<void()>& cookies_transfered_callback) {
80 BrowserThread::PostTask( 122 BrowserThread::PostTask(
81 BrowserThread::IO, FROM_HERE, 123 BrowserThread::IO, FROM_HERE,
82 base::Bind(&TransferDefaultCookiesOnIOThread, 124 base::Bind(&TransferDefaultCookiesOnIOThread,
83 make_scoped_refptr(from_profile->GetRequestContext()), 125 make_scoped_refptr(from_profile->GetRequestContext()),
84 make_scoped_refptr(to_profile->GetRequestContext()))); 126 make_scoped_refptr(to_profile->GetRequestContext()),
127 cookies_transfered_callback));
85 BrowserThread::PostTask( 128 BrowserThread::PostTask(
86 BrowserThread::IO, FROM_HERE, 129 BrowserThread::IO, FROM_HERE,
87 base::Bind(&TransferDefaultServerBoundCertsIOThread, 130 base::Bind(&TransferDefaultServerBoundCertsIOThread,
88 make_scoped_refptr(from_profile->GetRequestContext()), 131 make_scoped_refptr(from_profile->GetRequestContext()),
89 make_scoped_refptr(to_profile->GetRequestContext()))); 132 make_scoped_refptr(to_profile->GetRequestContext())));
90 } 133 }
91 134
92 // Transfers HTTP authentication cache from the |from_profile| 135 // Transfers HTTP authentication cache from the |from_profile|
93 // into the |to_profile|. If user was required to authenticate with a proxy 136 // into the |to_profile|. If user was required to authenticate with a proxy
94 // during the login, this authentication information will be transferred 137 // during the login, this authentication information will be transferred
95 // into the new session. 138 // into the new session.
96 void TransferDefaultAuthCache(Profile* from_profile, 139 void TransferDefaultAuthCache(Profile* from_profile,
97 Profile* to_profile) { 140 Profile* to_profile) {
98 BrowserThread::PostTask( 141 BrowserThread::PostTask(
99 BrowserThread::IO, FROM_HERE, 142 BrowserThread::IO, FROM_HERE,
100 base::Bind(&TransferDefaultAuthCacheOnIOThread, 143 base::Bind(&TransferDefaultAuthCacheOnIOThread,
101 make_scoped_refptr(from_profile->GetRequestContext()), 144 make_scoped_refptr(from_profile->GetRequestContext()),
102 make_scoped_refptr(to_profile->GetRequestContext()))); 145 make_scoped_refptr(to_profile->GetRequestContext())));
103 } 146 }
104 147
105 } // namespace 148 } // namespace
106 149
107 void ProfileAuthData::Transfer(Profile* from_profile, 150 void ProfileAuthData::Transfer(
108 Profile* to_profile, 151 Profile* from_profile,
109 bool transfer_cookies) { 152 Profile* to_profile,
153 bool transfer_cookies,
154 const base::Callback<void()>& cookies_transfered_callback) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 if (transfer_cookies) 156 if (transfer_cookies) {
112 TransferDefaultCookiesAndServerBoundCerts(from_profile, to_profile); 157 TransferDefaultCookiesAndServerBoundCerts(from_profile,
158 to_profile,
159 cookies_transfered_callback);
160 } else {
161 BrowserThread::PostTask(
162 BrowserThread::UI, FROM_HERE, cookies_transfered_callback);
163 }
113 164
114 TransferDefaultAuthCache(from_profile, to_profile); 165 TransferDefaultAuthCache(from_profile, to_profile);
115 } 166 }
116 } // namespace chromeos 167 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/profile_auth_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698