logo_service.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2014 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. #ifndef COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_SERVICE_H_
  5. #define COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_SERVICE_H_
  6. #include "components/keyed_service/core/keyed_service.h"
  7. #include "components/search_provider_logos/logo_common.h"
  8. namespace search_provider_logos {
  9. class LogoObserver;
  10. // Provides the logo for a profile's default search provider.
  11. //
  12. // Example usage:
  13. // LogoService* logo_service = LogoServiceFactory::GetForProfile(profile);
  14. // LogoCallbacks callbacks;
  15. // callbacks.on_cached_decoded_logo = base::BindOnce(ShowLogo);
  16. // callbacks.on_fresh_decoded_logo = base::BindOnce(FadeToLogo);
  17. // logo_service->GetLogo(callbacks);
  18. //
  19. class LogoService : public KeyedService {
  20. public:
  21. LogoService(const LogoService&) = delete;
  22. LogoService& operator=(const LogoService&) = delete;
  23. // Gets the logo for the default search provider and calls the provided
  24. // callbacks with the encoded and decoded logos. The service will:
  25. //
  26. // 1. Load a cached logo, and call callbacks.on_cached_{en,de}coded_logo.
  27. // 2. Fetch a fresh logo, and call callbacks.on_fresh_{en,de}coded_logo.
  28. //
  29. // At least one member of |callbacks| must be non-null. If |for_webui_ntp| is
  30. // true fetches a logo that is compatible with the WebUI NTP.
  31. virtual void GetLogo(LogoCallbacks callbacks, bool for_webui_ntp) = 0;
  32. // Gets the logo for the default search provider and notifies |observer|
  33. // 0-2 times with the results. The service will:
  34. //
  35. // 1. Call observer->OnLogoAvailable() with |from_cache=true| when
  36. // |on_cached_decoded_logo_available| would be called in the callback
  37. // interface with type DETERMINED.
  38. // 2. Call observer->OnLogoAvailable() with |from_cache=false| when
  39. // |on_fresh_decoded_logo_available| would be called in the callback
  40. // interface with type DETERMINED.
  41. // 3. Call observer->OnObserverRemoved().
  42. virtual void GetLogo(LogoObserver* observer) = 0;
  43. protected:
  44. LogoService();
  45. };
  46. } // namespace search_provider_logos
  47. #endif // COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_SERVICE_H_