| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
| 6 #include "base/android/jni_string.h" | 6 #include "base/android/jni_string.h" |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "chrome/browser/android/cookies/cookies_fetcher.h" | 9 #include "chrome/browser/android/cookies/cookies_fetcher.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 jobject_.Reset(env, obj); | 42 jobject_.Reset(env, obj); |
| 43 | 43 |
| 44 // The rest must be done from the IO thread. | 44 // The rest must be done from the IO thread. |
| 45 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 45 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 46 base::Bind(&CookiesFetcher::PersistCookiesInternal, | 46 base::Bind(&CookiesFetcher::PersistCookiesInternal, |
| 47 base::Unretained(this), getter)); | 47 base::Unretained(this), getter)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void CookiesFetcher::PersistCookiesInternal( | 50 void CookiesFetcher::PersistCookiesInternal( |
| 51 net::URLRequestContextGetter* getter) { | 51 net::URLRequestContextGetter* getter) { |
| 52 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 52 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 53 | 53 |
| 54 net::CookieStore* store = getter->GetURLRequestContext()->cookie_store(); | 54 net::CookieStore* store = getter->GetURLRequestContext()->cookie_store(); |
| 55 | 55 |
| 56 // Nullable sometimes according to docs. There is no work need to be done | 56 // Nullable sometimes according to docs. There is no work need to be done |
| 57 // but we can consider calling the Java callback with empty output. | 57 // but we can consider calling the Java callback with empty output. |
| 58 if (!store) { | 58 if (!store) { |
| 59 jobject_.Reset(); | 59 jobject_.Reset(); |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 | 62 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FROM_HERE, | 135 FROM_HERE, |
| 136 base::Bind(&CookiesFetcher::RestoreToCookieJarInternal, | 136 base::Bind(&CookiesFetcher::RestoreToCookieJarInternal, |
| 137 base::Unretained(this), | 137 base::Unretained(this), |
| 138 getter, | 138 getter, |
| 139 cookie)); | 139 cookie)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void CookiesFetcher::RestoreToCookieJarInternal( | 142 void CookiesFetcher::RestoreToCookieJarInternal( |
| 143 net::URLRequestContextGetter* getter, | 143 net::URLRequestContextGetter* getter, |
| 144 const net::CanonicalCookie& cookie) { | 144 const net::CanonicalCookie& cookie) { |
| 145 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 145 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 146 | 146 |
| 147 net::CookieStore* store = getter->GetURLRequestContext()->cookie_store(); | 147 net::CookieStore* store = getter->GetURLRequestContext()->cookie_store(); |
| 148 | 148 |
| 149 // Nullable sometimes according to docs. | 149 // Nullable sometimes according to docs. |
| 150 if (!store) { | 150 if (!store) { |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 net::CookieMonster* monster = store->GetCookieMonster(); | 154 net::CookieMonster* monster = store->GetCookieMonster(); |
| 155 base::Callback<void(bool success)> cb; | 155 base::Callback<void(bool success)> cb; |
| 156 | 156 |
| 157 monster->SetCookieWithDetailsAsync( | 157 monster->SetCookieWithDetailsAsync( |
| 158 GURL(cookie.Source()), cookie.Name(), cookie.Value(), cookie.Domain(), | 158 GURL(cookie.Source()), cookie.Name(), cookie.Value(), cookie.Domain(), |
| 159 cookie.Path(), cookie.ExpiryDate(), cookie.IsSecure(), | 159 cookie.Path(), cookie.ExpiryDate(), cookie.IsSecure(), |
| 160 cookie.IsHttpOnly(), cookie.IsFirstPartyOnly(), cookie.Priority(), cb); | 160 cookie.IsHttpOnly(), cookie.IsFirstPartyOnly(), cookie.Priority(), cb); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // JNI functions | 163 // JNI functions |
| 164 static jlong Init(JNIEnv* env, jobject obj) { | 164 static jlong Init(JNIEnv* env, jobject obj) { |
| 165 return reinterpret_cast<intptr_t>(new CookiesFetcher(env, obj, 0)); | 165 return reinterpret_cast<intptr_t>(new CookiesFetcher(env, obj, 0)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Register native methods | 168 // Register native methods |
| 169 bool RegisterCookiesFetcher(JNIEnv* env) { | 169 bool RegisterCookiesFetcher(JNIEnv* env) { |
| 170 return RegisterNativesImpl(env); | 170 return RegisterNativesImpl(env); |
| 171 } | 171 } |
| OLD | NEW |