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