OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 net::URLRequestContextGetter* auth_context, Profile* new_profile, | 116 net::URLRequestContextGetter* auth_context, Profile* new_profile, |
117 net::URLRequestContextGetter* new_context) | 117 net::URLRequestContextGetter* new_context) |
118 : auth_context_(auth_context), | 118 : auth_context_(auth_context), |
119 new_profile_(new_profile), | 119 new_profile_(new_profile), |
120 new_context_(new_context) {} | 120 new_context_(new_context) {} |
121 virtual ~TransferDefaultCookiesOnIOThreadTask() {} | 121 virtual ~TransferDefaultCookiesOnIOThreadTask() {} |
122 | 122 |
123 // Task override. | 123 // Task override. |
124 virtual void Run() { | 124 virtual void Run() { |
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
126 net::CookieStore* default_store = | |
127 auth_context_->GetURLRequestContext()->cookie_store(); | |
128 net::CookieMonster* default_monster = default_store->GetCookieMonster(); | |
129 default_monster->SetKeepExpiredCookies(); | |
130 net::CookieStore* new_store = | 126 net::CookieStore* new_store = |
131 new_context_->GetURLRequestContext()->cookie_store(); | 127 new_context_->GetURLRequestContext()->cookie_store(); |
132 net::CookieMonster* new_monster = new_store->GetCookieMonster(); | 128 net::CookieMonster* new_monster = new_store->GetCookieMonster(); |
133 | 129 |
130 new_monster->GetAllCookiesAsync(base::Bind(&HasCookie, | |
131 base::Unretained(this))); | |
132 } | |
133 | |
134 void HasCookie(const net::CookieList& existing_cookies) { | |
zel
2011/08/03 21:44:04
the code changed here, we don't fetch two cookie l
| |
134 // Check that existing store does not already have some cookies. | 135 // Check that existing store does not already have some cookies. |
135 // If it does, we are probably dealing with previously created profile | 136 // If it does, we are probably dealing with previously created profile |
136 // and no transfer will be necessary. | 137 // and no transfer will be necessary. |
137 // TOOD(zelidrag): Investigate perf impact of the next operation | 138 // TOOD(zelidrag): Investigate perf impact of the next operation |
138 // in case when we have a profile with bunch of cookies. | 139 // in case when we have a profile with bunch of cookies. |
139 net::CookieList existing_cookies = new_monster->GetAllCookies(); | |
140 if (existing_cookies.size()) | 140 if (existing_cookies.size()) |
141 return; | 141 return; |
142 | 142 |
143 if (!new_monster->InitializeFrom(default_monster)) { | 143 net::CookieStore* default_store = |
144 auth_context_->GetURLRequestContext()->cookie_store(); | |
145 net::CookieMonster* default_monster = default_store->GetCookieMonster(); | |
146 default_monster->GetAllCookiesAsync(base::Bind(&InitializeCookieMonster, | |
147 base::Unretained(this))); | |
148 } | |
149 | |
150 void InitializeCookieMonster(const net::CookieList& cookies) { | |
151 net::CookieStore* new_store = | |
152 new_context_->GetURLRequestContext()->cookie_store(); | |
153 net::CookieMonster* new_monster = new_store->GetCookieMonster(); | |
154 | |
155 if (!new_monster->InitializeFrom(cookies)) { | |
144 LOG(WARNING) << "Failed initial cookie transfer."; | 156 LOG(WARNING) << "Failed initial cookie transfer."; |
145 } | 157 } |
146 | 158 |
147 // TODO(zelidrag): Once sync is OAuth happy, remove this part. | 159 // TODO(zelidrag): Once sync is OAuth happy, remove this part. |
148 GaiaAuthConsumer::ClientLoginResult credentials; | 160 GaiaAuthConsumer::ClientLoginResult credentials; |
149 GetCredentialsFromCookieJar(default_monster->GetAllCookies(), &credentials); | 161 GetCredentialsFromCookieJar(cookies, &credentials); |
150 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
151 new FetchTokensOnUIThreadTask( | 163 new FetchTokensOnUIThreadTask( |
152 new_profile_, | 164 new_profile_, |
153 credentials)); | 165 credentials)); |
154 } | 166 } |
155 | 167 |
156 // TODO(zelidrag): Once sync is OAuth happy, remove this function. | 168 // TODO(zelidrag): Once sync is OAuth happy, remove this function. |
157 void GetCredentialsFromCookieJar(const net::CookieList& cookies, | 169 void GetCredentialsFromCookieJar(const net::CookieList& cookies, |
158 GaiaAuthConsumer::ClientLoginResult* credentials) { | 170 GaiaAuthConsumer::ClientLoginResult* credentials) { |
159 // At this point we should only have GAIA's cookies in place, | 171 // At this point we should only have GAIA's cookies in place, |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 // Mark login host for deletion after browser starts. This | 842 // Mark login host for deletion after browser starts. This |
831 // guarantees that the message loop will be referenced by the | 843 // guarantees that the message loop will be referenced by the |
832 // browser before it is dereferenced by the login host. | 844 // browser before it is dereferenced by the login host. |
833 if (login_host) { | 845 if (login_host) { |
834 login_host->OnSessionStart(); | 846 login_host->OnSessionStart(); |
835 login_host = NULL; | 847 login_host = NULL; |
836 } | 848 } |
837 } | 849 } |
838 | 850 |
839 } // namespace chromeos | 851 } // namespace chromeos |
OLD | NEW |