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

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

Issue 14963002: sync: Report GetUpdate triggers to the server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix handling of NEW_CLIENT GU source Created 7 years, 7 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 | « no previous file | sync/engine/download_updates_command_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #include "sync/engine/download_updates_command.h" 5 #include "sync/engine/download_updates_command.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "sync/engine/syncer.h" 10 #include "sync/engine/syncer.h"
11 #include "sync/engine/syncer_proto_util.h" 11 #include "sync/engine/syncer_proto_util.h"
12 #include "sync/internal_api/public/base/model_type_invalidation_map.h" 12 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
13 #include "sync/sessions/nudge_tracker.h"
13 #include "sync/syncable/directory.h" 14 #include "sync/syncable/directory.h"
14 #include "sync/syncable/nigori_handler.h" 15 #include "sync/syncable/nigori_handler.h"
15 #include "sync/syncable/syncable_read_transaction.h" 16 #include "sync/syncable/syncable_read_transaction.h"
16 17
17 using sync_pb::DebugInfo; 18 using sync_pb::DebugInfo;
18 19
19 namespace syncer { 20 namespace syncer {
20 using sessions::StatusController; 21 using sessions::StatusController;
21 using sessions::SyncSession; 22 using sessions::SyncSession;
22 using std::string; 23 using std::string;
(...skipping 20 matching lines...) Expand all
43 update_response.get_updates().encryption_keys(), 44 update_response.get_updates().encryption_keys(),
44 &trans); 45 &trans);
45 46
46 DVLOG(1) << "GetUpdates returned " 47 DVLOG(1) << "GetUpdates returned "
47 << update_response.get_updates().encryption_keys_size() 48 << update_response.get_updates().encryption_keys_size()
48 << "encryption keys. Nigori keystore key " 49 << "encryption keys. Nigori keystore key "
49 << (success ? "" : "not ") << "updated."; 50 << (success ? "" : "not ") << "updated.";
50 return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED); 51 return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED);
51 } 52 }
52 53
54 sync_pb::SyncEnums::GetUpdatesOrigin ConvertGetUpdateSourceToOrigin(
55 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
56 switch (source) {
57 // Configurations:
58 case sync_pb::GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE:
59 return sync_pb::SyncEnums::NEWLY_SUPPORTED_DATATYPE;
60 case sync_pb::GetUpdatesCallerInfo::MIGRATION:
61 return sync_pb::SyncEnums::MIGRATION;
62 case sync_pb::GetUpdatesCallerInfo::RECONFIGURATION:
63 return sync_pb::SyncEnums::RECONFIGURATION;
64 case sync_pb::GetUpdatesCallerInfo::NEW_CLIENT:
65 return sync_pb::SyncEnums::NEW_CLIENT;
66
67 // Poll, which never overlaps with anything else:
68 case sync_pb::GetUpdatesCallerInfo::PERIODIC:
69 return sync_pb::SyncEnums::PERIODIC;
70
71 // Overlapping normal-mode sources (fall-through is intentional):
72 case sync_pb::GetUpdatesCallerInfo::LOCAL:
73 case sync_pb::GetUpdatesCallerInfo::NOTIFICATION:
74 case sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH:
75 return sync_pb::SyncEnums::GU_TRIGGER;
76
77 // Deprecated or invalid (fall-through is intentional):
78 case sync_pb::GetUpdatesCallerInfo::UNKNOWN:
79 case sync_pb::GetUpdatesCallerInfo::FIRST_UPDATE:
80 case sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION:
81 NOTREACHED() << "Invalid source: " << source;
82 return sync_pb::SyncEnums::UNKNOWN_ORIGIN;
83 }
84 NOTREACHED();
85 return sync_pb::SyncEnums::UNKNOWN_ORIGIN;
86 }
87
53 } // namespace 88 } // namespace
54 89
55 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { 90 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
56 sync_pb::ClientToServerMessage client_to_server_message; 91 sync_pb::ClientToServerMessage client_to_server_message;
57 sync_pb::ClientToServerResponse update_response; 92 sync_pb::ClientToServerResponse update_response;
58 93
59 client_to_server_message.set_share(session->context()->account_name()); 94 client_to_server_message.set_share(session->context()->account_name());
60 client_to_server_message.set_message_contents( 95 client_to_server_message.set_message_contents(
61 sync_pb::ClientToServerMessage::GET_UPDATES); 96 sync_pb::ClientToServerMessage::GET_UPDATES);
62 sync_pb::GetUpdatesMessage* get_updates = 97 sync_pb::GetUpdatesMessage* get_updates =
63 client_to_server_message.mutable_get_updates(); 98 client_to_server_message.mutable_get_updates();
64 get_updates->set_create_mobile_bookmarks_folder( 99 get_updates->set_create_mobile_bookmarks_folder(
65 create_mobile_bookmarks_folder_); 100 create_mobile_bookmarks_folder_);
66 101
102 sync_pb::SyncEnums::GetUpdatesOrigin origin =
103 ConvertGetUpdateSourceToOrigin(session->source().updates_source);
104
67 syncable::Directory* dir = session->context()->directory(); 105 syncable::Directory* dir = session->context()->directory();
68 106
69 // Request updates for all enabled types. 107 // Request updates for all enabled types.
70 const ModelTypeSet enabled_types = 108 const ModelTypeSet enabled_types =
71 GetRoutingInfoTypes(session->context()->routing_info()); 109 GetRoutingInfoTypes(session->context()->routing_info());
72 DVLOG(1) << "Getting updates for types " 110 DVLOG(1) << "Getting updates for types "
73 << ModelTypeSetToString(enabled_types); 111 << ModelTypeSetToString(enabled_types);
74 DCHECK(!enabled_types.Empty()); 112 DCHECK(!enabled_types.Empty());
75 113
76 const ModelTypeInvalidationMap& invalidation_map = 114 const ModelTypeInvalidationMap& invalidation_map =
77 session->source().types; 115 session->source().types;
78 for (ModelTypeSet::Iterator it = enabled_types.First(); 116 for (ModelTypeSet::Iterator it = enabled_types.First();
79 it.Good(); it.Inc()) { 117 it.Good(); it.Inc()) {
80 if (ProxyTypes().Has(it.Get())) 118 if (ProxyTypes().Has(it.Get()))
81 continue; 119 continue;
82 sync_pb::DataTypeProgressMarker* progress_marker = 120 sync_pb::DataTypeProgressMarker* progress_marker =
83 get_updates->add_from_progress_marker(); 121 get_updates->add_from_progress_marker();
84 dir->GetDownloadProgress(it.Get(), progress_marker); 122 dir->GetDownloadProgress(it.Get(), progress_marker);
85 123
86 // Set notification hint if present. 124 // Set notification hint if present.
87 ModelTypeInvalidationMap::const_iterator find_it = 125 ModelTypeInvalidationMap::const_iterator find_it =
88 invalidation_map.find(it.Get()); 126 invalidation_map.find(it.Get());
89 if (find_it != invalidation_map.end()) { 127 if (find_it != invalidation_map.end()) {
90 progress_marker->set_notification_hint(find_it->second.payload); 128 progress_marker->set_notification_hint(find_it->second.payload);
91 } 129 }
130
131 if (origin == sync_pb::SyncEnums::GU_TRIGGER) {
132 session->nudge_tracker()->FillProtoMessage(
133 it.Get(),
134 progress_marker->mutable_get_update_triggers());
135 } else {
136 DCHECK(!session->nudge_tracker());
137 }
92 } 138 }
93 139
94 bool need_encryption_key = false; 140 bool need_encryption_key = false;
95 if (session->context()->keystore_encryption_enabled()) { 141 if (session->context()->keystore_encryption_enabled()) {
96 syncable::Directory* dir = session->context()->directory(); 142 syncable::Directory* dir = session->context()->directory();
97 syncable::ReadTransaction trans(FROM_HERE, dir); 143 syncable::ReadTransaction trans(FROM_HERE, dir);
98 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler(); 144 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler();
99 need_encryption_key = nigori_handler->NeedKeystoreKey(&trans); 145 need_encryption_key = nigori_handler->NeedKeystoreKey(&trans);
100 get_updates->set_need_encryption_key(need_encryption_key); 146 get_updates->set_need_encryption_key(need_encryption_key);
101 147
102 } 148 }
103 149
104 // We want folders for our associated types, always. If we were to set 150 // We want folders for our associated types, always. If we were to set
105 // this to false, the server would send just the non-container items 151 // this to false, the server would send just the non-container items
106 // (e.g. Bookmark URLs but not their containing folders). 152 // (e.g. Bookmark URLs but not their containing folders).
107 get_updates->set_fetch_folders(true); 153 get_updates->set_fetch_folders(true);
108 154
109 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. 155 // Set GetUpdatesMessage.GetUpdatesCallerInfo information.
110 get_updates->mutable_caller_info()->set_source( 156 get_updates->mutable_caller_info()->set_source(
111 session->source().updates_source); 157 session->source().updates_source);
112 get_updates->mutable_caller_info()->set_notifications_enabled( 158 get_updates->mutable_caller_info()->set_notifications_enabled(
113 session->context()->notifications_enabled()); 159 session->context()->notifications_enabled());
114 160
161 // Set the new and improved version of source, too.
162 get_updates->set_get_updates_origin(origin);
163
115 DebugInfo* debug_info = client_to_server_message.mutable_debug_info(); 164 DebugInfo* debug_info = client_to_server_message.mutable_debug_info();
116 165
117 AppendClientDebugInfoIfNeeded(session, debug_info); 166 AppendClientDebugInfoIfNeeded(session, debug_info);
118 167
119 SyncerError result = SyncerProtoUtil::PostClientToServerMessage( 168 SyncerError result = SyncerProtoUtil::PostClientToServerMessage(
120 &client_to_server_message, 169 &client_to_server_message,
121 &update_response, 170 &update_response,
122 session); 171 session);
123 172
124 DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( 173 DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // could be null in some unit tests. 208 // could be null in some unit tests.
160 if (session->context()->debug_info_getter()) { 209 if (session->context()->debug_info_getter()) {
161 session->context()->debug_info_getter()->GetAndClearDebugInfo( 210 session->context()->debug_info_getter()->GetAndClearDebugInfo(
162 debug_info); 211 debug_info);
163 } 212 }
164 session->mutable_status_controller()->set_debug_info_sent(); 213 session->mutable_status_controller()->set_debug_info_sent();
165 } 214 }
166 } 215 }
167 216
168 } // namespace syncer 217 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/engine/download_updates_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698