1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56

ash / webui / shortcut_customization_ui / shortcuts_app_manager_factory.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/webui/shortcut_customization_ui/shortcuts_app_manager_factory.h"
#include "ash/webui/shortcut_customization_ui/shortcuts_app_manager.h"
#include "chromeos/ash/components/local_search_service/public/cpp/local_search_service_proxy_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"

namespace ash::shortcut_ui {

// static
ShortcutsAppManager* ShortcutsAppManagerFactory::GetForBrowserContext(
    content::BrowserContext* context) {
  return static_cast<ShortcutsAppManager*>(
      ShortcutsAppManagerFactory::GetInstance()->GetServiceForBrowserContext(
          context, /*create=*/true));
}

// static
ShortcutsAppManagerFactory* ShortcutsAppManagerFactory::GetInstance() {
  return base::Singleton<ShortcutsAppManagerFactory>::get();
}

ShortcutsAppManagerFactory::ShortcutsAppManagerFactory()
    : BrowserContextKeyedServiceFactory(
          "ShortcutsAppManager",
          BrowserContextDependencyManager::GetInstance()) {
  DependsOn(
      local_search_service::LocalSearchServiceProxyFactory::GetInstance());
}

ShortcutsAppManagerFactory::~ShortcutsAppManagerFactory() = default;

content::BrowserContext* ShortcutsAppManagerFactory::GetBrowserContextToUse(
    content::BrowserContext* context) const {
  // The service should exist in incognito mode.
  return context;
}

std::unique_ptr<KeyedService>
ShortcutsAppManagerFactory::BuildServiceInstanceForBrowserContext(
    content::BrowserContext* context) const {
  return std::make_unique<ShortcutsAppManager>(
      local_search_service::LocalSearchServiceProxyFactory::
          GetForBrowserContext(context),
      user_prefs::UserPrefs::Get(context));
}

bool ShortcutsAppManagerFactory::ServiceIsNULLWhileTesting() const {
  return true;
}

}  // namespace ash::shortcut_ui