send_tab_to_self_model_bridge_observer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 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_SEND_TAB_TO_SELF_IOS_SEND_TAB_TO_SELF_MODEL_BRIDGE_OBSERVER_H_
  5. #define COMPONENTS_SEND_TAB_TO_SELF_IOS_SEND_TAB_TO_SELF_MODEL_BRIDGE_OBSERVER_H_
  6. #import <Foundation/Foundation.h>
  7. #include "components/send_tab_to_self/send_tab_to_self_model.h"
  8. #include "components/send_tab_to_self/send_tab_to_self_model_observer.h"
  9. // Protocol forwarding all Send Tab To Self Model Observer methods in
  10. // Objective-C.
  11. @protocol SendTabToSelfModelBridgeObserver <NSObject>
  12. @required
  13. - (void)sendTabToSelfModelLoaded:(send_tab_to_self::SendTabToSelfModel*)model;
  14. - (void)sendTabToSelfModel:(send_tab_to_self::SendTabToSelfModel*)model
  15. didAddEntriesRemotely:
  16. (const std::vector<const send_tab_to_self::SendTabToSelfEntry*>&)
  17. new_entries;
  18. // The Entry has already been deleted at this point and the guid cannot be used
  19. // to access the old entry via SendTabToSelfModel::GetEntryByGUID.
  20. - (void)sendTabToSelfModel:(send_tab_to_self::SendTabToSelfModel*)model
  21. didRemoveEntriesRemotely:(const std::vector<std::string>&)guids;
  22. @end
  23. namespace send_tab_to_self {
  24. // Observer for the Send Tab To Self model that translates all the callbacks to
  25. // Objective-C calls.
  26. class SendTabToSelfModelBridge : public SendTabToSelfModelObserver {
  27. public:
  28. // It is required that |model| should be non-null. If |observer| is nil this
  29. // class will result in all no-ops.
  30. explicit SendTabToSelfModelBridge(
  31. id<SendTabToSelfModelBridgeObserver> observer,
  32. SendTabToSelfModel* model);
  33. SendTabToSelfModelBridge(const SendTabToSelfModelBridge&) = delete;
  34. SendTabToSelfModelBridge& operator=(const SendTabToSelfModelBridge&) = delete;
  35. ~SendTabToSelfModelBridge() override;
  36. private:
  37. void SendTabToSelfModelLoaded() override;
  38. void EntriesAddedRemotely(
  39. const std::vector<const SendTabToSelfEntry*>&) override;
  40. void EntriesRemovedRemotely(const std::vector<std::string>&) override;
  41. __weak id<SendTabToSelfModelBridgeObserver> observer_;
  42. SendTabToSelfModel* model_; // weak
  43. };
  44. } // namespace send_tab_to_self
  45. #endif // COMPONENTS_SEND_TAB_TO_SELF_IOS_SEND_TAB_TO_SELF_MODEL_BRIDGE_OBSERVER_H_