clipboard_image_model_factory.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2020 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 ASH_PUBLIC_CPP_CLIPBOARD_IMAGE_MODEL_FACTORY_H_
  5. #define ASH_PUBLIC_CPP_CLIPBOARD_IMAGE_MODEL_FACTORY_H_
  6. #include <string>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/callback.h"
  9. #include "base/unguessable_token.h"
  10. #include "ui/base/models/image_model.h"
  11. namespace ui {
  12. class ImageModel;
  13. } // namespace ui
  14. namespace ash {
  15. // A factory implemented in the Browser with the primary profile which is
  16. // responsible for creating ui::ImageModels out of html strings from
  17. // ClipboardHistory to work around dependency restrictions in ash. This will not
  18. // create ImageModels until it is activated.
  19. class ASH_PUBLIC_EXPORT ClipboardImageModelFactory {
  20. public:
  21. // Returns the singleton factory instance.
  22. static ClipboardImageModelFactory* Get();
  23. using ImageModelCallback = base::OnceCallback<void(ui::ImageModel)>;
  24. // Asynchronously renders |html_markup|, identified by |id|. Later the
  25. // rendered html will be returned via |callback|, which is called as long as
  26. // the request is not canceled via CancelRequest. If the request times out, an
  27. // empty ImageModel will be passed through |callback|.
  28. virtual void Render(const base::UnguessableToken& id,
  29. const std::string& html_markup,
  30. const gfx::Size& bounding_box_size,
  31. ImageModelCallback callback) = 0;
  32. // Called to stop rendering which was requested with |id|.
  33. virtual void CancelRequest(const base::UnguessableToken& id) = 0;
  34. // Until Activate() is called, ClipboardImageModelFactory is in an inactive
  35. // state and all rendering requests will be queued until activated.
  36. virtual void Activate() = 0;
  37. // Called after Activate() to pause rendering requests. Rendering requests
  38. // will will continue until all requests are processed if
  39. // RenderCurrentPendingRequests() has been called.
  40. virtual void Deactivate() = 0;
  41. // Called to render all currently pending requests. This is called when the
  42. // virtual keyboard private api calls getClipboardHistory, so that clipboard
  43. // history items that are displayed will be rendered. Since there is no way to
  44. // track when the clipboard history is shown/hidden in the virtual keyboard,
  45. // this is called to ensure the current clipboard history is rendered.
  46. // Convenience function to `Activate()` until all requests are finished.
  47. virtual void RenderCurrentPendingRequests() = 0;
  48. // Called during shutdown to cleanup references to Profile.
  49. virtual void OnShutdown() = 0;
  50. protected:
  51. ClipboardImageModelFactory();
  52. virtual ~ClipboardImageModelFactory();
  53. };
  54. } // namespace ash
  55. #endif // ASH_PUBLIC_CPP_CLIPBOARD_IMAGE_MODEL_FACTORY_H_