web_data_service_factory.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2021 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. #include "weblayer/browser/web_data_service_factory.h"
  5. #include "base/bind.h"
  6. #include "base/files/file_path.h"
  7. #include "base/no_destructor.h"
  8. #include "base/notreached.h"
  9. #include "components/webdata_services/web_data_service_wrapper.h"
  10. #include "content/public/browser/browser_context.h"
  11. #include "content/public/browser/browser_task_traits.h"
  12. #include "content/public/browser/browser_thread.h"
  13. #include "weblayer/browser/i18n_util.h"
  14. namespace weblayer {
  15. namespace {
  16. // Callback to show error dialog on profile load error.
  17. void ProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
  18. sql::InitStatus status,
  19. const std::string& diagnostics) {
  20. NOTIMPLEMENTED();
  21. }
  22. } // namespace
  23. WebDataServiceFactory::WebDataServiceFactory() = default;
  24. WebDataServiceFactory::~WebDataServiceFactory() = default;
  25. // static
  26. WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
  27. static base::NoDestructor<WebDataServiceFactory> instance;
  28. return instance.get();
  29. }
  30. content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse(
  31. content::BrowserContext* context) const {
  32. return context;
  33. }
  34. KeyedService* WebDataServiceFactory::BuildServiceInstanceFor(
  35. content::BrowserContext* context) const {
  36. const base::FilePath& profile_path = context->GetPath();
  37. return new WebDataServiceWrapper(profile_path, i18n::GetApplicationLocale(),
  38. content::GetUIThreadTaskRunner({}),
  39. base::BindRepeating(&ProfileErrorCallback));
  40. }
  41. bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
  42. return true;
  43. }
  44. } // namespace weblayer