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

Side by Side Diff: android_webview/browser/aw_form_database_service.cc

Issue 23803005: Fix threading issues in aw form database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/browser/aw_form_database_service.h" 5 #include "android_webview/browser/aw_form_database_service.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "components/autofill/core/browser/webdata/autofill_table.h" 7 #include "components/autofill/core/browser/webdata/autofill_table.h"
8 #include "components/webdata/common/webdata_constants.h" 8 #include "components/webdata/common/webdata_constants.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "ui/base/l10n/l10n_util_android.h" 10 #include "ui/base/l10n/l10n_util_android.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 pending_query_handle_ = 0; 59 pending_query_handle_ = 0;
60 } 60 }
61 } 61 }
62 62
63 scoped_refptr<autofill::AutofillWebDataService> 63 scoped_refptr<autofill::AutofillWebDataService>
64 AwFormDatabaseService::get_autofill_webdata_service() { 64 AwFormDatabaseService::get_autofill_webdata_service() {
65 return autofill_data_; 65 return autofill_data_;
66 } 66 }
67 67
68 void AwFormDatabaseService::ClearFormData() { 68 void AwFormDatabaseService::ClearFormData() {
69 base::AutoLock lock(lock_);
joth 2013/09/05 00:59:10 I don't understand what problem this lock is solvi
70 // TODO(sgurun) investigate if it is better to do on DB thread
71 BrowserThread::PostTask(
72 BrowserThread::UI,
73 FROM_HERE,
74 base::Bind(&AwFormDatabaseService::ClearFormDataLocked,
75 base::Unretained(this)));
76 }
77
78 void AwFormDatabaseService::ClearFormDataLocked() {
69 base::Time begin; 79 base::Time begin;
70 base::Time end = base::Time::Max(); 80 base::Time end = base::Time::Max();
71 autofill_data_->RemoveFormElementsAddedBetween(begin, end); 81 autofill_data_->RemoveFormElementsAddedBetween(begin, end);
72 autofill_data_->RemoveAutofillDataModifiedBetween(begin, end); 82 autofill_data_->RemoveAutofillDataModifiedBetween(begin, end);
73 } 83 }
74 84
75 bool AwFormDatabaseService::HasFormData() { 85 bool AwFormDatabaseService::HasFormData() {
76 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 86 base::AutoLock lock(lock_);
77 base::Bind(&AwFormDatabaseService::HasFormDataImpl, 87 // TODO(sgurun) investigate if it is better to do on DB thread
joth 2013/09/05 00:59:10 I can answer this: it's *definitely* better done o
88 BrowserThread::PostTask(
89 BrowserThread::UI,
90 FROM_HERE,
91 base::Bind(&AwFormDatabaseService::HasFormDataLocked,
78 base::Unretained(this))); 92 base::Unretained(this)));
93 // TODO(sgurun) Could be unnecessarily blocking UI thread
79 completion_.Wait(); 94 completion_.Wait();
80 return has_form_data_; 95 return has_form_data_;
81 } 96 }
82 97
83 void AwFormDatabaseService::HasFormDataImpl() { 98 void AwFormDatabaseService::HasFormDataLocked() {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
85 pending_query_handle_ = autofill_data_->HasFormElements(this); 99 pending_query_handle_ = autofill_data_->HasFormElements(this);
86 } 100 }
87 101
88 102
89 void AwFormDatabaseService::OnWebDataServiceRequestDone( 103 void AwFormDatabaseService::OnWebDataServiceRequestDone(
90 WebDataServiceBase::Handle h, 104 WebDataServiceBase::Handle h,
91 const WDTypedResult* result) { 105 const WDTypedResult* result) {
92 106
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
94 DCHECK_EQ(pending_query_handle_, h); 108 DCHECK_EQ(pending_query_handle_, h);
95 pending_query_handle_ = 0; 109 pending_query_handle_ = 0;
96 has_form_data_ = false; 110 has_form_data_ = false;
97 111
98 if (result) { 112 if (result) {
99 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); 113 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
100 const WDResult<bool>* autofill_result = 114 const WDResult<bool>* autofill_result =
101 static_cast<const WDResult<bool>*>(result); 115 static_cast<const WDResult<bool>*>(result);
102 has_form_data_ = autofill_result->GetValue(); 116 has_form_data_ = autofill_result->GetValue();
103 } 117 }
104 completion_.Signal(); 118 completion_.Signal();
105 } 119 }
106 120
107 } // namespace android_webview 121 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698