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

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

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 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 | 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_payload_map.h" 24 #include "sync/internal_api/public/base/model_type_state_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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (sync_notifier_.get()) { 1018 if (sync_notifier_.get()) {
1019 const ModelTypeSet changed_types = 1019 const ModelTypeSet changed_types =
1020 ModelTypePayloadMapToEnumSet(event.snapshot.source().types); 1020 ModelTypeStateMapToSet(event.snapshot.source().types);
1021 sync_notifier_->SendNotification(changed_types); 1021 sync_notifier_->SendNotification(changed_types);
1022 } else { 1022 } else {
1023 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; 1023 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL";
1024 } 1024 }
1025 } 1025 }
1026 } 1026 }
1027 1027
1028 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { 1028 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
1029 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1029 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1030 OnStopSyncingPermanently()); 1030 OnStopSyncingPermanently());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 for (syncable::Directory::ChildHandles::const_iterator it = 1252 for (syncable::Directory::ChildHandles::const_iterator it =
1253 child_handles.begin(); it != child_handles.end(); ++it) { 1253 child_handles.begin(); it != child_handles.end(); ++it) {
1254 child_ids->Append(Value::CreateStringValue( 1254 child_ids->Append(Value::CreateStringValue(
1255 base::Int64ToString(*it))); 1255 base::Int64ToString(*it)));
1256 } 1256 }
1257 } 1257 }
1258 return JsArgList(&return_args); 1258 return JsArgList(&return_args);
1259 } 1259 }
1260 1260
1261 void SyncManagerImpl::UpdateNotificationInfo( 1261 void SyncManagerImpl::UpdateNotificationInfo(
1262 const ModelTypePayloadMap& type_payloads) { 1262 const ModelTypeStateMap& type_state_map) {
1263 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 1263 for (ModelTypeStateMap::const_iterator it = type_state_map.begin();
1264 it != type_payloads.end(); ++it) { 1264 it != type_state_map.end(); ++it) {
1265 NotificationInfo* info = &notification_info_map_[it->first]; 1265 NotificationInfo* info = &notification_info_map_[it->first];
1266 info->total_count++; 1266 info->total_count++;
1267 info->payload = it->second; 1267 info->payload = it->second.payload;
1268 } 1268 }
1269 } 1269 }
1270 1270
1271 void SyncManagerImpl::OnNotificationsEnabled() { 1271 void SyncManagerImpl::OnNotificationsEnabled() {
1272 OnNotificationStateChange(NO_NOTIFICATION_ERROR); 1272 OnNotificationStateChange(NO_NOTIFICATION_ERROR);
1273 } 1273 }
1274 1274
1275 void SyncManagerImpl::OnNotificationsDisabled( 1275 void SyncManagerImpl::OnNotificationsDisabled(
1276 NotificationsDisabledReason reason) { 1276 NotificationsDisabledReason reason) {
1277 OnNotificationStateChange(reason); 1277 OnNotificationStateChange(reason);
1278 } 1278 }
1279 1279
1280 void SyncManagerImpl::OnIncomingNotification( 1280 void SyncManagerImpl::OnIncomingNotification(
1281 const ObjectIdPayloadMap& id_payloads, 1281 const ObjectIdStateMap& id_state_map,
1282 IncomingNotificationSource source) { 1282 IncomingNotificationSource source) {
1283 DCHECK(thread_checker_.CalledOnValidThread()); 1283 DCHECK(thread_checker_.CalledOnValidThread());
1284 const ModelTypePayloadMap& type_payloads = 1284 const ModelTypeStateMap& type_state_map =
1285 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); 1285 ObjectIdStateMapToModelTypeStateMap(id_state_map);
1286 if (source == LOCAL_NOTIFICATION) { 1286 if (source == LOCAL_NOTIFICATION) {
1287 scheduler_->ScheduleNudgeWithPayloadsAsync( 1287 scheduler_->ScheduleNudgeWithStatesAsync(
1288 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), 1288 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec),
1289 NUDGE_SOURCE_LOCAL_REFRESH, 1289 NUDGE_SOURCE_LOCAL_REFRESH,
1290 type_payloads, FROM_HERE); 1290 type_state_map, FROM_HERE);
1291 } else if (!type_payloads.empty()) { 1291 } else if (!type_state_map.empty()) {
1292 scheduler_->ScheduleNudgeWithPayloadsAsync( 1292 scheduler_->ScheduleNudgeWithStatesAsync(
1293 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), 1293 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec),
1294 NUDGE_SOURCE_NOTIFICATION, 1294 NUDGE_SOURCE_NOTIFICATION,
1295 type_payloads, FROM_HERE); 1295 type_state_map, FROM_HERE);
1296 allstatus_.IncrementNotificationsReceived(); 1296 allstatus_.IncrementNotificationsReceived();
1297 UpdateNotificationInfo(type_payloads); 1297 UpdateNotificationInfo(type_state_map);
1298 debug_info_event_listener_.OnIncomingNotification(type_payloads); 1298 debug_info_event_listener_.OnIncomingNotification(type_state_map);
1299 } else { 1299 } else {
1300 LOG(WARNING) << "Sync received notification without any type information."; 1300 LOG(WARNING) << "Sync received notification without any type information.";
1301 } 1301 }
1302 1302
1303 if (js_event_handler_.IsInitialized()) { 1303 if (js_event_handler_.IsInitialized()) {
1304 DictionaryValue details; 1304 DictionaryValue details;
1305 ListValue* changed_types = new ListValue(); 1305 ListValue* changed_types = new ListValue();
1306 details.Set("changedTypes", changed_types); 1306 details.Set("changedTypes", changed_types);
1307 for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 1307 for (ModelTypeStateMap::const_iterator it = type_state_map.begin();
1308 it != type_payloads.end(); ++it) { 1308 it != type_state_map.end(); ++it) {
1309 const std::string& model_type_str = 1309 const std::string& model_type_str =
1310 ModelTypeToString(it->first); 1310 ModelTypeToString(it->first);
1311 changed_types->Append(Value::CreateStringValue(model_type_str)); 1311 changed_types->Append(Value::CreateStringValue(model_type_str));
1312 } 1312 }
1313 details.SetString("source", (source == LOCAL_NOTIFICATION) ? 1313 details.SetString("source", (source == LOCAL_NOTIFICATION) ?
1314 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); 1314 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION");
1315 js_event_handler_.Call(FROM_HERE, 1315 js_event_handler_.Call(FROM_HERE,
1316 &JsEventHandler::HandleJsEvent, 1316 &JsEventHandler::HandleJsEvent,
1317 "onIncomingNotification", 1317 "onIncomingNotification",
1318 JsEventDetails(&details)); 1318 JsEventDetails(&details));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 int SyncManagerImpl::GetDefaultNudgeDelay() { 1364 int SyncManagerImpl::GetDefaultNudgeDelay() {
1365 return kDefaultNudgeDelayMilliseconds; 1365 return kDefaultNudgeDelayMilliseconds;
1366 } 1366 }
1367 1367
1368 // static. 1368 // static.
1369 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1369 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1370 return kPreferencesNudgeDelayMilliseconds; 1370 return kPreferencesNudgeDelayMilliseconds;
1371 } 1371 }
1372 1372
1373 } // namespace syncer 1373 } // 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