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

Side by Side Diff: android_webview/native/cookie_manager.cc

Issue 273873003: Adds Asynchronous APIs to CookieManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 7 months 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
OLDNEW
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 "android_webview/native/cookie_manager.h" 5 #include "android_webview/native/cookie_manager.h"
6 6
7 #include "android_webview/browser/aw_browser_context.h" 7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_cookie_access_policy.h" 8 #include "android_webview/browser/aw_cookie_access_policy.h"
9 #include "android_webview/browser/net/init_native_callback.h" 9 #include "android_webview/browser/net/init_native_callback.h"
10 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" 10 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
(...skipping 17 matching lines...) Expand all
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/cookie_crypto_delegate.h" 29 #include "content/public/browser/cookie_crypto_delegate.h"
30 #include "content/public/browser/cookie_store_factory.h" 30 #include "content/public/browser/cookie_store_factory.h"
31 #include "content/public/common/url_constants.h" 31 #include "content/public/common/url_constants.h"
32 #include "jni/AwCookieManager_jni.h" 32 #include "jni/AwCookieManager_jni.h"
33 #include "net/cookies/cookie_monster.h" 33 #include "net/cookies/cookie_monster.h"
34 #include "net/cookies/cookie_options.h" 34 #include "net/cookies/cookie_options.h"
35 #include "net/url_request/url_request_context.h" 35 #include "net/url_request/url_request_context.h"
36 36
37 using base::FilePath; 37 using base::FilePath;
38 using base::WaitableEvent;
38 using base::android::ConvertJavaStringToUTF8; 39 using base::android::ConvertJavaStringToUTF8;
39 using base::android::ConvertJavaStringToUTF16; 40 using base::android::ConvertJavaStringToUTF16;
41 using base::android::ScopedJavaGlobalRef;
40 using content::BrowserThread; 42 using content::BrowserThread;
41 using net::CookieList; 43 using net::CookieList;
42 using net::CookieMonster; 44 using net::CookieMonster;
43 45
44 // In the future, we may instead want to inject an explicit CookieStore 46 // In the future, we may instead want to inject an explicit CookieStore
45 // dependency into this object during process initialization to avoid 47 // dependency into this object during process initialization to avoid
46 // depending on the URLRequestContext. 48 // depending on the URLRequestContext.
47 // See issue http://crbug.com/157683 49 // See issue http://crbug.com/157683
48 50
49 // All functions on the CookieManager can be called from any thread, including 51 // All functions on the CookieManager can be called from any thread, including
50 // threads without a message loop. BrowserThread::IO is used to call methods 52 // threads without a message loop. BrowserThread::IO is used to call methods
51 // on CookieMonster that needs to be called, and called back, on a chrome 53 // on CookieMonster that needs to be called, and called back, on a chrome
52 // thread. 54 // thread.
53 55
54 namespace android_webview { 56 namespace android_webview {
55 57
58 class RemoveCookiesCallback {
mkosiba (inactive) 2014/05/13 09:37:17 same here. CookieCallbackInteger, CookieCallbackBo
hjd_google 2014/05/15 10:52:07 Done.
59 public:
60 RemoveCookiesCallback(JNIEnv* env, jobject callback) {
61 callback_.Reset(env, callback);
62 }
63
64 void Invoke(int num_deleted) {
65 if (!callback_.is_null()) {
66 JNIEnv* env = base::android::AttachCurrentThread();
67 Java_AwCookieManager_invokeRemoveCookieCallback(
68 env, callback_.obj(), num_deleted);
69 }
70 }
71
72 private:
73 ScopedJavaGlobalRef<jobject> callback_;
74 DISALLOW_COPY_AND_ASSIGN(RemoveCookiesCallback);
75 };
76
77 class SetCookieCallback {
78 public:
79 SetCookieCallback(JNIEnv* env, jobject callback) {
80 callback_.Reset(env, callback);
81 }
82
83 void Invoke(bool success) {
84 if (!callback_.is_null()) {
85 JNIEnv* env = base::android::AttachCurrentThread();
86 Java_AwCookieManager_invokeSetCookieCallback(
87 env, callback_.obj(), success);
88 }
89 }
90
91 private:
92 ScopedJavaGlobalRef<jobject> callback_;
93 DISALLOW_COPY_AND_ASSIGN(SetCookieCallback);
94 };
95
56 namespace { 96 namespace {
57 97
58 // Are cookies allowed for file:// URLs by default? 98 // Are cookies allowed for file:// URLs by default?
59 const bool kDefaultFileSchemeAllowed = false; 99 const bool kDefaultFileSchemeAllowed = false;
60 100
61 void ImportLegacyCookieStore(const FilePath& cookie_store_path) { 101 void ImportLegacyCookieStore(const FilePath& cookie_store_path) {
62 // We use the old cookie store to create the new cookie store only if the 102 // We use the old cookie store to create the new cookie store only if the
63 // new cookie store does not exist. 103 // new cookie store does not exist.
64 if (base::PathExists(cookie_store_path)) 104 if (base::PathExists(cookie_store_path))
65 return; 105 return;
(...skipping 25 matching lines...) Expand all
91 public: 131 public:
92 static CookieManager* GetInstance(); 132 static CookieManager* GetInstance();
93 133
94 scoped_refptr<net::CookieStore> CreateBrowserThreadCookieStore( 134 scoped_refptr<net::CookieStore> CreateBrowserThreadCookieStore(
95 AwBrowserContext* browser_context); 135 AwBrowserContext* browser_context);
96 136
97 void SetAcceptCookie(bool accept); 137 void SetAcceptCookie(bool accept);
98 bool AcceptCookie(); 138 bool AcceptCookie();
99 void SetAcceptThirdPartyCookie(bool accept); 139 void SetAcceptThirdPartyCookie(bool accept);
100 bool AcceptThirdPartyCookie(); 140 bool AcceptThirdPartyCookie();
101 void SetCookie(const GURL& host, const std::string& cookie_value); 141 void SetCookie(const GURL& host,
142 const std::string& cookie_value,
143 scoped_ptr<SetCookieCallback> callback);
144 void SetCookieSync(const GURL& host,
145 const std::string& cookie_value);
102 std::string GetCookie(const GURL& host); 146 std::string GetCookie(const GURL& host);
103 void RemoveSessionCookie(); 147 void RemoveSessionCookie(scoped_ptr<RemoveCookiesCallback> callback);
104 void RemoveAllCookie(); 148 void RemoveAllCookie(scoped_ptr<RemoveCookiesCallback> callback);
149 void RemoveAllCookieSync();
150 void RemoveSessionCookieSync();
105 void RemoveExpiredCookie(); 151 void RemoveExpiredCookie();
106 void FlushCookieStore(); 152 void FlushCookieStore();
107 bool HasCookies(); 153 bool HasCookies();
108 bool AllowFileSchemeCookies(); 154 bool AllowFileSchemeCookies();
109 void SetAcceptFileSchemeCookies(bool accept); 155 void SetAcceptFileSchemeCookies(bool accept);
110 156
111 private: 157 private:
112 friend struct base::DefaultLazyInstanceTraits<CookieManager>; 158 friend struct base::DefaultLazyInstanceTraits<CookieManager>;
113 159
114 CookieManager(); 160 CookieManager();
115 ~CookieManager(); 161 ~CookieManager();
116 162
117 typedef base::Callback<void(base::WaitableEvent*)> CookieTask; 163 typedef base::Callback<void(WaitableEvent*)> CookieSyncTask;
164 typedef base::Callback<void()> CookieTask;
mkosiba (inactive) 2014/05/13 09:37:17 FYI: you're redefining base::Closure
165 void ExecCookieTaskSync(const CookieSyncTask& task);
118 void ExecCookieTask(const CookieTask& task); 166 void ExecCookieTask(const CookieTask& task);
119 167
120 void SetCookieAsyncHelper( 168 void SetCookieHelper(
121 const GURL& host, 169 const GURL& host,
122 const std::string& value, 170 const std::string& value,
123 base::WaitableEvent* completion); 171 scoped_ptr<SetCookieCallback> callback);
124 void SetCookieCompleted(base::WaitableEvent* completion, bool success); 172 void SetCookieSyncHelper(
173 const GURL& host,
174 const std::string& value,
175 WaitableEvent* completion);
176 void SetCookieCompleted(scoped_ptr<SetCookieCallback> callback, bool success);
177 void SetCookieSyncCompleted(WaitableEvent* completion, bool success);
125 178
126 void GetCookieValueAsyncHelper( 179 void GetCookieValueAsyncHelper(
127 const GURL& host, 180 const GURL& host,
128 std::string* result, 181 std::string* result,
129 base::WaitableEvent* completion); 182 WaitableEvent* completion);
130 void GetCookieValueCompleted(base::WaitableEvent* completion, 183 void GetCookieValueCompleted(WaitableEvent* completion,
131 std::string* result, 184 std::string* result,
132 const std::string& value); 185 const std::string& value);
133 186
134 void RemoveSessionCookieAsyncHelper(base::WaitableEvent* completion); 187 void RemoveSessionCookieHelper(scoped_ptr<RemoveCookiesCallback> callback);
135 void RemoveAllCookieAsyncHelper(base::WaitableEvent* completion); 188 void RemoveAllCookieHelper(scoped_ptr<RemoveCookiesCallback> callback);
136 void RemoveCookiesCompleted(base::WaitableEvent* completion, int num_deleted); 189 void RemoveCookiesCompleted(scoped_ptr<RemoveCookiesCallback> callback,
190 int num_deleted);
137 191
138 void FlushCookieStoreAsyncHelper(base::WaitableEvent* completion); 192 void RemoveSessionCookieSyncHelper(WaitableEvent* completion);
193 void RemoveAllCookieSyncHelper(WaitableEvent* completion);
194 void RemoveCookiesSyncCompleted(WaitableEvent* completion, int num_deleted);
195
196 void FlushCookieStoreAsyncHelper(WaitableEvent* completion);
139 197
140 void HasCookiesAsyncHelper(bool* result, 198 void HasCookiesAsyncHelper(bool* result,
141 base::WaitableEvent* completion); 199 WaitableEvent* completion);
142 void HasCookiesCompleted(base::WaitableEvent* completion, 200 void HasCookiesCompleted(WaitableEvent* completion,
143 bool* result, 201 bool* result,
144 const CookieList& cookies); 202 const CookieList& cookies);
145 203
146 void CreateCookieMonster( 204 void CreateCookieMonster(
147 const FilePath& user_data_dir, 205 const FilePath& user_data_dir,
148 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, 206 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
149 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); 207 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner);
150 void EnsureCookieMonsterExistsLocked(); 208 void EnsureCookieMonsterExistsLocked();
151 bool AllowFileSchemeCookiesLocked(); 209 bool AllowFileSchemeCookiesLocked();
152 void SetAcceptFileSchemeCookiesLocked(bool accept); 210 void SetAcceptFileSchemeCookiesLocked(bool accept);
153 211
154 scoped_refptr<net::CookieMonster> cookie_monster_; 212 scoped_refptr<net::CookieMonster> cookie_monster_;
155 scoped_refptr<base::MessageLoopProxy> cookie_monster_proxy_; 213 scoped_refptr<base::MessageLoopProxy> cookie_monster_proxy_;
156 base::Lock cookie_monster_lock_; 214 base::Lock cookie_monster_lock_;
157 215
158 // Both these threads are normally NULL. They only exist if CookieManager was 216 // Both these threads are normally NULL. They only exist if CookieManager was
159 // accessed before Chromium was started. 217 // accessed before Chromium was started.
160 scoped_ptr<base::Thread> cookie_monster_client_thread_; 218 scoped_ptr<base::Thread> cookie_monster_client_thread_;
161 scoped_ptr<base::Thread> cookie_monster_backend_thread_; 219 scoped_ptr<base::Thread> cookie_monster_backend_thread_;
162 220
163 DISALLOW_COPY_AND_ASSIGN(CookieManager); 221 DISALLOW_COPY_AND_ASSIGN(CookieManager);
164 }; 222 };
165 223
224
166 base::LazyInstance<CookieManager>::Leaky g_lazy_instance; 225 base::LazyInstance<CookieManager>::Leaky g_lazy_instance;
167 226
168 // static 227 // static
169 CookieManager* CookieManager::GetInstance() { 228 CookieManager* CookieManager::GetInstance() {
170 return g_lazy_instance.Pointer(); 229 return g_lazy_instance.Pointer();
171 } 230 }
172 231
173 CookieManager::CookieManager() { 232 CookieManager::CookieManager() {
174 } 233 }
175 234
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 cookie_monster_proxy_ = cookie_monster_client_thread_->message_loop_proxy(); 273 cookie_monster_proxy_ = cookie_monster_client_thread_->message_loop_proxy();
215 cookie_monster_backend_thread_.reset( 274 cookie_monster_backend_thread_.reset(
216 new base::Thread("CookieMonsterBackend")); 275 new base::Thread("CookieMonsterBackend"));
217 cookie_monster_backend_thread_->Start(); 276 cookie_monster_backend_thread_->Start();
218 277
219 CreateCookieMonster(user_data_dir, 278 CreateCookieMonster(user_data_dir,
220 cookie_monster_proxy_, 279 cookie_monster_proxy_,
221 cookie_monster_backend_thread_->message_loop_proxy()); 280 cookie_monster_backend_thread_->message_loop_proxy());
222 } 281 }
223 282
224 // Executes the |task| on the |cookie_monster_proxy_| message loop. 283 // Executes the |task| on the |cookie_monster_proxy_| message loop and
225 void CookieManager::ExecCookieTask(const CookieTask& task) { 284 // waits for it to complete before returning.
226 base::WaitableEvent completion(false, false); 285 void CookieManager::ExecCookieTaskSync(const CookieSyncTask& task) {
286 WaitableEvent completion(false, false);
227 base::AutoLock lock(cookie_monster_lock_); 287 base::AutoLock lock(cookie_monster_lock_);
228 288
229 EnsureCookieMonsterExistsLocked(); 289 EnsureCookieMonsterExistsLocked();
230 290
231 cookie_monster_proxy_->PostTask(FROM_HERE, base::Bind(task, &completion)); 291 cookie_monster_proxy_->PostTask(FROM_HERE, base::Bind(task, &completion));
232 292
233 // We always wait for the posted task to complete, even when it doesn't return
234 // a value, because previous versions of the CookieManager API were
235 // synchronous in most/all cases and the caller may be relying on this.
236 ScopedAllowWaitForLegacyWebViewApi wait; 293 ScopedAllowWaitForLegacyWebViewApi wait;
237 completion.Wait(); 294 completion.Wait();
238 } 295 }
239 296
297 // Executes the |task| on the |cookie_monster_proxy_| message loop.
298 void CookieManager::ExecCookieTask(const CookieTask& task) {
299 base::AutoLock lock(cookie_monster_lock_);
300 EnsureCookieMonsterExistsLocked();
301 cookie_monster_proxy_->PostTask(FROM_HERE, task);
302 }
303
240 scoped_refptr<net::CookieStore> CookieManager::CreateBrowserThreadCookieStore( 304 scoped_refptr<net::CookieStore> CookieManager::CreateBrowserThreadCookieStore(
241 AwBrowserContext* browser_context) { 305 AwBrowserContext* browser_context) {
242 base::AutoLock lock(cookie_monster_lock_); 306 base::AutoLock lock(cookie_monster_lock_);
243 307
244 if (cookie_monster_client_thread_) { 308 if (cookie_monster_client_thread_) {
245 // We created a cookie monster already on its own threads; we'll just keep 309 // We created a cookie monster already on its own threads; we'll just keep
246 // using it rather than creating one on the normal Chromium threads. 310 // using it rather than creating one on the normal Chromium threads.
247 // CookieMonster is threadsafe, so this is fine. 311 // CookieMonster is threadsafe, so this is fine.
248 return cookie_monster_; 312 return cookie_monster_;
249 } 313 }
(...skipping 27 matching lines...) Expand all
277 341
278 void CookieManager::SetAcceptThirdPartyCookie(bool accept) { 342 void CookieManager::SetAcceptThirdPartyCookie(bool accept) {
279 AwCookieAccessPolicy::GetInstance()->SetThirdPartyAllowAccess(accept); 343 AwCookieAccessPolicy::GetInstance()->SetThirdPartyAllowAccess(accept);
280 } 344 }
281 345
282 bool CookieManager::AcceptThirdPartyCookie() { 346 bool CookieManager::AcceptThirdPartyCookie() {
283 return AwCookieAccessPolicy::GetInstance()->GetThirdPartyAllowAccess(); 347 return AwCookieAccessPolicy::GetInstance()->GetThirdPartyAllowAccess();
284 } 348 }
285 349
286 void CookieManager::SetCookie(const GURL& host, 350 void CookieManager::SetCookie(const GURL& host,
351 const std::string& cookie_value,
352 scoped_ptr<SetCookieCallback> callback) {
353 ExecCookieTask(base::Bind(&CookieManager::SetCookieHelper,
354 base::Unretained(this),
355 host,
356 cookie_value,
357 Passed(&callback)));
358 }
359
360 void CookieManager::SetCookieSync(const GURL& host,
287 const std::string& cookie_value) { 361 const std::string& cookie_value) {
288 ExecCookieTask(base::Bind(&CookieManager::SetCookieAsyncHelper, 362 ExecCookieTaskSync(base::Bind(&CookieManager::SetCookieSyncHelper,
289 base::Unretained(this), 363 base::Unretained(this),
290 host, 364 host,
291 cookie_value)); 365 cookie_value));
292 } 366 }
293 367
294 void CookieManager::SetCookieAsyncHelper( 368 void CookieManager::SetCookieHelper(
295 const GURL& host, 369 const GURL& host,
296 const std::string& value, 370 const std::string& value,
297 base::WaitableEvent* completion) { 371 scoped_ptr<SetCookieCallback> callback) {
298 net::CookieOptions options; 372 net::CookieOptions options;
299 options.set_include_httponly(); 373 options.set_include_httponly();
300 374
301 cookie_monster_->SetCookieWithOptionsAsync( 375 cookie_monster_->SetCookieWithOptionsAsync(
302 host, value, options, 376 host, value, options,
303 base::Bind(&CookieManager::SetCookieCompleted, 377 base::Bind(&CookieManager::SetCookieCompleted,
304 base::Unretained(this), 378 base::Unretained(this),
379 Passed(&callback)));
380 }
381
382 void CookieManager::SetCookieSyncHelper(
383 const GURL& host,
384 const std::string& value,
385 WaitableEvent* completion) {
386 net::CookieOptions options;
387 options.set_include_httponly();
388
389 cookie_monster_->SetCookieWithOptionsAsync(
390 host, value, options,
391 base::Bind(&CookieManager::SetCookieSyncCompleted,
392 base::Unretained(this),
305 completion)); 393 completion));
306 } 394 }
307 395
308 void CookieManager::SetCookieCompleted(base::WaitableEvent* completion, 396 void CookieManager::SetCookieCompleted(scoped_ptr<SetCookieCallback> callback,
309 bool success) { 397 bool success) {
310 // The CookieManager API does not return a value for SetCookie, 398 callback->Invoke(success);
311 // so we don't need to propagate the |success| value back to the caller. 399 }
400
401 void CookieManager::SetCookieSyncCompleted(WaitableEvent* completion,
402 bool success) {
312 completion->Signal(); 403 completion->Signal();
313 } 404 }
314 405
315 std::string CookieManager::GetCookie(const GURL& host) { 406 std::string CookieManager::GetCookie(const GURL& host) {
316 std::string cookie_value; 407 std::string cookie_value;
317 ExecCookieTask(base::Bind(&CookieManager::GetCookieValueAsyncHelper, 408 ExecCookieTaskSync(base::Bind(&CookieManager::GetCookieValueAsyncHelper,
318 base::Unretained(this), 409 base::Unretained(this),
319 host, 410 host,
320 &cookie_value)); 411 &cookie_value));
321 412
322 return cookie_value; 413 return cookie_value;
323 } 414 }
324 415
325 void CookieManager::GetCookieValueAsyncHelper( 416 void CookieManager::GetCookieValueAsyncHelper(
326 const GURL& host, 417 const GURL& host,
327 std::string* result, 418 std::string* result,
328 base::WaitableEvent* completion) { 419 WaitableEvent* completion) {
329 net::CookieOptions options; 420 net::CookieOptions options;
330 options.set_include_httponly(); 421 options.set_include_httponly();
331 422
332 cookie_monster_->GetCookiesWithOptionsAsync( 423 cookie_monster_->GetCookiesWithOptionsAsync(
333 host, 424 host,
334 options, 425 options,
335 base::Bind(&CookieManager::GetCookieValueCompleted, 426 base::Bind(&CookieManager::GetCookieValueCompleted,
336 base::Unretained(this), 427 base::Unretained(this),
337 completion, 428 completion,
338 result)); 429 result));
339 } 430 }
340 431
341 void CookieManager::GetCookieValueCompleted(base::WaitableEvent* completion, 432 void CookieManager::GetCookieValueCompleted(WaitableEvent* completion,
342 std::string* result, 433 std::string* result,
343 const std::string& value) { 434 const std::string& value) {
344 *result = value; 435 *result = value;
345 completion->Signal(); 436 completion->Signal();
346 } 437 }
347 438
348 void CookieManager::RemoveSessionCookie() { 439 void CookieManager::RemoveSessionCookie(
349 ExecCookieTask(base::Bind(&CookieManager::RemoveSessionCookieAsyncHelper, 440 scoped_ptr<RemoveCookiesCallback> callback) {
441 ExecCookieTask(base::Bind(&CookieManager::RemoveSessionCookieHelper,
442 base::Unretained(this),
443 Passed(&callback)));
444 }
445
446 void CookieManager::RemoveSessionCookieSync() {
447 ExecCookieTaskSync(base::Bind(&CookieManager::RemoveSessionCookieSyncHelper,
350 base::Unretained(this))); 448 base::Unretained(this)));
351 } 449 }
352 450
353 void CookieManager::RemoveSessionCookieAsyncHelper( 451 void CookieManager::RemoveSessionCookieHelper(
354 base::WaitableEvent* completion) { 452 scoped_ptr<RemoveCookiesCallback> callback) {
355 cookie_monster_->DeleteSessionCookiesAsync( 453 cookie_monster_->DeleteSessionCookiesAsync(
356 base::Bind(&CookieManager::RemoveCookiesCompleted, 454 base::Bind(&CookieManager::RemoveCookiesCompleted,
357 base::Unretained(this), 455 base::Unretained(this),
456 Passed(&callback)));
457 }
458
459 void CookieManager::RemoveSessionCookieSyncHelper(WaitableEvent* completion) {
460 cookie_monster_->DeleteSessionCookiesAsync(
461 base::Bind(&CookieManager::RemoveCookiesSyncCompleted,
462 base::Unretained(this),
358 completion)); 463 completion));
359 } 464 }
360 465
361 void CookieManager::RemoveCookiesCompleted(base::WaitableEvent* completion, 466 void CookieManager::RemoveCookiesCompleted(
mkosiba (inactive) 2014/05/13 09:37:17 like we talked offline - let's try and collapse th
hjd_google 2014/05/15 10:52:07 Done!
362 int num_deleted) { 467 scoped_ptr<RemoveCookiesCallback> callback,
363 // The CookieManager API does not return a value for removeSessionCookie or 468 int num_deleted) {
364 // removeAllCookie, so we don't need to propagate the |num_deleted| value back 469 callback->Invoke(num_deleted);
365 // to the caller. 470 }
471
472 void CookieManager::RemoveCookiesSyncCompleted(
473 WaitableEvent* completion,
474 int num_deleted) {
366 completion->Signal(); 475 completion->Signal();
367 } 476 }
368 477
369 void CookieManager::RemoveAllCookie() { 478 void CookieManager::RemoveAllCookie(
370 ExecCookieTask(base::Bind(&CookieManager::RemoveAllCookieAsyncHelper, 479 scoped_ptr<RemoveCookiesCallback> callback) {
480 ExecCookieTask(base::Bind(&CookieManager::RemoveAllCookieHelper,
481 base::Unretained(this),
482 Passed(&callback)));
483 }
484
485 void CookieManager::RemoveAllCookieSync() {
486 ExecCookieTaskSync(base::Bind(&CookieManager::RemoveAllCookieSyncHelper,
371 base::Unretained(this))); 487 base::Unretained(this)));
372 } 488 }
373 489
374 void CookieManager::RemoveAllCookieAsyncHelper( 490 void CookieManager::RemoveAllCookieHelper(
375 base::WaitableEvent* completion) { 491 scoped_ptr<RemoveCookiesCallback> callback) {
376 cookie_monster_->DeleteAllAsync( 492 cookie_monster_->DeleteAllAsync(
377 base::Bind(&CookieManager::RemoveCookiesCompleted, 493 base::Bind(&CookieManager::RemoveCookiesCompleted,
378 base::Unretained(this), 494 base::Unretained(this),
495 Passed(&callback)));
496 }
497
498 void CookieManager::RemoveAllCookieSyncHelper(
499 WaitableEvent* completion) {
500 cookie_monster_->DeleteAllAsync(
501 base::Bind(&CookieManager::RemoveCookiesSyncCompleted,
502 base::Unretained(this),
379 completion)); 503 completion));
380 } 504 }
381 505
382 void CookieManager::RemoveExpiredCookie() { 506 void CookieManager::RemoveExpiredCookie() {
383 // HasCookies will call GetAllCookiesAsync, which in turn will force a GC. 507 // HasCookies will call GetAllCookiesAsync, which in turn will force a GC.
384 HasCookies(); 508 HasCookies();
385 } 509 }
386 510
387 void CookieManager::FlushCookieStoreAsyncHelper( 511 void CookieManager::FlushCookieStoreAsyncHelper(
388 base::WaitableEvent* completion) { 512 WaitableEvent* completion) {
389 cookie_monster_->FlushStore(base::Bind(&base::WaitableEvent::Signal, 513 cookie_monster_->FlushStore(base::Bind(&WaitableEvent::Signal,
390 base::Unretained(completion))); 514 base::Unretained(completion)));
391 } 515 }
392 516
393 void CookieManager::FlushCookieStore() { 517 void CookieManager::FlushCookieStore() {
394 ExecCookieTask(base::Bind(&CookieManager::FlushCookieStoreAsyncHelper, 518 ExecCookieTaskSync(base::Bind(&CookieManager::FlushCookieStoreAsyncHelper,
395 base::Unretained(this))); 519 base::Unretained(this)));
396 } 520 }
397 521
398 bool CookieManager::HasCookies() { 522 bool CookieManager::HasCookies() {
399 bool has_cookies; 523 bool has_cookies;
400 ExecCookieTask(base::Bind(&CookieManager::HasCookiesAsyncHelper, 524 ExecCookieTaskSync(base::Bind(&CookieManager::HasCookiesAsyncHelper,
401 base::Unretained(this), 525 base::Unretained(this),
402 &has_cookies)); 526 &has_cookies));
403 return has_cookies; 527 return has_cookies;
404 } 528 }
405 529
406 // TODO(kristianm): Simplify this, copying the entire list around 530 // TODO(kristianm): Simplify this, copying the entire list around
407 // should not be needed. 531 // should not be needed.
408 void CookieManager::HasCookiesAsyncHelper(bool* result, 532 void CookieManager::HasCookiesAsyncHelper(bool* result,
409 base::WaitableEvent* completion) { 533 WaitableEvent* completion) {
410 cookie_monster_->GetAllCookiesAsync( 534 cookie_monster_->GetAllCookiesAsync(
411 base::Bind(&CookieManager::HasCookiesCompleted, 535 base::Bind(&CookieManager::HasCookiesCompleted,
412 base::Unretained(this), 536 base::Unretained(this),
413 completion, 537 completion,
414 result)); 538 result));
415 } 539 }
416 540
417 void CookieManager::HasCookiesCompleted(base::WaitableEvent* completion, 541 void CookieManager::HasCookiesCompleted(WaitableEvent* completion,
418 bool* result, 542 bool* result,
419 const CookieList& cookies) { 543 const CookieList& cookies) {
420 *result = cookies.size() != 0; 544 *result = cookies.size() != 0;
421 completion->Signal(); 545 completion->Signal();
422 } 546 }
423 547
424 bool CookieManager::AllowFileSchemeCookies() { 548 bool CookieManager::AllowFileSchemeCookies() {
425 base::AutoLock lock(cookie_monster_lock_); 549 base::AutoLock lock(cookie_monster_lock_);
426 EnsureCookieMonsterExistsLocked(); 550 EnsureCookieMonsterExistsLocked();
427 return AllowFileSchemeCookiesLocked(); 551 return AllowFileSchemeCookiesLocked();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 static void SetAcceptThirdPartyCookie(JNIEnv* env, 584 static void SetAcceptThirdPartyCookie(JNIEnv* env,
461 jobject obj, 585 jobject obj,
462 jboolean accept) { 586 jboolean accept) {
463 CookieManager::GetInstance()->SetAcceptThirdPartyCookie(accept); 587 CookieManager::GetInstance()->SetAcceptThirdPartyCookie(accept);
464 } 588 }
465 589
466 static jboolean AcceptThirdPartyCookie(JNIEnv* env, jobject obj) { 590 static jboolean AcceptThirdPartyCookie(JNIEnv* env, jobject obj) {
467 return CookieManager::GetInstance()->AcceptThirdPartyCookie(); 591 return CookieManager::GetInstance()->AcceptThirdPartyCookie();
468 } 592 }
469 593
470 static void SetCookie(JNIEnv* env, jobject obj, jstring url, jstring value) { 594 static void SetCookie(JNIEnv* env,
595 jobject obj,
596 jstring url,
597 jstring value,
598 jobject java_callback) {
471 GURL host(ConvertJavaStringToUTF16(env, url)); 599 GURL host(ConvertJavaStringToUTF16(env, url));
472 std::string cookie_value(ConvertJavaStringToUTF8(env, value)); 600 std::string cookie_value(ConvertJavaStringToUTF8(env, value));
601 scoped_ptr<SetCookieCallback> callback(
602 new SetCookieCallback(env, java_callback));
603 CookieManager::GetInstance()->SetCookie(host, cookie_value, callback.Pass());
604 }
473 605
474 CookieManager::GetInstance()->SetCookie(host, cookie_value); 606 static void SetCookieSync(JNIEnv* env,
607 jobject obj,
608 jstring url,
609 jstring value) {
610 GURL host(ConvertJavaStringToUTF16(env, url));
611 std::string cookie_value(ConvertJavaStringToUTF8(env, value));
612 CookieManager::GetInstance()->SetCookieSync(host, cookie_value);
475 } 613 }
476 614
477 static jstring GetCookie(JNIEnv* env, jobject obj, jstring url) { 615 static jstring GetCookie(JNIEnv* env, jobject obj, jstring url) {
478 GURL host(ConvertJavaStringToUTF16(env, url)); 616 GURL host(ConvertJavaStringToUTF16(env, url));
479 617
480 return base::android::ConvertUTF8ToJavaString( 618 return base::android::ConvertUTF8ToJavaString(
481 env, 619 env,
482 CookieManager::GetInstance()->GetCookie(host)).Release(); 620 CookieManager::GetInstance()->GetCookie(host)).Release();
483 } 621 }
484 622
485 static void RemoveSessionCookie(JNIEnv* env, jobject obj) { 623 static void RemoveSessionCookie(JNIEnv* env,
486 CookieManager::GetInstance()->RemoveSessionCookie(); 624 jobject obj,
625 jobject java_callback) {
626 scoped_ptr<RemoveCookiesCallback> callback(
627 new RemoveCookiesCallback(env, java_callback));
628 CookieManager::GetInstance()->RemoveSessionCookie(callback.Pass());
487 } 629 }
488 630
489 static void RemoveAllCookie(JNIEnv* env, jobject obj) { 631 static void RemoveSessionCookieSync(JNIEnv* env, jobject obj) {
490 CookieManager::GetInstance()->RemoveAllCookie(); 632 CookieManager::GetInstance()->RemoveSessionCookieSync();
633 }
634
635 static void RemoveAllCookie(JNIEnv* env, jobject obj, jobject java_callback) {
636 scoped_ptr<RemoveCookiesCallback> callback(
637 new RemoveCookiesCallback(env, java_callback));
638 CookieManager::GetInstance()->RemoveAllCookie(callback.Pass());
639 }
640
641 static void RemoveAllCookieSync(JNIEnv* env, jobject obj) {
642 CookieManager::GetInstance()->RemoveAllCookieSync();
491 } 643 }
492 644
493 static void RemoveExpiredCookie(JNIEnv* env, jobject obj) { 645 static void RemoveExpiredCookie(JNIEnv* env, jobject obj) {
494 CookieManager::GetInstance()->RemoveExpiredCookie(); 646 CookieManager::GetInstance()->RemoveExpiredCookie();
495 } 647 }
496 648
497 static void FlushCookieStore(JNIEnv* env, jobject obj) { 649 static void FlushCookieStore(JNIEnv* env, jobject obj) {
498 CookieManager::GetInstance()->FlushCookieStore(); 650 CookieManager::GetInstance()->FlushCookieStore();
499 } 651 }
500 652
(...skipping 14 matching lines...) Expand all
515 AwBrowserContext* browser_context) { 667 AwBrowserContext* browser_context) {
516 return CookieManager::GetInstance()->CreateBrowserThreadCookieStore( 668 return CookieManager::GetInstance()->CreateBrowserThreadCookieStore(
517 browser_context); 669 browser_context);
518 } 670 }
519 671
520 bool RegisterCookieManager(JNIEnv* env) { 672 bool RegisterCookieManager(JNIEnv* env) {
521 return RegisterNativesImpl(env); 673 return RegisterNativesImpl(env);
522 } 674 }
523 675
524 } // android_webview namespace 676 } // android_webview namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698