bookmark_sync_service.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2018 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_SYNC_BOOKMARKS_BOOKMARK_SYNC_SERVICE_H_
  5. #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SYNC_SERVICE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/sequence_checker.h"
  11. #include "components/keyed_service/core/keyed_service.h"
  12. class BookmarkUndoService;
  13. namespace syncer {
  14. class ModelTypeControllerDelegate;
  15. }
  16. namespace bookmarks {
  17. class BookmarkModel;
  18. }
  19. namespace favicon {
  20. class FaviconService;
  21. }
  22. namespace sync_bookmarks {
  23. class BookmarkModelTypeProcessor;
  24. // This service owns the BookmarkModelTypeProcessor.
  25. class BookmarkSyncService : public KeyedService {
  26. public:
  27. // |bookmark_undo_service| must not be null and must outlive this object.
  28. explicit BookmarkSyncService(BookmarkUndoService* bookmark_undo_service);
  29. BookmarkSyncService(const BookmarkSyncService&) = delete;
  30. BookmarkSyncService& operator=(const BookmarkSyncService&) = delete;
  31. // KeyedService implemenation.
  32. ~BookmarkSyncService() override;
  33. // Analgous to Encode/Decode methods in BookmarkClient.
  34. std::string EncodeBookmarkSyncMetadata();
  35. void DecodeBookmarkSyncMetadata(
  36. const std::string& metadata_str,
  37. const base::RepeatingClosure& schedule_save_closure,
  38. bookmarks::BookmarkModel* model);
  39. // Returns the ModelTypeControllerDelegate for syncer::BOOKMARKS.
  40. // |favicon_service| is the favicon service used when processing updates in
  41. // the underlying processor. It could have been a separate a setter in
  42. // BookmarkSyncService instead of passing it as a parameter to
  43. // GetBookmarkSyncControllerDelegate(). However, this would incur the risk of
  44. // overlooking setting it. Therefore, it has been added as a parameter to the
  45. // GetBookmarkSyncControllerDelegate() in order to gauarantee it will be set
  46. // before the processor starts receiving updates.
  47. virtual base::WeakPtr<syncer::ModelTypeControllerDelegate>
  48. GetBookmarkSyncControllerDelegate(favicon::FaviconService* favicon_service);
  49. private:
  50. // BookmarkModelTypeProcessor handles communications between sync engine and
  51. // BookmarkModel/HistoryService.
  52. std::unique_ptr<sync_bookmarks::BookmarkModelTypeProcessor>
  53. bookmark_model_type_processor_;
  54. };
  55. } // namespace sync_bookmarks
  56. #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SYNC_SERVICE_H_