| 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/public/sync_manager.h" | 5 #include "sync/internal_api/public/sync_manager.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 27 matching lines...) Expand all Loading... |
| 38 #include "sync/internal_api/public/util/experiments.h" | 38 #include "sync/internal_api/public/util/experiments.h" |
| 39 #include "sync/internal_api/public/write_node.h" | 39 #include "sync/internal_api/public/write_node.h" |
| 40 #include "sync/internal_api/public/write_transaction.h" | 40 #include "sync/internal_api/public/write_transaction.h" |
| 41 #include "sync/internal_api/syncapi_internal.h" | 41 #include "sync/internal_api/syncapi_internal.h" |
| 42 #include "sync/internal_api/syncapi_server_connection_manager.h" | 42 #include "sync/internal_api/syncapi_server_connection_manager.h" |
| 43 #include "sync/js/js_arg_list.h" | 43 #include "sync/js/js_arg_list.h" |
| 44 #include "sync/js/js_backend.h" | 44 #include "sync/js/js_backend.h" |
| 45 #include "sync/js/js_event_details.h" | 45 #include "sync/js/js_event_details.h" |
| 46 #include "sync/js/js_event_handler.h" | 46 #include "sync/js/js_event_handler.h" |
| 47 #include "sync/js/js_reply_handler.h" | 47 #include "sync/js/js_reply_handler.h" |
| 48 #include "sync/notifier/invalidation_util.h" |
| 48 #include "sync/notifier/notifications_disabled_reason.h" | 49 #include "sync/notifier/notifications_disabled_reason.h" |
| 49 #include "sync/notifier/sync_notifier.h" | 50 #include "sync/notifier/sync_notifier.h" |
| 50 #include "sync/notifier/sync_notifier_observer.h" | 51 #include "sync/notifier/sync_notifier_observer.h" |
| 51 #include "sync/protocol/encryption.pb.h" | 52 #include "sync/protocol/encryption.pb.h" |
| 52 #include "sync/protocol/proto_value_conversions.h" | 53 #include "sync/protocol/proto_value_conversions.h" |
| 53 #include "sync/protocol/sync.pb.h" | 54 #include "sync/protocol/sync.pb.h" |
| 54 #include "sync/syncable/directory.h" | 55 #include "sync/syncable/directory.h" |
| 55 #include "sync/syncable/directory_change_delegate.h" | 56 #include "sync/syncable/directory_change_delegate.h" |
| 56 #include "sync/syncable/entry.h" | 57 #include "sync/syncable/entry.h" |
| 57 #include "sync/syncable/in_memory_directory_backing_store.h" | 58 #include "sync/syncable/in_memory_directory_backing_store.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 293 |
| 293 // Open the directory named with username_for_share | 294 // Open the directory named with username_for_share |
| 294 bool OpenDirectory(); | 295 bool OpenDirectory(); |
| 295 | 296 |
| 296 // Cryptographer::Observer implementation. | 297 // Cryptographer::Observer implementation. |
| 297 virtual void OnEncryptedTypesChanged( | 298 virtual void OnEncryptedTypesChanged( |
| 298 syncer::ModelTypeSet encrypted_types, | 299 syncer::ModelTypeSet encrypted_types, |
| 299 bool encrypt_everything) OVERRIDE; | 300 bool encrypt_everything) OVERRIDE; |
| 300 | 301 |
| 301 // SyncNotifierObserver implementation. | 302 // SyncNotifierObserver implementation. |
| 303 virtual ObjectIdSet GetHandledIds() OVERRIDE; |
| 302 virtual void OnNotificationsEnabled() OVERRIDE; | 304 virtual void OnNotificationsEnabled() OVERRIDE; |
| 303 virtual void OnNotificationsDisabled( | 305 virtual void OnNotificationsDisabled( |
| 304 syncer::NotificationsDisabledReason reason) OVERRIDE; | 306 syncer::NotificationsDisabledReason reason) OVERRIDE; |
| 305 virtual void OnIncomingNotification( | 307 virtual void OnIncomingNotification( |
| 306 const syncer::ModelTypePayloadMap& type_payloads, | 308 const ObjectIdPayloadMap& id_payloads, |
| 307 syncer::IncomingNotificationSource source) OVERRIDE; | 309 syncer::IncomingNotificationSource source) OVERRIDE; |
| 308 | 310 |
| 309 void AddObserver(SyncManager::Observer* observer); | 311 void AddObserver(SyncManager::Observer* observer); |
| 310 void RemoveObserver(SyncManager::Observer* observer); | 312 void RemoveObserver(SyncManager::Observer* observer); |
| 311 | 313 |
| 312 // Accessors for the private members. | 314 // Accessors for the private members. |
| 313 syncable::Directory* directory() { return share_.directory.get(); } | 315 syncable::Directory* directory() { return share_.directory.get(); } |
| 314 SyncAPIServerConnectionManager* connection_manager() { | 316 SyncAPIServerConnectionManager* connection_manager() { |
| 315 return connection_manager_.get(); | 317 return connection_manager_.get(); |
| 316 } | 318 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // create SyncSessions. Must outlive the SyncScheduler. | 543 // create SyncSessions. Must outlive the SyncScheduler. |
| 542 scoped_ptr<SyncSessionContext> session_context_; | 544 scoped_ptr<SyncSessionContext> session_context_; |
| 543 | 545 |
| 544 // The scheduler that runs the Syncer. Needs to be explicitly | 546 // The scheduler that runs the Syncer. Needs to be explicitly |
| 545 // Start()ed. | 547 // Start()ed. |
| 546 scoped_ptr<SyncScheduler> scheduler_; | 548 scoped_ptr<SyncScheduler> scheduler_; |
| 547 | 549 |
| 548 // The SyncNotifier which notifies us when updates need to be downloaded. | 550 // The SyncNotifier which notifies us when updates need to be downloaded. |
| 549 scoped_ptr<syncer::SyncNotifier> sync_notifier_; | 551 scoped_ptr<syncer::SyncNotifier> sync_notifier_; |
| 550 | 552 |
| 553 // The model types we want to register for notifications on represented as |
| 554 // invalidation::ObjectIds. |
| 555 ObjectIdSet enabled_sync_types_; |
| 556 |
| 551 // A multi-purpose status watch object that aggregates stats from various | 557 // A multi-purpose status watch object that aggregates stats from various |
| 552 // sync components. | 558 // sync components. |
| 553 AllStatus allstatus_; | 559 AllStatus allstatus_; |
| 554 | 560 |
| 555 // Each element of this array is a store of change records produced by | 561 // Each element of this array is a store of change records produced by |
| 556 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are | 562 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are |
| 557 // segregated by model type, and are stored here to be processed and | 563 // segregated by model type, and are stored here to be processed and |
| 558 // forwarded to the observer slightly later, at the TRANSACTION_ENDING | 564 // forwarded to the observer slightly later, at the TRANSACTION_ENDING |
| 559 // step by HandleTransactionEndingChangeEvent. The list is cleared in the | 565 // step by HandleTransactionEndingChangeEvent. The list is cleared in the |
| 560 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent. | 566 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent. |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 // on the UI thread and if shutdown wins then that tasks would execute on | 954 // on the UI thread and if shutdown wins then that tasks would execute on |
| 949 // a freed pointer. This is because UI thread is not shut down. | 955 // a freed pointer. This is because UI thread is not shut down. |
| 950 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 956 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 951 OnInitializationComplete( | 957 OnInitializationComplete( |
| 952 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 958 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 953 signed_in)); | 959 signed_in)); |
| 954 | 960 |
| 955 if (!signed_in && testing_mode_ == NON_TEST) | 961 if (!signed_in && testing_mode_ == NON_TEST) |
| 956 return false; | 962 return false; |
| 957 | 963 |
| 958 sync_notifier_->AddObserver(this); | 964 sync_notifier_->AddHandler(this); |
| 959 | 965 |
| 960 return signed_in; | 966 return signed_in; |
| 961 } | 967 } |
| 962 | 968 |
| 963 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( | 969 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( |
| 964 const std::string& chrome_version, | 970 const std::string& chrome_version, |
| 965 const base::Closure& done_callback) { | 971 const base::Closure& done_callback) { |
| 966 DCHECK(initialized_); | 972 DCHECK(initialized_); |
| 967 syncer::GetSessionName( | 973 syncer::GetSessionName( |
| 968 blocking_task_runner_, | 974 blocking_task_runner_, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 credentials.email, credentials.sync_token); | 1177 credentials.email, credentials.sync_token); |
| 1172 if (initialized_ && scheduler()) { | 1178 if (initialized_ && scheduler()) { |
| 1173 scheduler()->OnCredentialsUpdated(); | 1179 scheduler()->OnCredentialsUpdated(); |
| 1174 } | 1180 } |
| 1175 } | 1181 } |
| 1176 } | 1182 } |
| 1177 | 1183 |
| 1178 void SyncManager::SyncInternal::UpdateEnabledTypes( | 1184 void SyncManager::SyncInternal::UpdateEnabledTypes( |
| 1179 const ModelTypeSet& enabled_types) { | 1185 const ModelTypeSet& enabled_types) { |
| 1180 DCHECK(thread_checker_.CalledOnValidThread()); | 1186 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1181 sync_notifier_->UpdateEnabledTypes(enabled_types); | 1187 enabled_sync_types_ = ModelTypeSetToObjectIdSet(enabled_types); |
| 1188 sync_notifier_->ReloadHandlers(); |
| 1182 } | 1189 } |
| 1183 | 1190 |
| 1184 void SyncManager::SyncInternal::SetEncryptionPassphrase( | 1191 void SyncManager::SyncInternal::SetEncryptionPassphrase( |
| 1185 const std::string& passphrase, | 1192 const std::string& passphrase, |
| 1186 bool is_explicit) { | 1193 bool is_explicit) { |
| 1187 // We do not accept empty passphrases. | 1194 // We do not accept empty passphrases. |
| 1188 if (passphrase.empty()) { | 1195 if (passphrase.empty()) { |
| 1189 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 1196 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 1190 return; | 1197 return; |
| 1191 } | 1198 } |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 | 1664 |
| 1658 scheduler_.reset(); | 1665 scheduler_.reset(); |
| 1659 session_context_.reset(); | 1666 session_context_.reset(); |
| 1660 | 1667 |
| 1661 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1668 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1662 RemoveObserver(&js_sync_manager_observer_); | 1669 RemoveObserver(&js_sync_manager_observer_); |
| 1663 | 1670 |
| 1664 RemoveObserver(&debug_info_event_listener_); | 1671 RemoveObserver(&debug_info_event_listener_); |
| 1665 | 1672 |
| 1666 if (sync_notifier_.get()) { | 1673 if (sync_notifier_.get()) { |
| 1667 sync_notifier_->RemoveObserver(this); | 1674 sync_notifier_->RemoveHandler(this); |
| 1668 } | 1675 } |
| 1669 sync_notifier_.reset(); | 1676 sync_notifier_.reset(); |
| 1670 | 1677 |
| 1671 if (connection_manager_.get()) { | 1678 if (connection_manager_.get()) { |
| 1672 connection_manager_->RemoveListener(this); | 1679 connection_manager_->RemoveListener(this); |
| 1673 } | 1680 } |
| 1674 connection_manager_.reset(); | 1681 connection_manager_.reset(); |
| 1675 | 1682 |
| 1676 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1683 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1677 observing_ip_address_changes_ = false; | 1684 observing_ip_address_changes_ = false; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 void SyncManager::SyncInternal::UpdateNotificationInfo( | 2247 void SyncManager::SyncInternal::UpdateNotificationInfo( |
| 2241 const syncer::ModelTypePayloadMap& type_payloads) { | 2248 const syncer::ModelTypePayloadMap& type_payloads) { |
| 2242 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); | 2249 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 2243 it != type_payloads.end(); ++it) { | 2250 it != type_payloads.end(); ++it) { |
| 2244 NotificationInfo* info = ¬ification_info_map_[it->first]; | 2251 NotificationInfo* info = ¬ification_info_map_[it->first]; |
| 2245 info->total_count++; | 2252 info->total_count++; |
| 2246 info->payload = it->second; | 2253 info->payload = it->second; |
| 2247 } | 2254 } |
| 2248 } | 2255 } |
| 2249 | 2256 |
| 2257 ObjectIdSet SyncManager::SyncInternal::GetHandledIds() { |
| 2258 return enabled_sync_types_; |
| 2259 } |
| 2260 |
| 2250 void SyncManager::SyncInternal::OnNotificationsEnabled() { | 2261 void SyncManager::SyncInternal::OnNotificationsEnabled() { |
| 2251 DVLOG(1) << "Notifications enabled"; | 2262 DVLOG(1) << "Notifications enabled"; |
| 2252 allstatus_.SetNotificationsEnabled(true); | 2263 allstatus_.SetNotificationsEnabled(true); |
| 2253 if (scheduler()) { | 2264 if (scheduler()) { |
| 2254 scheduler()->set_notifications_enabled(true); | 2265 scheduler()->set_notifications_enabled(true); |
| 2255 } | 2266 } |
| 2256 // TODO(akalin): Separate onNotificationStateChange into | 2267 // TODO(akalin): Separate onNotificationStateChange into |
| 2257 // enabled/disabled events. | 2268 // enabled/disabled events. |
| 2258 if (js_event_handler_.IsInitialized()) { | 2269 if (js_event_handler_.IsInitialized()) { |
| 2259 DictionaryValue details; | 2270 DictionaryValue details; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2279 js_event_handler_.Call(FROM_HERE, | 2290 js_event_handler_.Call(FROM_HERE, |
| 2280 &JsEventHandler::HandleJsEvent, | 2291 &JsEventHandler::HandleJsEvent, |
| 2281 "onNotificationStateChange", | 2292 "onNotificationStateChange", |
| 2282 JsEventDetails(&details)); | 2293 JsEventDetails(&details)); |
| 2283 } | 2294 } |
| 2284 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 2295 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 2285 // error. | 2296 // error. |
| 2286 } | 2297 } |
| 2287 | 2298 |
| 2288 void SyncManager::SyncInternal::OnIncomingNotification( | 2299 void SyncManager::SyncInternal::OnIncomingNotification( |
| 2289 const syncer::ModelTypePayloadMap& type_payloads, | 2300 const ObjectIdPayloadMap& id_payloads, |
| 2290 syncer::IncomingNotificationSource source) { | 2301 syncer::IncomingNotificationSource source) { |
| 2291 DCHECK(thread_checker_.CalledOnValidThread()); | 2302 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2303 ModelTypePayloadMap type_payloads = |
| 2304 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); |
| 2292 if (source == syncer::LOCAL_NOTIFICATION) { | 2305 if (source == syncer::LOCAL_NOTIFICATION) { |
| 2293 if (scheduler()) { | 2306 if (scheduler()) { |
| 2294 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2307 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| 2295 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 2308 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 2296 syncer::NUDGE_SOURCE_LOCAL_REFRESH, | 2309 syncer::NUDGE_SOURCE_LOCAL_REFRESH, |
| 2297 type_payloads, FROM_HERE); | 2310 type_payloads, FROM_HERE); |
| 2298 } | 2311 } |
| 2299 } else if (!type_payloads.empty()) { | 2312 } else if (!type_payloads.empty()) { |
| 2300 if (scheduler()) { | 2313 if (scheduler()) { |
| 2301 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2314 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2403 | 2416 |
| 2404 void SyncManager::SimulateDisableNotificationsForTest(int reason) { | 2417 void SyncManager::SimulateDisableNotificationsForTest(int reason) { |
| 2405 DCHECK(thread_checker_.CalledOnValidThread()); | 2418 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2406 data_->OnNotificationsDisabled( | 2419 data_->OnNotificationsDisabled( |
| 2407 static_cast<syncer::NotificationsDisabledReason>(reason)); | 2420 static_cast<syncer::NotificationsDisabledReason>(reason)); |
| 2408 } | 2421 } |
| 2409 | 2422 |
| 2410 void SyncManager::TriggerOnIncomingNotificationForTest( | 2423 void SyncManager::TriggerOnIncomingNotificationForTest( |
| 2411 ModelTypeSet model_types) { | 2424 ModelTypeSet model_types) { |
| 2412 DCHECK(thread_checker_.CalledOnValidThread()); | 2425 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2413 syncer::ModelTypePayloadMap model_types_with_payloads = | 2426 ModelTypePayloadMap type_payloads = |
| 2414 syncer::ModelTypePayloadMapFromEnumSet(model_types, | 2427 ModelTypePayloadMapFromEnumSet(model_types, std::string()); |
| 2415 std::string()); | 2428 data_->OnIncomingNotification( |
| 2416 | 2429 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
| 2417 data_->OnIncomingNotification(model_types_with_payloads, | 2430 REMOTE_NOTIFICATION); |
| 2418 syncer::REMOTE_NOTIFICATION); | |
| 2419 } | 2431 } |
| 2420 | 2432 |
| 2421 const char* ConnectionStatusToString(ConnectionStatus status) { | 2433 const char* ConnectionStatusToString(ConnectionStatus status) { |
| 2422 switch (status) { | 2434 switch (status) { |
| 2423 case CONNECTION_OK: | 2435 case CONNECTION_OK: |
| 2424 return "CONNECTION_OK"; | 2436 return "CONNECTION_OK"; |
| 2425 case CONNECTION_AUTH_ERROR: | 2437 case CONNECTION_AUTH_ERROR: |
| 2426 return "CONNECTION_AUTH_ERROR"; | 2438 return "CONNECTION_AUTH_ERROR"; |
| 2427 case CONNECTION_SERVER_ERROR: | 2439 case CONNECTION_SERVER_ERROR: |
| 2428 return "CONNECTION_SERVER_ERROR"; | 2440 return "CONNECTION_SERVER_ERROR"; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 share->directory->GetDownloadProgress(i.Get(), &marker); | 2481 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2470 | 2482 |
| 2471 if (marker.token().empty()) | 2483 if (marker.token().empty()) |
| 2472 result.Put(i.Get()); | 2484 result.Put(i.Get()); |
| 2473 | 2485 |
| 2474 } | 2486 } |
| 2475 return result; | 2487 return result; |
| 2476 } | 2488 } |
| 2477 | 2489 |
| 2478 } // namespace syncer | 2490 } // namespace syncer |
| OLD | NEW |