Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / sync / engine / get_updates_processor.h
blob934c3f14991d375082ecdda0e0ff661fe9083aa7
1 // Copyright 2014 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.
5 #ifndef SYNC_ENGINE_GET_UPDATES_PROCESSOR_H
6 #define SYNC_ENGINE_GET_UPDATES_PROCESSOR_H
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "sync/base/sync_export.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/engine/model_safe_worker.h"
16 #include "sync/protocol/sync.pb.h"
17 #include "sync/sessions/model_type_registry.h"
19 namespace sync_pb {
20 class GetUpdatesMessage;
21 class GetUpdatesResponse;
22 } // namespace sync_pb
24 namespace syncer {
26 namespace sessions {
27 class StatusController;
28 class SyncSession;
29 class SyncSessionContext;
30 class DebugInfoGetter;
31 } // namespace sessions
33 namespace syncable {
34 class Directory;
35 } // namespace syncable
37 class GetUpdatesDelegate;
39 // This class manages the set of per-type syncer objects.
41 // It owns these types and hides the details of iterating over all of them.
42 // Most methods allow the caller to specify a subset of types on which the
43 // operation is to be applied. It is a logic error if the supplied set of types
44 // contains a type which was not previously registered with the manager.
45 class SYNC_EXPORT_PRIVATE GetUpdatesProcessor {
46 public:
47 explicit GetUpdatesProcessor(UpdateHandlerMap* update_handler_map,
48 const GetUpdatesDelegate& delegate);
49 ~GetUpdatesProcessor();
51 // Downloads and processes a batch of updates for the specified types.
53 // Returns SYNCER_OK if the download succeeds, SERVER_MORE_TO_DOWNLOAD if the
54 // download succeeded but there are still some updates left to fetch on the
55 // server, or an appropriate error value in case of failure.
56 SyncerError DownloadUpdates(
57 ModelTypeSet* request_types,
58 sessions::SyncSession* session,
59 bool create_mobile_bookmarks_folder);
61 // Applies any downloaded and processed updates.
62 void ApplyUpdates(
63 ModelTypeSet gu_types,
64 sessions::StatusController* status_controller);
66 private:
67 // Populates a GetUpdates request message with per-type information.
68 void PrepareGetUpdates(
69 ModelTypeSet gu_types,
70 sync_pb::ClientToServerMessage* message);
72 // Sends the specified message to the server and stores the response in a
73 // member of the |session|'s StatusController.
74 SyncerError ExecuteDownloadUpdates(ModelTypeSet* request_types,
75 sessions::SyncSession* session,
76 sync_pb::ClientToServerMessage* msg);
78 // Helper function for processing responses from the server. Defined here for
79 // testing.
80 SyncerError ProcessResponse(const sync_pb::GetUpdatesResponse& gu_response,
81 ModelTypeSet proto_request_types,
82 sessions::StatusController* status);
84 // Processes a GetUpdates responses for each type.
85 syncer::SyncerError ProcessGetUpdatesResponse(
86 ModelTypeSet gu_types,
87 const sync_pb::GetUpdatesResponse& gu_response,
88 sessions::StatusController* status_controller);
90 static void CopyClientDebugInfo(
91 sessions::DebugInfoGetter* debug_info_getter,
92 sync_pb::DebugInfo* debug_info);
94 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, BookmarkNudge);
95 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NotifyMany);
96 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, InitialSyncRequest);
97 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, ConfigureTest);
98 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, PollTest);
99 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, RetryTest);
100 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NudgeWithRetryTest);
101 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, InvalidResponse);
102 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, MoreToDownloadResponse);
103 FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NormalResponseTest);
104 FRIEND_TEST_ALL_PREFIXES(DownloadUpdatesDebugInfoTest,
105 VerifyCopyClientDebugInfo_Empty);
106 FRIEND_TEST_ALL_PREFIXES(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites);
108 // A map of 'update handlers', one for each enabled type.
109 // This must be kept in sync with the routing info. Our temporary solution to
110 // that problem is to initialize this map in set_routing_info().
111 UpdateHandlerMap* update_handler_map_;
113 const GetUpdatesDelegate& delegate_;
115 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessor);
118 } // namespace syncer
120 #endif // SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_