Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "android_webview/browser/aw_form_database_service.h" | |
| 6 #include "base/logging.h" | |
| 7 #include "components/autofill/browser/webdata/autofill_table.h" | |
| 8 #include "components/webdata/common/webdata_constants.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "ui/base/l10n/l10n_util_android.h" | |
| 11 | |
| 12 using content::BrowserThread; | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Callback to handle database error. It seems chrome uses this to | |
| 17 // display an error dialog box only. | |
| 18 void DatabaseErrorCallback(sql::InitStatus status) { | |
| 19 LOG(WARNING) << "initializing autocomplete database failed"; | |
|
benm (inactive)
2013/05/07 11:16:11
Does the caller of this function then disable auto
sgurun-gerrit only
2013/05/07 18:39:02
On 2013/05/07 11:16:11, benm wrote:
> Does the cal
sgurun-gerrit only
2013/05/07 18:39:02
the webdata service backend does not issue any que
| |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace android_webview { | |
| 25 | |
| 26 AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path) | |
| 27 : pending_query_handle_(0), | |
| 28 has_form_elements_(0), | |
|
benm (inactive)
2013/05/07 11:16:11
0 -> false
sgurun-gerrit only
2013/05/07 18:39:02
Done.
| |
| 29 completion_(false, false) { | |
| 30 | |
| 31 web_database_ = new WebDatabaseService(path.Append(kWebDataFilename)); | |
| 32 web_database_->AddTable( | |
|
benm (inactive)
2013/05/07 11:16:11
Do we need to do this every time that we instantia
sgurun-gerrit only
2013/05/07 18:39:02
I think the issue is that there are lots of abstra
| |
| 33 scoped_ptr<WebDatabaseTable>(new autofill::AutofillTable( | |
| 34 l10n_util::GetDefaultLocale()))); | |
| 35 web_database_->LoadDatabase(); | |
| 36 | |
| 37 autofill_data_ = new autofill::AutofillWebDataService( | |
| 38 web_database_, base::Bind(&DatabaseErrorCallback)); | |
| 39 autofill_data_->Init(); | |
| 40 } | |
| 41 | |
| 42 AwFormDatabaseService::~AwFormDatabaseService() { | |
| 43 CancelPendingQuery(); | |
|
benm (inactive)
2013/05/07 11:16:11
Shutdown() too?
sgurun-gerrit only
2013/05/07 18:41:59
Done.
| |
| 44 } | |
| 45 | |
| 46 void AwFormDatabaseService::Shutdown() { | |
| 47 autofill_data_->ShutdownOnUIThread(); | |
|
benm (inactive)
2013/05/07 11:16:11
DCHECK that we're on the UI thread.
sgurun-gerrit only
2013/05/07 18:39:02
Done.
| |
| 48 web_database_->ShutdownDatabase(); | |
| 49 } | |
| 50 | |
| 51 void AwFormDatabaseService::CancelPendingQuery() { | |
| 52 if (pending_query_handle_) { | |
| 53 if (autofill_data_) | |
| 54 autofill_data_->CancelRequest(pending_query_handle_); | |
| 55 pending_query_handle_ = 0; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 scoped_refptr<autofill::AutofillWebDataService> | |
| 60 AwFormDatabaseService::get_autofill_webdata_service() { | |
| 61 return autofill_data_; | |
| 62 } | |
| 63 | |
| 64 void AwFormDatabaseService::ClearFormElements() { | |
| 65 | |
|
benm (inactive)
2013/05/07 11:16:11
nit: remove \n (and throughout)
sgurun-gerrit only
2013/05/07 18:39:02
Done.
| |
| 66 base::Time begin; | |
| 67 base::Time end = base::Time::Max(); | |
| 68 autofill_data_->RemoveFormElementsAddedBetween(begin, end); | |
| 69 autofill_data_->RemoveAutofillDataModifiedBetween(begin, end); | |
| 70 } | |
| 71 | |
| 72 bool AwFormDatabaseService::HasFormElements() { | |
| 73 | |
| 74 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 75 base::Bind(&AwFormDatabaseService::HasFormElementsImpl, | |
| 76 base::Unretained(this))); | |
| 77 completion_.Wait(); | |
| 78 return has_form_elements_; | |
| 79 } | |
| 80 | |
| 81 void AwFormDatabaseService::HasFormElementsImpl() { | |
| 82 | |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 84 has_form_elements_ = false; | |
| 85 pending_query_handle_ = autofill_data_->HasFormElements(this); | |
| 86 } | |
| 87 | |
| 88 | |
| 89 void AwFormDatabaseService::OnWebDataServiceRequestDone( | |
| 90 WebDataServiceBase::Handle h, | |
| 91 const WDTypedResult* result) { | |
| 92 | |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 94 DCHECK_EQ(pending_query_handle_, h); | |
| 95 pending_query_handle_ = 0; | |
| 96 | |
| 97 if (result) { | |
| 98 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); | |
| 99 const WDResult<bool>* autofill_result = | |
| 100 static_cast<const WDResult<bool>*>(result); | |
| 101 has_form_elements_ = autofill_result->GetValue(); | |
| 102 } | |
| 103 completion_.Signal(); | |
| 104 } | |
| 105 | |
| 106 } // namespace android_webview | |
| OLD | NEW |