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

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

Issue 2812703003: aw: Remove global AllowWait on UI thread (Closed)
Patch Set: future Created 3 years, 8 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
« no previous file with comments | « android_webview/lib/main/aw_main_delegate.cc ('k') | base/threading/thread_restrictions.h » ('j') | 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) 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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "android_webview/browser/aw_browser_context.h" 11 #include "android_webview/browser/aw_browser_context.h"
12 #include "android_webview/browser/aw_cookie_access_policy.h" 12 #include "android_webview/browser/aw_cookie_access_policy.h"
13 #include "android_webview/browser/net/init_native_callback.h" 13 #include "android_webview/browser/net/init_native_callback.h"
14 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
15 #include "base/android/jni_string.h" 14 #include "base/android/jni_string.h"
16 #include "base/android/path_utils.h" 15 #include "base/android/path_utils.h"
17 #include "base/bind.h" 16 #include "base/bind.h"
18 #include "base/bind_helpers.h" 17 #include "base/bind_helpers.h"
19 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
20 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
21 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
22 #include "base/location.h" 21 #include "base/location.h"
23 #include "base/logging.h" 22 #include "base/logging.h"
24 #include "base/memory/ref_counted.h" 23 #include "base/memory/ref_counted.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 << cookie_store_path.AsUTF8Unsafe(); 140 << cookie_store_path.AsUTF8Unsafe();
142 } 141 }
143 } 142 }
144 143
145 void GetUserDataDir(FilePath* user_data_dir) { 144 void GetUserDataDir(FilePath* user_data_dir) {
146 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, user_data_dir)) { 145 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, user_data_dir)) {
147 NOTREACHED() << "Failed to get app data directory for Android WebView"; 146 NOTREACHED() << "Failed to get app data directory for Android WebView";
148 } 147 }
149 } 148 }
150 149
150 } // namespace
151
151 // CookieManager creates and owns Webview's CookieStore, in addition to handling 152 // CookieManager creates and owns Webview's CookieStore, in addition to handling
152 // calls into the CookieStore from Java. 153 // calls into the CookieStore from Java.
153 // 154 //
154 // Since Java calls can be made on the IO Thread, and must synchronously return 155 // Since Java calls can be made on the IO Thread, and must synchronously return
155 // a result, and the CookieStore API allows it to asynchronously return results, 156 // a result, and the CookieStore API allows it to asynchronously return results,
156 // the CookieStore must be run on its own thread, to prevent deadlock. 157 // the CookieStore must be run on its own thread, to prevent deadlock.
157 class CookieManager { 158 class CookieManager {
158 public: 159 public:
159 static CookieManager* GetInstance(); 160 static CookieManager* GetInstance();
160 161
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 226
226 base::Thread cookie_store_client_thread_; 227 base::Thread cookie_store_client_thread_;
227 base::Thread cookie_store_backend_thread_; 228 base::Thread cookie_store_backend_thread_;
228 229
229 scoped_refptr<base::SingleThreadTaskRunner> cookie_store_task_runner_; 230 scoped_refptr<base::SingleThreadTaskRunner> cookie_store_task_runner_;
230 std::unique_ptr<net::CookieStore> cookie_store_; 231 std::unique_ptr<net::CookieStore> cookie_store_;
231 232
232 DISALLOW_COPY_AND_ASSIGN(CookieManager); 233 DISALLOW_COPY_AND_ASSIGN(CookieManager);
233 }; 234 };
234 235
236 namespace {
235 base::LazyInstance<CookieManager>::Leaky g_lazy_instance; 237 base::LazyInstance<CookieManager>::Leaky g_lazy_instance;
236 238 }
237 } // namespace
238 239
239 // static 240 // static
240 CookieManager* CookieManager::GetInstance() { 241 CookieManager* CookieManager::GetInstance() {
241 return g_lazy_instance.Pointer(); 242 return g_lazy_instance.Pointer();
242 } 243 }
243 244
244 CookieManager::CookieManager() 245 CookieManager::CookieManager()
245 : accept_file_scheme_cookies_(kDefaultFileSchemeAllowed), 246 : accept_file_scheme_cookies_(kDefaultFileSchemeAllowed),
246 cookie_store_created_(false), 247 cookie_store_created_(false),
247 cookie_store_client_thread_("CookieMonsterClient"), 248 cookie_store_client_thread_("CookieMonsterClient"),
(...skipping 16 matching lines...) Expand all
264 // Alternatively you can call the version which supplies a Closure in which 265 // Alternatively you can call the version which supplies a Closure in which
265 // case you must call Run on it when you want the unblock the calling code. 266 // case you must call Run on it when you want the unblock the calling code.
266 // 267 //
267 // Ignore a bool callback. 268 // Ignore a bool callback.
268 void CookieManager::ExecCookieTaskSync( 269 void CookieManager::ExecCookieTaskSync(
269 const base::Callback<void(BoolCallback)>& task) { 270 const base::Callback<void(BoolCallback)>& task) {
270 WaitableEvent completion(base::WaitableEvent::ResetPolicy::AUTOMATIC, 271 WaitableEvent completion(base::WaitableEvent::ResetPolicy::AUTOMATIC,
271 base::WaitableEvent::InitialState::NOT_SIGNALED); 272 base::WaitableEvent::InitialState::NOT_SIGNALED);
272 ExecCookieTask( 273 ExecCookieTask(
273 base::Bind(task, BoolCallbackAdapter(SignalEventClosure(&completion)))); 274 base::Bind(task, BoolCallbackAdapter(SignalEventClosure(&completion))));
274 ScopedAllowWaitForLegacyWebViewApi wait; 275 base::ThreadRestrictions::ScopedAllowWait wait;
275 completion.Wait(); 276 completion.Wait();
276 } 277 }
277 278
278 // Ignore an int callback. 279 // Ignore an int callback.
279 void CookieManager::ExecCookieTaskSync( 280 void CookieManager::ExecCookieTaskSync(
280 const base::Callback<void(IntCallback)>& task) { 281 const base::Callback<void(IntCallback)>& task) {
281 WaitableEvent completion(base::WaitableEvent::ResetPolicy::AUTOMATIC, 282 WaitableEvent completion(base::WaitableEvent::ResetPolicy::AUTOMATIC,
282 base::WaitableEvent::InitialState::NOT_SIGNALED); 283 base::WaitableEvent::InitialState::NOT_SIGNALED);
283 ExecCookieTask( 284 ExecCookieTask(
284 base::Bind(task, IntCallbackAdapter(SignalEventClosure(&completion)))); 285 base::Bind(task, IntCallbackAdapter(SignalEventClosure(&completion))));
285 ScopedAllowWaitForLegacyWebViewApi wait; 286 base::ThreadRestrictions::ScopedAllowWait wait;
286 completion.Wait(); 287 completion.Wait();
287 } 288 }
288 289
289 // Call the supplied closure when you want to signal that the blocked code can 290 // Call the supplied closure when you want to signal that the blocked code can
290 // continue. 291 // continue.
291 void CookieManager::ExecCookieTaskSync( 292 void CookieManager::ExecCookieTaskSync(
292 const base::Callback<void(base::Closure)>& task) { 293 const base::Callback<void(base::Closure)>& task) {
293 WaitableEvent completion(base::WaitableEvent::ResetPolicy::AUTOMATIC, 294 WaitableEvent completion(base::WaitableEvent::ResetPolicy::AUTOMATIC,
294 base::WaitableEvent::InitialState::NOT_SIGNALED); 295 base::WaitableEvent::InitialState::NOT_SIGNALED);
295 ExecCookieTask(base::Bind(task, SignalEventClosure(&completion))); 296 ExecCookieTask(base::Bind(task, SignalEventClosure(&completion)));
296 ScopedAllowWaitForLegacyWebViewApi wait; 297 base::ThreadRestrictions::ScopedAllowWait wait;
297 completion.Wait(); 298 completion.Wait();
298 } 299 }
299 300
300 // Executes the |task| using |cookie_store_task_runner_|. 301 // Executes the |task| using |cookie_store_task_runner_|.
301 void CookieManager::ExecCookieTask(const base::Closure& task) { 302 void CookieManager::ExecCookieTask(const base::Closure& task) {
302 cookie_store_task_runner_->PostTask(FROM_HERE, task); 303 cookie_store_task_runner_->PostTask(FROM_HERE, task);
303 } 304 }
304 305
305 base::SingleThreadTaskRunner* CookieManager::GetCookieStoreTaskRunner() { 306 base::SingleThreadTaskRunner* CookieManager::GetCookieStoreTaskRunner() {
306 return cookie_store_task_runner_.get(); 307 return cookie_store_task_runner_.get();
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 630
630 net::CookieStore* GetCookieStore() { 631 net::CookieStore* GetCookieStore() {
631 return CookieManager::GetInstance()->GetCookieStore(); 632 return CookieManager::GetInstance()->GetCookieStore();
632 } 633 }
633 634
634 bool RegisterCookieManager(JNIEnv* env) { 635 bool RegisterCookieManager(JNIEnv* env) {
635 return RegisterNativesImpl(env); 636 return RegisterNativesImpl(env);
636 } 637 }
637 638
638 } // android_webview namespace 639 } // android_webview namespace
OLDNEW
« no previous file with comments | « android_webview/lib/main/aw_main_delegate.cc ('k') | base/threading/thread_restrictions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698