session_sync_service_impl.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_SESSIONS_SESSION_SYNC_SERVICE_IMPL_H_
  5. #define COMPONENTS_SYNC_SESSIONS_SESSION_SYNC_SERVICE_IMPL_H_
  6. #include <memory>
  7. #include "base/callback_list.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "components/sync/model/model_type_store.h"
  10. #include "components/sync_sessions/session_sync_service.h"
  11. #include "components/version_info/channel.h"
  12. namespace sync_sessions {
  13. class SessionSyncBridge;
  14. class SyncSessionsClient;
  15. // Single non-test implementation of SessionSyncService.
  16. class SessionSyncServiceImpl : public SessionSyncService {
  17. public:
  18. SessionSyncServiceImpl(version_info::Channel channel,
  19. std::unique_ptr<SyncSessionsClient> sessions_client);
  20. SessionSyncServiceImpl(const SessionSyncServiceImpl&) = delete;
  21. SessionSyncServiceImpl& operator=(const SessionSyncServiceImpl&) = delete;
  22. ~SessionSyncServiceImpl() override;
  23. syncer::GlobalIdMapper* GetGlobalIdMapper() const override;
  24. // Return the active OpenTabsUIDelegate. If open/proxy tabs is not enabled or
  25. // not currently syncing, returns nullptr.
  26. OpenTabsUIDelegate* GetOpenTabsUIDelegate() override;
  27. // Allows client code to be notified when foreign sessions change.
  28. [[nodiscard]] base::CallbackListSubscription
  29. SubscribeToForeignSessionsChanged(const base::RepeatingClosure& cb) override;
  30. base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate()
  31. override;
  32. // Intended to be used by ProxyDataTypeController: influences whether
  33. // GetOpenTabsUIDelegate() returns null or not.
  34. void ProxyTabsStateChanged(syncer::DataTypeController::State state) override;
  35. // Returns OpenTabsUIDelegate regardless of sync being enabled or disabled,
  36. // useful for tests.
  37. OpenTabsUIDelegate* GetUnderlyingOpenTabsUIDelegateForTest();
  38. private:
  39. void NotifyForeignSessionUpdated();
  40. std::unique_ptr<SyncSessionsClient> sessions_client_;
  41. bool proxy_tabs_running_ = false;
  42. std::unique_ptr<SessionSyncBridge> bridge_;
  43. base::RepeatingClosureList foreign_sessions_changed_closure_list_;
  44. };
  45. } // namespace sync_sessions
  46. #endif // COMPONENTS_SYNC_SESSIONS_SESSION_SYNC_SERVICE_IMPL_H_