summaryrefslogtreecommitdiffstats
path: root/components/webdata_services
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2014-12-15 15:21:56 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-15 23:22:23 +0000
commitcb955cd06650ee281f745b5a86aff7864fe44066 (patch)
treed663541ca9f25582d5de09be3844285467d404dd /components/webdata_services
parent81c98ba5f74cbe9e6f1a12a0b96371b65dd4374e (diff)
downloadchromium_src-cb955cd06650ee281f745b5a86aff7864fe44066.zip
chromium_src-cb955cd06650ee281f745b5a86aff7864fe44066.tar.gz
chromium_src-cb955cd06650ee281f745b5a86aff7864fe44066.tar.bz2
Introduce new component webdata_services
Move WebDataServiceWrapper into its own component webdata_services so that the code can be shared with iOS. The code cannot go into webdata component since it depends on other components (autofill, password_manager, search_engine, signin) that depends on webdata (as they implements the WebDataService interface). BUG=437508 Review URL: https://codereview.chromium.org/777863002 Cr-Commit-Position: refs/heads/master@{#308451}
Diffstat (limited to 'components/webdata_services')
-rw-r--r--components/webdata_services/BUILD.gn38
-rw-r--r--components/webdata_services/DEPS10
-rw-r--r--components/webdata_services/OWNERS4
-rw-r--r--components/webdata_services/web_data_service_test_util.cc39
-rw-r--r--components/webdata_services/web_data_service_test_util.h48
-rw-r--r--components/webdata_services/web_data_service_wrapper.cc107
-rw-r--r--components/webdata_services/web_data_service_wrapper.h85
7 files changed, 331 insertions, 0 deletions
diff --git a/components/webdata_services/BUILD.gn b/components/webdata_services/BUILD.gn
new file mode 100644
index 0000000..8e83363
--- /dev/null
+++ b/components/webdata_services/BUILD.gn
@@ -0,0 +1,38 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+static_library("webdata_services") {
+ output_name = "webdata_services"
+
+ sources = [
+ "web_data_service_wrapper.cc",
+ "web_data_service_wrapper.h",
+ ]
+
+ deps = [
+ "//base",
+ "//components/autofill/core/browser",
+ "//components/keyed_service/core",
+ "//components/password_manager/core/browser",
+ "//components/search_engines",
+ "//components/signin/core/browser",
+ "//components/webdata/common",
+ "//sql",
+ ]
+}
+
+source_set("test_support") {
+ testonly = true
+ sources = [
+ "web_data_service_test_util.cc",
+ "web_data_service_test_util.h",
+ ]
+
+ deps = [
+ ":webdata_services",
+ "//base",
+ "//components/autofill/core/browser",
+ "//components/signin/core/browser",
+ ]
+}
diff --git a/components/webdata_services/DEPS b/components/webdata_services/DEPS
new file mode 100644
index 0000000..2fa1e61
--- /dev/null
+++ b/components/webdata_services/DEPS
@@ -0,0 +1,10 @@
+include_rules = [
+ "+components/autofill/core/browser/webdata",
+ "+components/keyed_service/core",
+ "+components/password_manager/core/browser/webdata",
+ "+components/search_engines/keyword_table.h",
+ "+components/search_engines/keyword_web_data_service.h",
+ "+components/signin/core/browser/webdata",
+ "+components/webdata/common",
+ "+sql",
+]
diff --git a/components/webdata_services/OWNERS b/components/webdata_services/OWNERS
new file mode 100644
index 0000000..dbe16c9
--- /dev/null
+++ b/components/webdata_services/OWNERS
@@ -0,0 +1,4 @@
+pkasting@chromium.org
+
+# For sqlite stuff:
+shess@chromium.org
diff --git a/components/webdata_services/web_data_service_test_util.cc b/components/webdata_services/web_data_service_test_util.cc
new file mode 100644
index 0000000..e013f32
--- /dev/null
+++ b/components/webdata_services/web_data_service_test_util.cc
@@ -0,0 +1,39 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/webdata_services/web_data_service_test_util.h"
+
+#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
+
+using autofill::AutofillWebDataService;
+
+MockWebDataServiceWrapperBase::MockWebDataServiceWrapperBase() {
+}
+
+MockWebDataServiceWrapperBase::~MockWebDataServiceWrapperBase() {
+}
+
+void MockWebDataServiceWrapperBase::Shutdown() {
+}
+
+// TODO(caitkp): This won't scale well. As we get more WebData subclasses, we
+// will probably need a better way to create these mocks rather than passing
+// all the webdatas in.
+MockWebDataServiceWrapper::MockWebDataServiceWrapper(
+ scoped_refptr<AutofillWebDataService> fake_autofill,
+ scoped_refptr<TokenWebData> fake_token)
+ : fake_autofill_web_data_(fake_autofill), fake_token_web_data_(fake_token) {
+}
+
+MockWebDataServiceWrapper::~MockWebDataServiceWrapper() {
+}
+
+scoped_refptr<AutofillWebDataService>
+MockWebDataServiceWrapper::GetAutofillWebData() {
+ return fake_autofill_web_data_;
+}
+
+scoped_refptr<TokenWebData> MockWebDataServiceWrapper::GetTokenWebData() {
+ return fake_token_web_data_;
+}
diff --git a/components/webdata_services/web_data_service_test_util.h b/components/webdata_services/web_data_service_test_util.h
new file mode 100644
index 0000000..4c260a1
--- /dev/null
+++ b/components/webdata_services/web_data_service_test_util.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_TEST_UTIL_H__
+#define COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_TEST_UTIL_H__
+
+#include "base/basictypes.h"
+#include "base/message_loop/message_loop.h"
+#include "components/signin/core/browser/webdata/token_web_data.h"
+#include "components/webdata_services/web_data_service_wrapper.h"
+
+// Base class for mocks of WebDataService, that does nothing in
+// Shutdown().
+class MockWebDataServiceWrapperBase : public WebDataServiceWrapper {
+ public:
+ MockWebDataServiceWrapperBase();
+ ~MockWebDataServiceWrapperBase() override;
+
+ void Shutdown() override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperBase);
+};
+
+// Pass your fake WebDataService in the constructor and this will
+// serve it up via GetWebData().
+class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase {
+ public:
+ MockWebDataServiceWrapper(
+ scoped_refptr<autofill::AutofillWebDataService> fake_autofill,
+ scoped_refptr<TokenWebData> fake_token);
+
+ ~MockWebDataServiceWrapper() override;
+
+ scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData() override;
+
+ scoped_refptr<TokenWebData> GetTokenWebData() override;
+
+ protected:
+ scoped_refptr<autofill::AutofillWebDataService> fake_autofill_web_data_;
+ scoped_refptr<TokenWebData> fake_token_web_data_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper);
+};
+
+#endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_TEST_UTIL_H__
diff --git a/components/webdata_services/web_data_service_wrapper.cc b/components/webdata_services/web_data_service_wrapper.cc
new file mode 100644
index 0000000..ca4287e
--- /dev/null
+++ b/components/webdata_services/web_data_service_wrapper.cc
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/webdata_services/web_data_service_wrapper.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "components/autofill/core/browser/webdata/autofill_table.h"
+#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
+#include "components/password_manager/core/browser/webdata/logins_table.h"
+#include "components/search_engines/keyword_table.h"
+#include "components/search_engines/keyword_web_data_service.h"
+#include "components/signin/core/browser/webdata/token_service_table.h"
+#include "components/signin/core/browser/webdata/token_web_data.h"
+#include "components/webdata/common/web_database_service.h"
+#include "components/webdata/common/webdata_constants.h"
+
+#if defined(OS_WIN)
+#include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
+#endif
+
+WebDataServiceWrapper::WebDataServiceWrapper() {
+}
+
+WebDataServiceWrapper::WebDataServiceWrapper(
+ const base::FilePath& profile_path,
+ const std::string& application_locale,
+ const scoped_refptr<base::MessageLoopProxy>& ui_thread,
+ const scoped_refptr<base::MessageLoopProxy>& db_thread,
+ ShowErrorCallback show_error_callback) {
+ base::FilePath path = profile_path.Append(kWebDataFilename);
+ web_database_ = new WebDatabaseService(path, ui_thread, db_thread);
+
+ // All tables objects that participate in managing the database must
+ // be added here.
+ web_database_->AddTable(scoped_ptr<WebDatabaseTable>(
+ new autofill::AutofillTable(application_locale)));
+ web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable()));
+ // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
+ // access, but for now, we still create it on all platforms since it deletes
+ // the old logins table. We can remove this after a while, e.g. in M22 or so.
+ web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new LoginsTable()));
+ web_database_->AddTable(
+ scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
+ web_database_->LoadDatabase();
+
+ autofill_web_data_ = new autofill::AutofillWebDataService(
+ web_database_, ui_thread, db_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_AUTOFILL));
+ autofill_web_data_->Init();
+
+ keyword_web_data_ = new KeywordWebDataService(
+ web_database_, ui_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_KEYWORD));
+ keyword_web_data_->Init();
+
+ token_web_data_ = new TokenWebData(
+ web_database_, ui_thread, db_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_TOKEN));
+ token_web_data_->Init();
+
+#if defined(OS_WIN)
+ password_web_data_ = new PasswordWebDataService(
+ web_database_, ui_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_PASSWORD));
+ password_web_data_->Init();
+#endif
+}
+
+WebDataServiceWrapper::~WebDataServiceWrapper() {
+}
+
+void WebDataServiceWrapper::Shutdown() {
+ autofill_web_data_->ShutdownOnUIThread();
+ keyword_web_data_->ShutdownOnUIThread();
+ token_web_data_->ShutdownOnUIThread();
+
+#if defined(OS_WIN)
+ password_web_data_->ShutdownOnUIThread();
+#endif
+
+ web_database_->ShutdownDatabase();
+}
+
+scoped_refptr<autofill::AutofillWebDataService>
+WebDataServiceWrapper::GetAutofillWebData() {
+ return autofill_web_data_.get();
+}
+
+scoped_refptr<KeywordWebDataService>
+WebDataServiceWrapper::GetKeywordWebData() {
+ return keyword_web_data_.get();
+}
+
+scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() {
+ return token_web_data_.get();
+}
+
+#if defined(OS_WIN)
+scoped_refptr<PasswordWebDataService>
+WebDataServiceWrapper::GetPasswordWebData() {
+ return password_web_data_.get();
+}
+#endif
diff --git a/components/webdata_services/web_data_service_wrapper.h b/components/webdata_services/web_data_service_wrapper.h
new file mode 100644
index 0000000..76f5693
--- /dev/null
+++ b/components/webdata_services/web_data_service_wrapper.h
@@ -0,0 +1,85 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_
+#define COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_
+
+#include <string>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "sql/init_status.h"
+
+class KeywordWebDataService;
+class TokenWebData;
+class WebDatabaseService;
+
+#if defined(OS_WIN)
+class PasswordWebDataService;
+#endif
+
+namespace autofill {
+class AutofillWebDataBackend;
+class AutofillWebDataService;
+} // namespace autofill
+
+namespace base {
+class FilePath;
+class MessageLoopProxy;
+} // namespace base
+
+// WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices
+// so that they can be associated with a context.
+class WebDataServiceWrapper : public KeyedService {
+ public:
+ // ErrorType indicates which service encountered an error loading its data.
+ enum ErrorType {
+ ERROR_LOADING_AUTOFILL,
+ ERROR_LOADING_KEYWORD,
+ ERROR_LOADING_TOKEN,
+ ERROR_LOADING_PASSWORD,
+ };
+
+ // Shows an error message if a loading error occurs.
+ using ShowErrorCallback = void (*)(ErrorType, sql::InitStatus);
+
+ WebDataServiceWrapper(const base::FilePath& profile_path,
+ const std::string& application_locale,
+ const scoped_refptr<base::MessageLoopProxy>& ui_thread,
+ const scoped_refptr<base::MessageLoopProxy>& db_thread,
+ ShowErrorCallback show_error_callback);
+ ~WebDataServiceWrapper() override;
+
+ // For testing.
+ WebDataServiceWrapper();
+
+ // KeyedService:
+ void Shutdown() override;
+
+ // Create the various types of service instances. These methods are virtual
+ // for testing purpose.
+ virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData();
+ virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData();
+ virtual scoped_refptr<TokenWebData> GetTokenWebData();
+#if defined(OS_WIN)
+ virtual scoped_refptr<PasswordWebDataService> GetPasswordWebData();
+#endif
+
+ private:
+ scoped_refptr<WebDatabaseService> web_database_;
+
+ scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_;
+ scoped_refptr<KeywordWebDataService> keyword_web_data_;
+ scoped_refptr<TokenWebData> token_web_data_;
+
+#if defined(OS_WIN)
+ scoped_refptr<PasswordWebDataService> password_web_data_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
+};
+
+#endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_