Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 65 // Poll, which never overlaps with anything else: | |
| 66 case sync_pb::GetUpdatesCallerInfo::PERIODIC: | |
| 67 return sync_pb::SyncEnums::PERIODIC; | |
| 68 | |
| 69 // Overlapping normal-mode sources (fall-through is intentional): | |
| 70 case sync_pb::GetUpdatesCallerInfo::LOCAL: | |
| 71 case sync_pb::GetUpdatesCallerInfo::NOTIFICATION: | |
| 72 case sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH: | |
| 73 return sync_pb::SyncEnums::GU_TRIGGER; | |
| 74 | |
| 75 // Deprecated or invalid (fall-through is intentional): | |
| 76 case sync_pb::GetUpdatesCallerInfo::UNKNOWN: | |
| 77 case sync_pb::GetUpdatesCallerInfo::FIRST_UPDATE: | |
| 78 case sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION: | |
| 79 case sync_pb::GetUpdatesCallerInfo::NEW_CLIENT: | |
| 80 NOTREACHED(); | |
| 81 return sync_pb::SyncEnums::UNKNOWN_ORIGIN; | |
| 82 } | |
| 83 } | |
| 84 | |
| 53 } // namespace | 85 } // namespace |
| 54 | 86 |
| 55 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { | 87 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { |
| 56 sync_pb::ClientToServerMessage client_to_server_message; | 88 sync_pb::ClientToServerMessage client_to_server_message; |
| 57 sync_pb::ClientToServerResponse update_response; | 89 sync_pb::ClientToServerResponse update_response; |
| 58 | 90 |
| 59 client_to_server_message.set_share(session->context()->account_name()); | 91 client_to_server_message.set_share(session->context()->account_name()); |
| 60 client_to_server_message.set_message_contents( | 92 client_to_server_message.set_message_contents( |
| 61 sync_pb::ClientToServerMessage::GET_UPDATES); | 93 sync_pb::ClientToServerMessage::GET_UPDATES); |
| 62 sync_pb::GetUpdatesMessage* get_updates = | 94 sync_pb::GetUpdatesMessage* get_updates = |
| 63 client_to_server_message.mutable_get_updates(); | 95 client_to_server_message.mutable_get_updates(); |
| 64 get_updates->set_create_mobile_bookmarks_folder( | 96 get_updates->set_create_mobile_bookmarks_folder( |
| 65 create_mobile_bookmarks_folder_); | 97 create_mobile_bookmarks_folder_); |
| 66 | 98 |
| 99 sync_pb::SyncEnums::GetUpdatesOrigin origin = | |
| 100 ConvertGetUpdateSourceToOrigin(session->source().updates_source); | |
| 101 | |
| 67 syncable::Directory* dir = session->context()->directory(); | 102 syncable::Directory* dir = session->context()->directory(); |
| 68 | 103 |
| 69 // Request updates for all enabled types. | 104 // Request updates for all enabled types. |
| 70 const ModelTypeSet enabled_types = | 105 const ModelTypeSet enabled_types = |
| 71 GetRoutingInfoTypes(session->context()->routing_info()); | 106 GetRoutingInfoTypes(session->context()->routing_info()); |
| 72 DVLOG(1) << "Getting updates for types " | 107 DVLOG(1) << "Getting updates for types " |
| 73 << ModelTypeSetToString(enabled_types); | 108 << ModelTypeSetToString(enabled_types); |
| 74 DCHECK(!enabled_types.Empty()); | 109 DCHECK(!enabled_types.Empty()); |
| 75 | 110 |
| 76 const ModelTypeInvalidationMap& invalidation_map = | 111 const ModelTypeInvalidationMap& invalidation_map = |
| 77 session->source().types; | 112 session->source().types; |
| 78 for (ModelTypeSet::Iterator it = enabled_types.First(); | 113 for (ModelTypeSet::Iterator it = enabled_types.First(); |
| 79 it.Good(); it.Inc()) { | 114 it.Good(); it.Inc()) { |
| 80 if (ProxyTypes().Has(it.Get())) | 115 if (ProxyTypes().Has(it.Get())) |
| 81 continue; | 116 continue; |
| 82 sync_pb::DataTypeProgressMarker* progress_marker = | 117 sync_pb::DataTypeProgressMarker* progress_marker = |
| 83 get_updates->add_from_progress_marker(); | 118 get_updates->add_from_progress_marker(); |
| 84 dir->GetDownloadProgress(it.Get(), progress_marker); | 119 dir->GetDownloadProgress(it.Get(), progress_marker); |
| 85 | 120 |
| 86 // Set notification hint if present. | 121 // Set notification hint if present. |
| 87 ModelTypeInvalidationMap::const_iterator find_it = | 122 ModelTypeInvalidationMap::const_iterator find_it = |
| 88 invalidation_map.find(it.Get()); | 123 invalidation_map.find(it.Get()); |
| 89 if (find_it != invalidation_map.end()) { | 124 if (find_it != invalidation_map.end()) { |
| 90 progress_marker->set_notification_hint(find_it->second.payload); | 125 progress_marker->set_notification_hint(find_it->second.payload); |
| 91 } | 126 } |
| 127 | |
| 128 if (session->nudge_tracker()) { | |
| 129 DCHECK_EQ(sync_pb::SyncEnums::GU_TRIGGER, origin); | |
|
tim (not reviewing)
2013/05/06 21:29:04
The real question we're asking is "What kind of GU
rlarocque
2013/05/07 18:45:39
Done.
| |
| 130 session->nudge_tracker()->FillProtoMessage( | |
| 131 it.Get(), | |
| 132 progress_marker->mutable_get_update_triggers()); | |
| 133 } else { | |
| 134 DCHECK_NE(sync_pb::SyncEnums::GU_TRIGGER, origin); | |
| 135 } | |
| 92 } | 136 } |
| 93 | 137 |
| 94 bool need_encryption_key = false; | 138 bool need_encryption_key = false; |
| 95 if (session->context()->keystore_encryption_enabled()) { | 139 if (session->context()->keystore_encryption_enabled()) { |
| 96 syncable::Directory* dir = session->context()->directory(); | 140 syncable::Directory* dir = session->context()->directory(); |
| 97 syncable::ReadTransaction trans(FROM_HERE, dir); | 141 syncable::ReadTransaction trans(FROM_HERE, dir); |
| 98 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler(); | 142 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler(); |
| 99 need_encryption_key = nigori_handler->NeedKeystoreKey(&trans); | 143 need_encryption_key = nigori_handler->NeedKeystoreKey(&trans); |
| 100 get_updates->set_need_encryption_key(need_encryption_key); | 144 get_updates->set_need_encryption_key(need_encryption_key); |
| 101 | 145 |
| 102 } | 146 } |
| 103 | 147 |
| 104 // We want folders for our associated types, always. If we were to set | 148 // 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 | 149 // this to false, the server would send just the non-container items |
| 106 // (e.g. Bookmark URLs but not their containing folders). | 150 // (e.g. Bookmark URLs but not their containing folders). |
| 107 get_updates->set_fetch_folders(true); | 151 get_updates->set_fetch_folders(true); |
| 108 | 152 |
| 109 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. | 153 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. |
| 110 get_updates->mutable_caller_info()->set_source( | 154 get_updates->mutable_caller_info()->set_source( |
| 111 session->source().updates_source); | 155 session->source().updates_source); |
| 112 get_updates->mutable_caller_info()->set_notifications_enabled( | 156 get_updates->mutable_caller_info()->set_notifications_enabled( |
| 113 session->context()->notifications_enabled()); | 157 session->context()->notifications_enabled()); |
| 114 | 158 |
| 159 // Set the new and improved version of source, too. | |
| 160 get_updates->set_get_updates_origin(origin); | |
| 161 | |
| 115 DebugInfo* debug_info = client_to_server_message.mutable_debug_info(); | 162 DebugInfo* debug_info = client_to_server_message.mutable_debug_info(); |
| 116 | 163 |
| 117 AppendClientDebugInfoIfNeeded(session, debug_info); | 164 AppendClientDebugInfoIfNeeded(session, debug_info); |
| 118 | 165 |
| 119 SyncerError result = SyncerProtoUtil::PostClientToServerMessage( | 166 SyncerError result = SyncerProtoUtil::PostClientToServerMessage( |
| 120 &client_to_server_message, | 167 &client_to_server_message, |
| 121 &update_response, | 168 &update_response, |
| 122 session); | 169 session); |
| 123 | 170 |
| 124 DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( | 171 DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // could be null in some unit tests. | 206 // could be null in some unit tests. |
| 160 if (session->context()->debug_info_getter()) { | 207 if (session->context()->debug_info_getter()) { |
| 161 session->context()->debug_info_getter()->GetAndClearDebugInfo( | 208 session->context()->debug_info_getter()->GetAndClearDebugInfo( |
| 162 debug_info); | 209 debug_info); |
| 163 } | 210 } |
| 164 session->mutable_status_controller()->set_debug_info_sent(); | 211 session->mutable_status_controller()->set_debug_info_sent(); |
| 165 } | 212 } |
| 166 } | 213 } |
| 167 | 214 |
| 168 } // namespace syncer | 215 } // namespace syncer |
| OLD | NEW |