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

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 11052007: Rename ModelType/ObjectIdStateMap to InvalidationMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/sync_manager_impl_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/internal_api/sync_manager_impl.h" 5 #include "sync/internal_api/sync_manager_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "sync/engine/sync_scheduler.h" 20 #include "sync/engine/sync_scheduler.h"
21 #include "sync/engine/syncer_types.h" 21 #include "sync/engine/syncer_types.h"
22 #include "sync/internal_api/change_reorder_buffer.h" 22 #include "sync/internal_api/change_reorder_buffer.h"
23 #include "sync/internal_api/public/base/model_type.h" 23 #include "sync/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/base/model_type_state_map.h" 24 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
25 #include "sync/internal_api/public/base_node.h" 25 #include "sync/internal_api/public/base_node.h"
26 #include "sync/internal_api/public/configure_reason.h" 26 #include "sync/internal_api/public/configure_reason.h"
27 #include "sync/internal_api/public/engine/polling_constants.h" 27 #include "sync/internal_api/public/engine/polling_constants.h"
28 #include "sync/internal_api/public/http_post_provider_factory.h" 28 #include "sync/internal_api/public/http_post_provider_factory.h"
29 #include "sync/internal_api/public/internal_components_factory.h" 29 #include "sync/internal_api/public/internal_components_factory.h"
30 #include "sync/internal_api/public/read_node.h" 30 #include "sync/internal_api/public/read_node.h"
31 #include "sync/internal_api/public/read_transaction.h" 31 #include "sync/internal_api/public/read_transaction.h"
32 #include "sync/internal_api/public/user_share.h" 32 #include "sync/internal_api/public/user_share.h"
33 #include "sync/internal_api/public/util/experiments.h" 33 #include "sync/internal_api/public/util/experiments.h"
34 #include "sync/internal_api/public/write_node.h" 34 #include "sync/internal_api/public/write_node.h"
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 } 1009 }
1010 1010
1011 // This is here for tests, which are still using p2p notifications. 1011 // This is here for tests, which are still using p2p notifications.
1012 // 1012 //
1013 // TODO(chron): Consider changing this back to track has_more_to_sync 1013 // TODO(chron): Consider changing this back to track has_more_to_sync
1014 // only notify peers if a successful commit has occurred. 1014 // only notify peers if a successful commit has occurred.
1015 bool is_notifiable_commit = 1015 bool is_notifiable_commit =
1016 (event.snapshot.model_neutral_state().num_successful_commits > 0); 1016 (event.snapshot.model_neutral_state().num_successful_commits > 0);
1017 if (is_notifiable_commit) { 1017 if (is_notifiable_commit) {
1018 if (invalidator_.get()) { 1018 if (invalidator_.get()) {
1019 const ObjectIdStateMap& id_state_map = 1019 const ObjectIdInvalidationMap& invalidation_map =
1020 ModelTypeStateMapToObjectIdStateMap(event.snapshot.source().types); 1020 ModelTypeInvalidationMapToObjectIdInvalidationMap(
1021 invalidator_->SendInvalidation(id_state_map); 1021 event.snapshot.source().types);
1022 invalidator_->SendInvalidation(invalidation_map);
1022 } else { 1023 } else {
1023 DVLOG(1) << "Not sending invalidation: invalidator_ is NULL"; 1024 DVLOG(1) << "Not sending invalidation: invalidator_ is NULL";
1024 } 1025 }
1025 } 1026 }
1026 } 1027 }
1027 1028
1028 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { 1029 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
1029 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1030 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1030 OnStopSyncingPermanently()); 1031 OnStopSyncingPermanently());
1031 return; 1032 return;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 for (syncable::Directory::ChildHandles::const_iterator it = 1230 for (syncable::Directory::ChildHandles::const_iterator it =
1230 child_handles.begin(); it != child_handles.end(); ++it) { 1231 child_handles.begin(); it != child_handles.end(); ++it) {
1231 child_ids->Append(Value::CreateStringValue( 1232 child_ids->Append(Value::CreateStringValue(
1232 base::Int64ToString(*it))); 1233 base::Int64ToString(*it)));
1233 } 1234 }
1234 } 1235 }
1235 return JsArgList(&return_args); 1236 return JsArgList(&return_args);
1236 } 1237 }
1237 1238
1238 void SyncManagerImpl::UpdateNotificationInfo( 1239 void SyncManagerImpl::UpdateNotificationInfo(
1239 const ModelTypeStateMap& type_state_map) { 1240 const ModelTypeInvalidationMap& invalidation_map) {
1240 for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); 1241 for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin();
1241 it != type_state_map.end(); ++it) { 1242 it != invalidation_map.end(); ++it) {
1242 NotificationInfo* info = &notification_info_map_[it->first]; 1243 NotificationInfo* info = &notification_info_map_[it->first];
1243 info->total_count++; 1244 info->total_count++;
1244 info->payload = it->second.payload; 1245 info->payload = it->second.payload;
1245 } 1246 }
1246 } 1247 }
1247 1248
1248 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { 1249 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) {
1249 const std::string& state_str = InvalidatorStateToString(state); 1250 const std::string& state_str = InvalidatorStateToString(state);
1250 invalidator_state_ = state; 1251 invalidator_state_ = state;
1251 DVLOG(1) << "Invalidator state changed to: " << state_str; 1252 DVLOG(1) << "Invalidator state changed to: " << state_str;
1252 const bool notifications_enabled = 1253 const bool notifications_enabled =
1253 (invalidator_state_ == INVALIDATIONS_ENABLED); 1254 (invalidator_state_ == INVALIDATIONS_ENABLED);
1254 allstatus_.SetNotificationsEnabled(notifications_enabled); 1255 allstatus_.SetNotificationsEnabled(notifications_enabled);
1255 scheduler_->SetNotificationsEnabled(notifications_enabled); 1256 scheduler_->SetNotificationsEnabled(notifications_enabled);
1256 1257
1257 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth 1258 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth
1258 // error. 1259 // error.
1259 1260
1260 if (js_event_handler_.IsInitialized()) { 1261 if (js_event_handler_.IsInitialized()) {
1261 DictionaryValue details; 1262 DictionaryValue details;
1262 details.SetString("state", state_str); 1263 details.SetString("state", state_str);
1263 js_event_handler_.Call(FROM_HERE, 1264 js_event_handler_.Call(FROM_HERE,
1264 &JsEventHandler::HandleJsEvent, 1265 &JsEventHandler::HandleJsEvent,
1265 "onNotificationStateChange", 1266 "onNotificationStateChange",
1266 JsEventDetails(&details)); 1267 JsEventDetails(&details));
1267 } 1268 }
1268 } 1269 }
1269 1270
1270 void SyncManagerImpl::OnIncomingInvalidation( 1271 void SyncManagerImpl::OnIncomingInvalidation(
1271 const ObjectIdStateMap& id_state_map, 1272 const ObjectIdInvalidationMap& invalidation_map,
1272 IncomingInvalidationSource source) { 1273 IncomingInvalidationSource source) {
1273 DCHECK(thread_checker_.CalledOnValidThread()); 1274 DCHECK(thread_checker_.CalledOnValidThread());
1274 const ModelTypeStateMap& type_state_map = 1275 const ModelTypeInvalidationMap& type_invalidation_map =
1275 ObjectIdStateMapToModelTypeStateMap(id_state_map); 1276 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map);
1276 if (source == LOCAL_INVALIDATION) { 1277 if (source == LOCAL_INVALIDATION) {
1277 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); 1278 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH);
1278 scheduler_->ScheduleNudgeWithStatesAsync( 1279 scheduler_->ScheduleNudgeWithStatesAsync(
1279 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), 1280 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec),
1280 NUDGE_SOURCE_LOCAL_REFRESH, 1281 NUDGE_SOURCE_LOCAL_REFRESH,
1281 type_state_map, FROM_HERE); 1282 type_invalidation_map, FROM_HERE);
1282 } else if (!type_state_map.empty()) { 1283 } else if (!type_invalidation_map.empty()) {
1283 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); 1284 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION);
1284 scheduler_->ScheduleNudgeWithStatesAsync( 1285 scheduler_->ScheduleNudgeWithStatesAsync(
1285 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), 1286 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec),
1286 NUDGE_SOURCE_NOTIFICATION, 1287 NUDGE_SOURCE_NOTIFICATION,
1287 type_state_map, FROM_HERE); 1288 type_invalidation_map, FROM_HERE);
1288 allstatus_.IncrementNotificationsReceived(); 1289 allstatus_.IncrementNotificationsReceived();
1289 UpdateNotificationInfo(type_state_map); 1290 UpdateNotificationInfo(type_invalidation_map);
1290 debug_info_event_listener_.OnIncomingNotification(type_state_map); 1291 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map);
1291 } else { 1292 } else {
1292 LOG(WARNING) << "Sync received invalidation without any type information."; 1293 LOG(WARNING) << "Sync received invalidation without any type information.";
1293 } 1294 }
1294 1295
1295 if (js_event_handler_.IsInitialized()) { 1296 if (js_event_handler_.IsInitialized()) {
1296 DictionaryValue details; 1297 DictionaryValue details;
1297 ListValue* changed_types = new ListValue(); 1298 ListValue* changed_types = new ListValue();
1298 details.Set("changedTypes", changed_types); 1299 details.Set("changedTypes", changed_types);
1299 for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); 1300 for (ModelTypeInvalidationMap::const_iterator it =
1300 it != type_state_map.end(); ++it) { 1301 type_invalidation_map.begin(); it != type_invalidation_map.end();
1302 ++it) {
1301 const std::string& model_type_str = 1303 const std::string& model_type_str =
1302 ModelTypeToString(it->first); 1304 ModelTypeToString(it->first);
1303 changed_types->Append(Value::CreateStringValue(model_type_str)); 1305 changed_types->Append(Value::CreateStringValue(model_type_str));
1304 } 1306 }
1305 details.SetString("source", (source == LOCAL_INVALIDATION) ? 1307 details.SetString("source", (source == LOCAL_INVALIDATION) ?
1306 "LOCAL_INVALIDATION" : "REMOTE_INVALIDATION"); 1308 "LOCAL_INVALIDATION" : "REMOTE_INVALIDATION");
1307 js_event_handler_.Call(FROM_HERE, 1309 js_event_handler_.Call(FROM_HERE,
1308 &JsEventHandler::HandleJsEvent, 1310 &JsEventHandler::HandleJsEvent,
1309 "onIncomingNotification", 1311 "onIncomingNotification",
1310 JsEventDetails(&details)); 1312 JsEventDetails(&details));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 int SyncManagerImpl::GetDefaultNudgeDelay() { 1358 int SyncManagerImpl::GetDefaultNudgeDelay() {
1357 return kDefaultNudgeDelayMilliseconds; 1359 return kDefaultNudgeDelayMilliseconds;
1358 } 1360 }
1359 1361
1360 // static. 1362 // static.
1361 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1363 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1362 return kPreferencesNudgeDelayMilliseconds; 1364 return kPreferencesNudgeDelayMilliseconds;
1363 } 1365 }
1364 1366
1365 } // namespace syncer 1367 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698