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"; | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 namespace android_webview { | |
25 | |
26 AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path) | |
27 : completion_(false, false) { | |
benm (inactive)
2013/04/29 18:00:03
missing some members.
sgurun-gerrit only
2013/04/29 19:32:39
Done.
| |
28 | |
29 web_database_ = new WebDatabaseService(path.Append(kWebDataFilename)); | |
30 web_database_->AddTable( | |
31 scoped_ptr<WebDatabaseTable>(new autofill::AutofillTable( | |
32 l10n_util::GetDefaultLocale()))); | |
33 web_database_->LoadDatabase(WebDatabaseService::InitCallback()); | |
34 | |
35 autofill_data_ = new autofill::AutofillWebDataService( | |
36 web_database_, base::Bind(&DatabaseErrorCallback)); | |
37 autofill_data_->Init(); | |
38 } | |
39 | |
40 AwFormDatabaseService::~AwFormDatabaseService() { | |
41 CancelPendingQuery(); | |
42 } | |
43 | |
44 void AwFormDatabaseService::Shutdown() { | |
45 autofill_data_->ShutdownOnUIThread(); | |
46 web_database_->ShutdownDatabase(); | |
47 } | |
48 | |
49 void AwFormDatabaseService::CancelPendingQuery() { | |
50 if (pending_query_handle_) { | |
51 if (autofill_data_) | |
52 autofill_data_->CancelRequest(pending_query_handle_); | |
53 pending_query_handle_ = 0; | |
54 } | |
55 } | |
56 | |
57 scoped_refptr<autofill::AutofillWebDataService> | |
58 AwFormDatabaseService::get_autofill_webdata_service() { | |
59 return autofill_data_; | |
60 } | |
61 | |
62 bool AwFormDatabaseService::HasFormElements() { | |
63 | |
64 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
65 base::Bind(&AwFormDatabaseService::HasFormElementsImpl, | |
66 base::Unretained(this))); | |
67 completion_.Wait(); | |
68 return has_form_elements_; | |
69 } | |
70 | |
71 void AwFormDatabaseService::HasFormElementsImpl() { | |
72 | |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
74 has_form_elements_ = false; | |
75 pending_query_handle_ = autofill_data_->HasFormElements(this); | |
76 } | |
77 | |
78 | |
79 void AwFormDatabaseService::OnWebDataServiceRequestDone( | |
80 WebDataServiceBase::Handle h, | |
81 const WDTypedResult* result) { | |
82 | |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
84 DCHECK(pending_query_handle_); | |
85 pending_query_handle_ = 0; | |
86 | |
87 if (result) { | |
88 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); | |
89 const WDResult<bool>* autofill_result = | |
90 static_cast<const WDResult<bool>*>(result); | |
91 has_form_elements_ = autofill_result->GetValue(); | |
92 } | |
93 completion_.Signal(); | |
94 } | |
95 | |
96 } // namespace android_webview | |
OLD | NEW |