Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: sync/engine/get_updates_delegate.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/engine/get_updates_delegate.h ('k') | sync/engine/get_updates_processor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "sync/engine/get_updates_delegate.h"
6
7 #include "sync/engine/directory_update_handler.h"
8 #include "sync/engine/get_updates_processor.h"
9 #include "sync/internal_api/public/events/configure_get_updates_request_event.h"
10 #include "sync/internal_api/public/events/normal_get_updates_request_event.h"
11 #include "sync/internal_api/public/events/poll_get_updates_request_event.h"
12
13 namespace syncer {
14
15 namespace {
16
17 void NonPassiveApplyUpdates(
18 ModelTypeSet gu_types,
19 sessions::StatusController* status_controller,
20 UpdateHandlerMap* update_handler_map) {
21 for (UpdateHandlerMap::iterator it = update_handler_map->begin();
22 it != update_handler_map->end(); ++it) {
23 if (gu_types.Has(it->first))
24 it->second->ApplyUpdates(status_controller);
25 }
26 }
27
28 void PassiveApplyUpdates(
29 ModelTypeSet gu_types,
30 sessions::StatusController* status_controller,
31 UpdateHandlerMap* update_handler_map) {
32 for (UpdateHandlerMap::iterator it = update_handler_map->begin();
33 it != update_handler_map->end(); ++it) {
34 if (gu_types.Has(it->first))
35 it->second->PassiveApplyUpdates(status_controller);
36 }
37 }
38
39 } // namespace
40
41 GetUpdatesDelegate::GetUpdatesDelegate() {}
42
43 GetUpdatesDelegate::~GetUpdatesDelegate() {}
44
45 NormalGetUpdatesDelegate::NormalGetUpdatesDelegate(
46 const sessions::NudgeTracker& nudge_tracker)
47 : nudge_tracker_(nudge_tracker) {}
48
49 NormalGetUpdatesDelegate::~NormalGetUpdatesDelegate() {}
50
51 // This function assumes the progress markers have already been populated.
52 void NormalGetUpdatesDelegate::HelpPopulateGuMessage(
53 sync_pb::GetUpdatesMessage* get_updates) const {
54 // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
55 get_updates->mutable_caller_info()->set_source(
56 nudge_tracker_.GetLegacySource());
57
58 // Set the new and improved version of source, too.
59 get_updates->set_get_updates_origin(sync_pb::SyncEnums::GU_TRIGGER);
60 get_updates->set_is_retry(nudge_tracker_.IsRetryRequired());
61
62 // Special case: A GU performed for no other reason than retry will have its
63 // origin set to RETRY.
64 if (nudge_tracker_.GetLegacySource() == sync_pb::GetUpdatesCallerInfo::RETRY)
65 get_updates->set_get_updates_origin(sync_pb::SyncEnums::RETRY);
66
67 // Fill in the notification hints.
68 for (int i = 0; i < get_updates->from_progress_marker_size(); ++i) {
69 sync_pb::DataTypeProgressMarker* progress_marker =
70 get_updates->mutable_from_progress_marker(i);
71 ModelType type = GetModelTypeFromSpecificsFieldNumber(
72 progress_marker->data_type_id());
73
74 DCHECK(!nudge_tracker_.IsTypeThrottled(type))
75 << "Throttled types should have been removed from the request_types.";
76
77 nudge_tracker_.SetLegacyNotificationHint(type, progress_marker);
78 nudge_tracker_.FillProtoMessage(
79 type,
80 progress_marker->mutable_get_update_triggers());
81 }
82 }
83
84 void NormalGetUpdatesDelegate::ApplyUpdates(
85 ModelTypeSet gu_types,
86 sessions::StatusController* status_controller,
87 UpdateHandlerMap* update_handler_map) const {
88 NonPassiveApplyUpdates(gu_types, status_controller, update_handler_map);
89 }
90
91 std::unique_ptr<ProtocolEvent> NormalGetUpdatesDelegate::GetNetworkRequestEvent(
92 base::Time timestamp,
93 const sync_pb::ClientToServerMessage& request) const {
94 return std::unique_ptr<ProtocolEvent>(
95 new NormalGetUpdatesRequestEvent(timestamp, nudge_tracker_, request));
96 }
97
98 ConfigureGetUpdatesDelegate::ConfigureGetUpdatesDelegate(
99 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) : source_(source) {}
100
101 ConfigureGetUpdatesDelegate::~ConfigureGetUpdatesDelegate() {}
102
103 void ConfigureGetUpdatesDelegate::HelpPopulateGuMessage(
104 sync_pb::GetUpdatesMessage* get_updates) const {
105 get_updates->mutable_caller_info()->set_source(source_);
106 get_updates->set_get_updates_origin(ConvertConfigureSourceToOrigin(source_));
107 }
108
109 void ConfigureGetUpdatesDelegate::ApplyUpdates(
110 ModelTypeSet gu_types,
111 sessions::StatusController* status_controller,
112 UpdateHandlerMap* update_handler_map) const {
113 PassiveApplyUpdates(gu_types, status_controller, update_handler_map);
114 }
115
116 std::unique_ptr<ProtocolEvent>
117 ConfigureGetUpdatesDelegate::GetNetworkRequestEvent(
118 base::Time timestamp,
119 const sync_pb::ClientToServerMessage& request) const {
120 return std::unique_ptr<ProtocolEvent>(new ConfigureGetUpdatesRequestEvent(
121 timestamp, ConvertConfigureSourceToOrigin(source_), request));
122 }
123
124 sync_pb::SyncEnums::GetUpdatesOrigin
125 ConfigureGetUpdatesDelegate::ConvertConfigureSourceToOrigin(
126 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
127 switch (source) {
128 // Configurations:
129 case sync_pb::GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE:
130 return sync_pb::SyncEnums::NEWLY_SUPPORTED_DATATYPE;
131 case sync_pb::GetUpdatesCallerInfo::MIGRATION:
132 return sync_pb::SyncEnums::MIGRATION;
133 case sync_pb::GetUpdatesCallerInfo::RECONFIGURATION:
134 return sync_pb::SyncEnums::RECONFIGURATION;
135 case sync_pb::GetUpdatesCallerInfo::NEW_CLIENT:
136 return sync_pb::SyncEnums::NEW_CLIENT;
137 case sync_pb::GetUpdatesCallerInfo::PROGRAMMATIC:
138 return sync_pb::SyncEnums::PROGRAMMATIC;
139 default:
140 NOTREACHED();
141 return sync_pb::SyncEnums::UNKNOWN_ORIGIN;
142 }
143 }
144
145 PollGetUpdatesDelegate::PollGetUpdatesDelegate() {}
146
147 PollGetUpdatesDelegate::~PollGetUpdatesDelegate() {}
148
149 void PollGetUpdatesDelegate::HelpPopulateGuMessage(
150 sync_pb::GetUpdatesMessage* get_updates) const {
151 // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
152 get_updates->mutable_caller_info()->set_source(
153 sync_pb::GetUpdatesCallerInfo::PERIODIC);
154
155 // Set the new and improved version of source, too.
156 get_updates->set_get_updates_origin(sync_pb::SyncEnums::PERIODIC);
157 }
158
159 void PollGetUpdatesDelegate::ApplyUpdates(
160 ModelTypeSet gu_types,
161 sessions::StatusController* status_controller,
162 UpdateHandlerMap* update_handler_map) const {
163 NonPassiveApplyUpdates(gu_types, status_controller, update_handler_map);
164 }
165
166 std::unique_ptr<ProtocolEvent> PollGetUpdatesDelegate::GetNetworkRequestEvent(
167 base::Time timestamp,
168 const sync_pb::ClientToServerMessage& request) const {
169 return std::unique_ptr<ProtocolEvent>(
170 new PollGetUpdatesRequestEvent(timestamp, request));
171 }
172
173 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/get_updates_delegate.h ('k') | sync/engine/get_updates_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698