File: get_updates_processor.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (105 lines) | stat: -rw-r--r-- 4,442 bytes parent folder | download
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. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_
#define COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_

#include <map>
#include <vector>

#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "components/sync/base/model_type.h"
#include "components/sync/engine/model_safe_worker.h"
#include "components/sync/engine_impl/model_type_registry.h"
#include "components/sync/protocol/sync.pb.h"

namespace sync_pb {
class GetUpdatesResponse;
}  // namespace sync_pb

namespace syncer {

class DebugInfoGetter;
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();

  // Downloads and processes a batch of updates for the specified types.
  //
  // Returns SYNCER_OK if the download succeeds, SERVER_MORE_TO_DOWNLOAD if the
  // download succeeded but there are still some updates left to fetch on the
  // server, or an appropriate error value in case of failure.
  SyncerError DownloadUpdates(ModelTypeSet* request_types,
                              SyncCycle* cycle,
                              bool create_mobile_bookmarks_folder);

  // Applies any downloaded and processed updates.
  void ApplyUpdates(ModelTypeSet gu_types, StatusController* status_controller);

 private:
  // Populates a GetUpdates request message with per-type information.
  void PrepareGetUpdates(ModelTypeSet 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(ModelTypeSet* request_types,
                                     SyncCycle* cycle,
                                     sync_pb::ClientToServerMessage* msg);

  // Helper function for processing responses from the server.  Defined here for
  // testing.
  SyncerError ProcessResponse(const sync_pb::GetUpdatesResponse& gu_response,
                              ModelTypeSet proto_request_types,
                              StatusController* status);

  // Processes a GetUpdates responses for each type.
  SyncerError ProcessGetUpdatesResponse(
      ModelTypeSet gu_types,
      const sync_pb::GetUpdatesResponse& gu_response,
      StatusController* status_controller);

  static void CopyClientDebugInfo(DebugInfoGetter* debug_info_getter,
                                  sync_pb::DebugInfo* debug_info);

  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, BookmarkNudge);
  FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NotifyMany);
  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);
  FRIEND_TEST_ALL_PREFIXES(DownloadUpdatesDebugInfoTest,
                           VerifyCopyClientDebugInfo_Empty);
  FRIEND_TEST_ALL_PREFIXES(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites);

  // 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().
  UpdateHandlerMap* update_handler_map_;

  const GetUpdatesDelegate& delegate_;

  DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessor);
};

}  // namespace syncer

#endif  // COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_