File: fake_server_sync_invalidation_sender.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 3,543 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_INVALIDATIONS_FAKE_SERVER_SYNC_INVALIDATION_SENDER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_INVALIDATIONS_FAKE_SERVER_SYNC_INVALIDATION_SENDER_H_

#include "base/memory/raw_ptr.h"
#include "components/gcm_driver/gcm_connection_observer.h"
#include "components/sync/base/data_type.h"
#include "components/sync/protocol/sync_invalidations_payload.pb.h"
#include "components/sync/test/fake_server.h"

namespace instance_id {
class FakeGCMDriverForInstanceID;
}  // namespace instance_id

namespace fake_server {

// This class is observing changes to the fake server, and sends invalidations
// to clients upon commits. Sent invalidation follows the same format expected
// by the sync invalidations framework (i.e. SyncInvalidationsService).
class FakeServerSyncInvalidationSender : public FakeServer::Observer,
                                         public gcm::GCMConnectionObserver {
 public:
  // This has the same value as in
  // components/sync/invalidations/sync_invalidations_service_impl.cc.
  static constexpr char kSyncInvalidationsAppId[] =
      "com.google.chrome.sync.invalidations";

  // |fake_server| must not be nullptr, and must outlive this object.
  explicit FakeServerSyncInvalidationSender(FakeServer* fake_server);
  ~FakeServerSyncInvalidationSender() override;
  FakeServerSyncInvalidationSender(const FakeServerSyncInvalidationSender&) =
      delete;
  FakeServerSyncInvalidationSender& operator=(
      const FakeServerSyncInvalidationSender&) = delete;

  // Add |fake_gcm_driver| to send invalidations to from the fake server.
  void AddFakeGCMDriver(
      instance_id::FakeGCMDriverForInstanceID* fake_gcm_driver);

  // Remove |fake_gcm_driver| to stop sending invalidations.
  void RemoveFakeGCMDriver(
      instance_id::FakeGCMDriverForInstanceID* fake_gcm_driver);

  // FakeServer::Observer implementation.
  void OnWillCommit() override;
  void OnCommit(syncer::DataTypeSet committed_data_types) override;

  // gcm::GCMConnectionObserver implementation.
  void OnConnected(const net::IPEndPoint& ip_endpoint) override;

 private:
  instance_id::FakeGCMDriverForInstanceID* GetFakeGCMDriverByToken(
      const std::string& fcm_registration_token) const;

  // Delivers all the incoming messages to the corresponding FCM handlers.
  // Messages for FCM tokens which are not registered will be kept.
  void DeliverInvalidationsToHandlers();

  // Updates |token_to_interested_data_types_map_before_commit_| from DeviceInfo
  // data type.
  void UpdateTokenToInterestedDataTypesMap();

  const raw_ptr<FakeServer> fake_server_;

  // Cache of invalidations to be dispatched by
  // DeliverInvalidationsToHandlers(), keyed by FCM registration token. If no
  // handler is registered for a token, then the corresponding invalidations
  // will remain here until a handler is added.
  std::map<std::string, std::vector<sync_pb::SyncInvalidationsPayload>>
      invalidations_to_deliver_;

  // List of tokens with a list of interested data types. Used to send
  // invalidations to a corresponding client.
  std::map<std::string, syncer::DataTypeSet> token_to_interested_data_types_;

  std::vector<raw_ptr<instance_id::FakeGCMDriverForInstanceID>>
      fake_gcm_drivers_;
};

}  // namespace fake_server

#endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_INVALIDATIONS_FAKE_SERVER_SYNC_INVALIDATION_SENDER_H_