instance_id_driver.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2015 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_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_DRIVER_H_
  5. #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_DRIVER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include "base/memory/raw_ptr.h"
  10. namespace gcm {
  11. class GCMDriver;
  12. } // namespace gcm
  13. namespace instance_id {
  14. class InstanceID;
  15. // Bridge between Instance ID users in Chrome and the platform-specific
  16. // implementation.
  17. //
  18. // Create instances of this class with |InstanceIDProfileServiceFactory|.
  19. class InstanceIDDriver {
  20. public:
  21. explicit InstanceIDDriver(gcm::GCMDriver* gcm_driver);
  22. InstanceIDDriver(const InstanceIDDriver&) = delete;
  23. InstanceIDDriver& operator=(const InstanceIDDriver&) = delete;
  24. virtual ~InstanceIDDriver();
  25. // Returns the InstanceID that provides the Instance ID service for the given
  26. // application. The lifetime of the InstanceID will be managed by this class.
  27. // App IDs are arbitrary strings that typically look like "chrome.foo.bar".
  28. virtual InstanceID* GetInstanceID(const std::string& app_id);
  29. // Removes the InstanceID when it is not longer needed, i.e. the app is being
  30. // uninstalled.
  31. virtual void RemoveInstanceID(const std::string& app_id);
  32. // Returns true if the InstanceID for the given application has been created.
  33. // This is currently only used for testing purpose.
  34. virtual bool ExistsInstanceID(const std::string& app_id) const;
  35. private:
  36. // Owned by GCMProfileServiceFactory, which is a dependency of
  37. // InstanceIDProfileServiceFactory, which owns this.
  38. raw_ptr<gcm::GCMDriver> gcm_driver_;
  39. std::map<std::string, std::unique_ptr<InstanceID>> instance_id_map_;
  40. };
  41. } // namespace instance_id
  42. #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_DRIVER_H_