File: get_updates_processor.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 (105 lines) | stat: -rw-r--r-- 4,499 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_
#define COMPONENTS_SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "components/sync/base/data_type.h"
#include "components/sync/engine/data_type_registry.h"
#include "components/sync/engine/syncer_error.h"

namespace sync_pb {
class GetUpdatesResponse;
class ClientToServerMessage;
}  // namespace sync_pb

namespace syncer {

class GetUpdatesDelegate;
class StatusController;
class SyncCycle;

// This class manages the set of per-type syncer objects.
//
// It owns these types and hides the details of iterating over all of them.
// Most methods allow the caller to specify a subset of types on which the
// operation is to be applied.  It is a logic error if the supplied set of types
// contains a type which was not previously registered with the manager.
class GetUpdatesProcessor {
 public:
  explicit GetUpdatesProcessor(UpdateHandlerMap* update_handler_map,
                               const GetUpdatesDelegate& delegate);

  GetUpdatesProcessor(const GetUpdatesProcessor&) = delete;
  GetUpdatesProcessor& operator=(const GetUpdatesProcessor&) = delete;

  ~GetUpdatesProcessor();

  // Downloads and processes a batch of updates for the specified types.
  //
  // Returns SYNCER_OK if the download succeeds or an appropriate error value in
  // case of failure.
  SyncerError DownloadUpdates(DataTypeSet* request_types, SyncCycle* cycle);

  // Applies any downloaded and processed updates.
  void ApplyUpdates(const DataTypeSet& gu_types,
                    const DataTypeSet& data_types_with_failure,
                    StatusController* status_controller);

  // Records a download failure for the updated types.
  void RecordDownloadFailure(const DataTypeSet& gu_types,
                             UpdateHandler::NudgedUpdateResult failure_result);

  // Returns true if last DownloadUpdates() outcome indicated that there are
  // more updates to download from the server, e.g. when GetUpdatesResponse has
  // non-zero `changes_remaining`.
  bool HasMoreUpdatesToDownload() const;

 private:
  // Populates a GetUpdates request message with per-type information.
  void PrepareGetUpdates(const DataTypeSet& gu_types,
                         sync_pb::ClientToServerMessage* message);

  // Sends the specified message to the server and stores the response in a
  // member of the `cycle`'s StatusController.
  SyncerError ExecuteDownloadUpdates(DataTypeSet* request_types,
                                     SyncCycle* cycle,
                                     sync_pb::ClientToServerMessage* msg);

  // Processes a GetUpdates response for each type.
  SyncerError ProcessResponse(const sync_pb::GetUpdatesResponse& gu_response,
                              const DataTypeSet& gu_types,
                              StatusController* status_controller);

  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, BookmarkNudge);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NotifyNormalDelegate);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NotifyConfigureDelegate);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest,
                           NotifyPollGetUpdatesDelegate);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, InitialSyncRequest);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, ConfigureTest);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, PollTest);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, RetryTest);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NudgeWithRetryTest);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, InvalidResponse);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, MoreToDownloadResponse);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NormalResponseTest);

  // A map of 'update handlers', one for each enabled type.
  // This must be kept in sync with the routing info.  Our temporary solution to
  // that problem is to initialize this map in set_routing_info().
  const raw_ptr<UpdateHandlerMap> update_handler_map_;

  // Whether last GetUpdatesResponse has non-zero `changes_remaining`.
  bool has_more_updates_to_download_ = false;

  const raw_ref<const GetUpdatesDelegate> delegate_;
};

}  // namespace syncer

#endif  // COMPONENTS_SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_