PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/browser/api/networking_private/networking_private_delegate_factory.h

https://gitlab.com/0072016/Facebook-SDK-
C Header | 88 lines | 57 code | 20 blank | 11 comment | 1 complexity | 4d81e374cf3db7d82f338097805240e9 MD5 | raw file
  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 EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_FACTORY_H_
  5. #define EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_FACTORY_H_
  6. #include "base/macros.h"
  7. #include "base/memory/scoped_ptr.h"
  8. #include "base/memory/singleton.h"
  9. #include "build/build_config.h"
  10. #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
  11. #include "extensions/browser/api/networking_private/networking_private_delegate.h"
  12. namespace context {
  13. class BrowserContext;
  14. }
  15. namespace extensions {
  16. #if defined(OS_WIN) || defined(OS_MACOSX)
  17. class NetworkingPrivateServiceClient;
  18. #endif
  19. // Factory for creating NetworkingPrivateDelegate instances as a keyed service.
  20. // NetworkingPrivateDelegate supports the networkingPrivate API.
  21. class NetworkingPrivateDelegateFactory
  22. : public BrowserContextKeyedServiceFactory {
  23. public:
  24. // There needs to be a way to allow the application (e.g. Chrome) to provide
  25. // additional delegates to the API (in src/extensions). Since this factory is
  26. // already a singleton, it provides a good place to hold these delegate
  27. // factories. See NetworkingPrivateDelegate for the delegate declarations.
  28. class VerifyDelegateFactory {
  29. public:
  30. VerifyDelegateFactory();
  31. virtual ~VerifyDelegateFactory();
  32. virtual scoped_ptr<NetworkingPrivateDelegate::VerifyDelegate>
  33. CreateDelegate() = 0;
  34. private:
  35. DISALLOW_COPY_AND_ASSIGN(VerifyDelegateFactory);
  36. };
  37. class UIDelegateFactory {
  38. public:
  39. UIDelegateFactory();
  40. virtual ~UIDelegateFactory();
  41. virtual scoped_ptr<NetworkingPrivateDelegate::UIDelegate>
  42. CreateDelegate() = 0;
  43. private:
  44. DISALLOW_COPY_AND_ASSIGN(UIDelegateFactory);
  45. };
  46. // Provide optional factories for creating delegate instances.
  47. void SetVerifyDelegateFactory(scoped_ptr<VerifyDelegateFactory> factory);
  48. void SetUIDelegateFactory(scoped_ptr<UIDelegateFactory> factory);
  49. static NetworkingPrivateDelegate* GetForBrowserContext(
  50. content::BrowserContext* browser_context);
  51. static NetworkingPrivateDelegateFactory* GetInstance();
  52. private:
  53. friend struct base::DefaultSingletonTraits<NetworkingPrivateDelegateFactory>;
  54. NetworkingPrivateDelegateFactory();
  55. ~NetworkingPrivateDelegateFactory() override;
  56. // BrowserContextKeyedServiceFactory:
  57. KeyedService* BuildServiceInstanceFor(
  58. content::BrowserContext* browser_context) const override;
  59. content::BrowserContext* GetBrowserContextToUse(
  60. content::BrowserContext* context) const override;
  61. bool ServiceIsCreatedWithBrowserContext() const override;
  62. bool ServiceIsNULLWhileTesting() const override;
  63. scoped_ptr<VerifyDelegateFactory> verify_factory_;
  64. scoped_ptr<UIDelegateFactory> ui_factory_;
  65. DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDelegateFactory);
  66. };
  67. } // namespace extensions
  68. #endif // EXTENSIONS_BROWSER_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_DELEGATE_FACTORY_H_