| OLD | NEW |
| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 using syncable::UNIQUE_POSITION; | 58 using syncable::UNIQUE_POSITION; |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 // Delays for syncer nudges. | 62 // Delays for syncer nudges. |
| 63 static const int kDefaultNudgeDelayMilliseconds = 200; | 63 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 64 static const int kPreferencesNudgeDelayMilliseconds = 2000; | 64 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 65 static const int kSyncRefreshDelayMsec = 500; | 65 static const int kSyncRefreshDelayMsec = 500; |
| 66 static const int kSyncSchedulerDelayMsec = 250; | 66 static const int kSyncSchedulerDelayMsec = 250; |
| 67 | 67 |
| 68 // Maximum count and size for traffic recorder. | |
| 69 static const unsigned int kMaxMessagesToRecord = 100; | |
| 70 static const unsigned int kMaxMessageSizeToRecord = 50 * 1024; | |
| 71 | |
| 72 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( | 68 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( |
| 73 ConfigureReason reason) { | 69 ConfigureReason reason) { |
| 74 switch (reason) { | 70 switch (reason) { |
| 75 case CONFIGURE_REASON_RECONFIGURATION: | 71 case CONFIGURE_REASON_RECONFIGURATION: |
| 76 return GetUpdatesCallerInfo::RECONFIGURATION; | 72 return GetUpdatesCallerInfo::RECONFIGURATION; |
| 77 case CONFIGURE_REASON_MIGRATION: | 73 case CONFIGURE_REASON_MIGRATION: |
| 78 return GetUpdatesCallerInfo::MIGRATION; | 74 return GetUpdatesCallerInfo::MIGRATION; |
| 79 case CONFIGURE_REASON_NEW_CLIENT: | 75 case CONFIGURE_REASON_NEW_CLIENT: |
| 80 return GetUpdatesCallerInfo::NEW_CLIENT; | 76 return GetUpdatesCallerInfo::NEW_CLIENT; |
| 81 case CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: | 77 case CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return delay; | 161 return delay; |
| 166 } | 162 } |
| 167 }; | 163 }; |
| 168 | 164 |
| 169 SyncManagerImpl::SyncManagerImpl(const std::string& name) | 165 SyncManagerImpl::SyncManagerImpl(const std::string& name) |
| 170 : name_(name), | 166 : name_(name), |
| 171 change_delegate_(NULL), | 167 change_delegate_(NULL), |
| 172 initialized_(false), | 168 initialized_(false), |
| 173 observing_network_connectivity_changes_(false), | 169 observing_network_connectivity_changes_(false), |
| 174 invalidator_state_(DEFAULT_INVALIDATION_ERROR), | 170 invalidator_state_(DEFAULT_INVALIDATION_ERROR), |
| 175 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), | |
| 176 encryptor_(NULL), | 171 encryptor_(NULL), |
| 177 report_unrecoverable_error_function_(NULL), | 172 report_unrecoverable_error_function_(NULL), |
| 178 weak_ptr_factory_(this) { | 173 weak_ptr_factory_(this) { |
| 179 // Pre-fill |notification_info_map_|. | 174 // Pre-fill |notification_info_map_|. |
| 180 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 175 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 181 notification_info_map_.insert( | 176 notification_info_map_.insert( |
| 182 std::make_pair(ModelTypeFromInt(i), NotificationInfo())); | 177 std::make_pair(ModelTypeFromInt(i), NotificationInfo())); |
| 183 } | 178 } |
| 184 | 179 |
| 185 // Bind message handlers. | 180 // Bind message handlers. |
| 186 BindJsMessageHandler( | 181 BindJsMessageHandler( |
| 187 "getAllNodes", | 182 "getAllNodes", |
| 188 &SyncManagerImpl::GetAllNodes); | 183 &SyncManagerImpl::GetAllNodes); |
| 189 BindJsMessageHandler( | |
| 190 "getClientServerTraffic", | |
| 191 &SyncManagerImpl::GetClientServerTraffic); | |
| 192 } | 184 } |
| 193 | 185 |
| 194 SyncManagerImpl::~SyncManagerImpl() { | 186 SyncManagerImpl::~SyncManagerImpl() { |
| 195 DCHECK(thread_checker_.CalledOnValidThread()); | 187 DCHECK(thread_checker_.CalledOnValidThread()); |
| 196 CHECK(!initialized_); | 188 CHECK(!initialized_); |
| 197 } | 189 } |
| 198 | 190 |
| 199 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} | 191 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} |
| 200 SyncManagerImpl::NotificationInfo::~NotificationInfo() {} | 192 SyncManagerImpl::NotificationInfo::~NotificationInfo() {} |
| 201 | 193 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 409 DVLOG(1) << "Sync is bringing up SyncSessionContext."; |
| 418 std::vector<SyncEngineEventListener*> listeners; | 410 std::vector<SyncEngineEventListener*> listeners; |
| 419 listeners.push_back(&allstatus_); | 411 listeners.push_back(&allstatus_); |
| 420 listeners.push_back(this); | 412 listeners.push_back(this); |
| 421 session_context_ = internal_components_factory->BuildContext( | 413 session_context_ = internal_components_factory->BuildContext( |
| 422 connection_manager_.get(), | 414 connection_manager_.get(), |
| 423 directory(), | 415 directory(), |
| 424 extensions_activity, | 416 extensions_activity, |
| 425 listeners, | 417 listeners, |
| 426 &debug_info_event_listener_, | 418 &debug_info_event_listener_, |
| 427 &traffic_recorder_, | |
| 428 model_type_registry_.get(), | 419 model_type_registry_.get(), |
| 429 invalidator_client_id).Pass(); | 420 invalidator_client_id).Pass(); |
| 430 session_context_->set_account_name(credentials.email); | 421 session_context_->set_account_name(credentials.email); |
| 431 scheduler_ = internal_components_factory->BuildScheduler( | 422 scheduler_ = internal_components_factory->BuildScheduler( |
| 432 name_, session_context_.get(), cancelation_signal).Pass(); | 423 name_, session_context_.get(), cancelation_signal).Pass(); |
| 433 | 424 |
| 434 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); | 425 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); |
| 435 | 426 |
| 436 initialized_ = true; | 427 initialized_ = true; |
| 437 | 428 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 name, js_message_handler.Run(args)); | 975 name, js_message_handler.Run(args)); |
| 985 } | 976 } |
| 986 | 977 |
| 987 void SyncManagerImpl::BindJsMessageHandler( | 978 void SyncManagerImpl::BindJsMessageHandler( |
| 988 const std::string& name, | 979 const std::string& name, |
| 989 UnboundJsMessageHandler unbound_message_handler) { | 980 UnboundJsMessageHandler unbound_message_handler) { |
| 990 js_message_handlers_[name] = | 981 js_message_handlers_[name] = |
| 991 base::Bind(unbound_message_handler, base::Unretained(this)); | 982 base::Bind(unbound_message_handler, base::Unretained(this)); |
| 992 } | 983 } |
| 993 | 984 |
| 994 JsArgList SyncManagerImpl::GetClientServerTraffic( | |
| 995 const JsArgList& args) { | |
| 996 base::ListValue return_args; | |
| 997 base::ListValue* value = traffic_recorder_.ToValue(); | |
| 998 if (value != NULL) | |
| 999 return_args.Append(value); | |
| 1000 return JsArgList(&return_args); | |
| 1001 } | |
| 1002 | |
| 1003 JsArgList SyncManagerImpl::GetAllNodes(const JsArgList& args) { | 985 JsArgList SyncManagerImpl::GetAllNodes(const JsArgList& args) { |
| 1004 ReadTransaction trans(FROM_HERE, GetUserShare()); | 986 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1005 base::ListValue return_args; | 987 base::ListValue return_args; |
| 1006 scoped_ptr<base::ListValue> nodes( | 988 scoped_ptr<base::ListValue> nodes( |
| 1007 trans.GetDirectory()->GetAllNodeDetails(trans.GetWrappedTrans())); | 989 trans.GetDirectory()->GetAllNodeDetails(trans.GetWrappedTrans())); |
| 1008 return_args.Append(nodes.release()); | 990 return_args.Append(nodes.release()); |
| 1009 return JsArgList(&return_args); | 991 return JsArgList(&return_args); |
| 1010 } | 992 } |
| 1011 | 993 |
| 1012 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { | 994 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1153 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1172 return kDefaultNudgeDelayMilliseconds; | 1154 return kDefaultNudgeDelayMilliseconds; |
| 1173 } | 1155 } |
| 1174 | 1156 |
| 1175 // static. | 1157 // static. |
| 1176 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1158 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1177 return kPreferencesNudgeDelayMilliseconds; | 1159 return kPreferencesNudgeDelayMilliseconds; |
| 1178 } | 1160 } |
| 1179 | 1161 |
| 1180 } // namespace syncer | 1162 } // namespace syncer |
| OLD | NEW |