| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 292 |
| 293 // Open the directory named with username_for_share | 293 // Open the directory named with username_for_share |
| 294 bool OpenDirectory(); | 294 bool OpenDirectory(); |
| 295 | 295 |
| 296 // Cryptographer::Observer implementation. | 296 // Cryptographer::Observer implementation. |
| 297 virtual void OnEncryptedTypesChanged( | 297 virtual void OnEncryptedTypesChanged( |
| 298 syncer::ModelTypeSet encrypted_types, | 298 syncer::ModelTypeSet encrypted_types, |
| 299 bool encrypt_everything) OVERRIDE; | 299 bool encrypt_everything) OVERRIDE; |
| 300 | 300 |
| 301 // SyncNotifierObserver implementation. | 301 // SyncNotifierObserver implementation. |
| 302 virtual ObjectIdSet GetHandledIds() OVERRIDE; |
| 302 virtual void OnNotificationsEnabled() OVERRIDE; | 303 virtual void OnNotificationsEnabled() OVERRIDE; |
| 303 virtual void OnNotificationsDisabled( | 304 virtual void OnNotificationsDisabled( |
| 304 syncer::NotificationsDisabledReason reason) OVERRIDE; | 305 syncer::NotificationsDisabledReason reason) OVERRIDE; |
| 305 virtual void OnIncomingNotification( | 306 virtual void OnIncomingNotification( |
| 306 const syncer::ModelTypePayloadMap& type_payloads, | 307 const ObjectIdPayloadMap& id_payloads, |
| 307 syncer::IncomingNotificationSource source) OVERRIDE; | 308 syncer::IncomingNotificationSource source) OVERRIDE; |
| 308 | 309 |
| 309 void AddObserver(SyncManager::Observer* observer); | 310 void AddObserver(SyncManager::Observer* observer); |
| 310 void RemoveObserver(SyncManager::Observer* observer); | 311 void RemoveObserver(SyncManager::Observer* observer); |
| 311 | 312 |
| 312 // Accessors for the private members. | 313 // Accessors for the private members. |
| 313 syncable::Directory* directory() { return share_.directory.get(); } | 314 syncable::Directory* directory() { return share_.directory.get(); } |
| 314 SyncAPIServerConnectionManager* connection_manager() { | 315 SyncAPIServerConnectionManager* connection_manager() { |
| 315 return connection_manager_.get(); | 316 return connection_manager_.get(); |
| 316 } | 317 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // create SyncSessions. Must outlive the SyncScheduler. | 542 // create SyncSessions. Must outlive the SyncScheduler. |
| 542 scoped_ptr<SyncSessionContext> session_context_; | 543 scoped_ptr<SyncSessionContext> session_context_; |
| 543 | 544 |
| 544 // The scheduler that runs the Syncer. Needs to be explicitly | 545 // The scheduler that runs the Syncer. Needs to be explicitly |
| 545 // Start()ed. | 546 // Start()ed. |
| 546 scoped_ptr<SyncScheduler> scheduler_; | 547 scoped_ptr<SyncScheduler> scheduler_; |
| 547 | 548 |
| 548 // The SyncNotifier which notifies us when updates need to be downloaded. | 549 // The SyncNotifier which notifies us when updates need to be downloaded. |
| 549 scoped_ptr<syncer::SyncNotifier> sync_notifier_; | 550 scoped_ptr<syncer::SyncNotifier> sync_notifier_; |
| 550 | 551 |
| 552 // The model types we want to register for notifications on represented as |
| 553 // invalidation::ObjectIds. |
| 554 ObjectIdSet enabled_sync_types_; |
| 555 |
| 551 // A multi-purpose status watch object that aggregates stats from various | 556 // A multi-purpose status watch object that aggregates stats from various |
| 552 // sync components. | 557 // sync components. |
| 553 AllStatus allstatus_; | 558 AllStatus allstatus_; |
| 554 | 559 |
| 555 // Each element of this array is a store of change records produced by | 560 // Each element of this array is a store of change records produced by |
| 556 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are | 561 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are |
| 557 // segregated by model type, and are stored here to be processed and | 562 // segregated by model type, and are stored here to be processed and |
| 558 // forwarded to the observer slightly later, at the TRANSACTION_ENDING | 563 // forwarded to the observer slightly later, at the TRANSACTION_ENDING |
| 559 // step by HandleTransactionEndingChangeEvent. The list is cleared in the | 564 // step by HandleTransactionEndingChangeEvent. The list is cleared in the |
| 560 // TRANSACTION_COMPLETE step by HandleTransactionCompleteChangeEvent. | 565 // 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 | 953 // 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. | 954 // a freed pointer. This is because UI thread is not shut down. |
| 950 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 955 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 951 OnInitializationComplete( | 956 OnInitializationComplete( |
| 952 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 957 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 953 signed_in)); | 958 signed_in)); |
| 954 | 959 |
| 955 if (!signed_in && testing_mode_ == NON_TEST) | 960 if (!signed_in && testing_mode_ == NON_TEST) |
| 956 return false; | 961 return false; |
| 957 | 962 |
| 958 sync_notifier_->AddObserver(this); | 963 sync_notifier_->AddHandler(this); |
| 959 | 964 |
| 960 return signed_in; | 965 return signed_in; |
| 961 } | 966 } |
| 962 | 967 |
| 963 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( | 968 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( |
| 964 const std::string& chrome_version, | 969 const std::string& chrome_version, |
| 965 const base::Closure& done_callback) { | 970 const base::Closure& done_callback) { |
| 966 DCHECK(initialized_); | 971 DCHECK(initialized_); |
| 967 syncer::GetSessionName( | 972 syncer::GetSessionName( |
| 968 blocking_task_runner_, | 973 blocking_task_runner_, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 credentials.email, credentials.sync_token); | 1176 credentials.email, credentials.sync_token); |
| 1172 if (initialized_ && scheduler()) { | 1177 if (initialized_ && scheduler()) { |
| 1173 scheduler()->OnCredentialsUpdated(); | 1178 scheduler()->OnCredentialsUpdated(); |
| 1174 } | 1179 } |
| 1175 } | 1180 } |
| 1176 } | 1181 } |
| 1177 | 1182 |
| 1178 void SyncManager::SyncInternal::UpdateEnabledTypes( | 1183 void SyncManager::SyncInternal::UpdateEnabledTypes( |
| 1179 const ModelTypeSet& enabled_types) { | 1184 const ModelTypeSet& enabled_types) { |
| 1180 DCHECK(thread_checker_.CalledOnValidThread()); | 1185 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1181 sync_notifier_->UpdateEnabledTypes(enabled_types); | 1186 // TODO(dcheng): Should this be a helper? |
| 1187 enabled_sync_types_.clear(); |
| 1188 for (ModelTypeSet::Iterator iter = enabled_types.First(); iter.Good(); |
| 1189 iter.Inc()) { |
| 1190 invalidation::ObjectId model_type_as_id; |
| 1191 if (!RealModelTypeToObjectId(iter.Get(), &model_type_as_id)) { |
| 1192 DLOG(WARNING) << "Invalid model type " << iter.Get(); |
| 1193 continue; |
| 1194 } |
| 1195 enabled_sync_types_.insert(model_type_as_id); |
| 1196 } |
| 1197 sync_notifier_->ReloadHandlers(); |
| 1182 } | 1198 } |
| 1183 | 1199 |
| 1184 void SyncManager::SyncInternal::SetEncryptionPassphrase( | 1200 void SyncManager::SyncInternal::SetEncryptionPassphrase( |
| 1185 const std::string& passphrase, | 1201 const std::string& passphrase, |
| 1186 bool is_explicit) { | 1202 bool is_explicit) { |
| 1187 // We do not accept empty passphrases. | 1203 // We do not accept empty passphrases. |
| 1188 if (passphrase.empty()) { | 1204 if (passphrase.empty()) { |
| 1189 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 1205 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 1190 return; | 1206 return; |
| 1191 } | 1207 } |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 | 1673 |
| 1658 scheduler_.reset(); | 1674 scheduler_.reset(); |
| 1659 session_context_.reset(); | 1675 session_context_.reset(); |
| 1660 | 1676 |
| 1661 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1677 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1662 RemoveObserver(&js_sync_manager_observer_); | 1678 RemoveObserver(&js_sync_manager_observer_); |
| 1663 | 1679 |
| 1664 RemoveObserver(&debug_info_event_listener_); | 1680 RemoveObserver(&debug_info_event_listener_); |
| 1665 | 1681 |
| 1666 if (sync_notifier_.get()) { | 1682 if (sync_notifier_.get()) { |
| 1667 sync_notifier_->RemoveObserver(this); | 1683 sync_notifier_->RemoveHandler(this); |
| 1668 } | 1684 } |
| 1669 sync_notifier_.reset(); | 1685 sync_notifier_.reset(); |
| 1670 | 1686 |
| 1671 if (connection_manager_.get()) { | 1687 if (connection_manager_.get()) { |
| 1672 connection_manager_->RemoveListener(this); | 1688 connection_manager_->RemoveListener(this); |
| 1673 } | 1689 } |
| 1674 connection_manager_.reset(); | 1690 connection_manager_.reset(); |
| 1675 | 1691 |
| 1676 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1692 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1677 observing_ip_address_changes_ = false; | 1693 observing_ip_address_changes_ = false; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 void SyncManager::SyncInternal::UpdateNotificationInfo( | 2256 void SyncManager::SyncInternal::UpdateNotificationInfo( |
| 2241 const syncer::ModelTypePayloadMap& type_payloads) { | 2257 const syncer::ModelTypePayloadMap& type_payloads) { |
| 2242 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); | 2258 for (syncer::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
| 2243 it != type_payloads.end(); ++it) { | 2259 it != type_payloads.end(); ++it) { |
| 2244 NotificationInfo* info = ¬ification_info_map_[it->first]; | 2260 NotificationInfo* info = ¬ification_info_map_[it->first]; |
| 2245 info->total_count++; | 2261 info->total_count++; |
| 2246 info->payload = it->second; | 2262 info->payload = it->second; |
| 2247 } | 2263 } |
| 2248 } | 2264 } |
| 2249 | 2265 |
| 2266 ObjectIdSet SyncManager::SyncInternal::GetHandledIds() { |
| 2267 return enabled_sync_types_; |
| 2268 } |
| 2269 |
| 2250 void SyncManager::SyncInternal::OnNotificationsEnabled() { | 2270 void SyncManager::SyncInternal::OnNotificationsEnabled() { |
| 2251 DVLOG(1) << "Notifications enabled"; | 2271 DVLOG(1) << "Notifications enabled"; |
| 2252 allstatus_.SetNotificationsEnabled(true); | 2272 allstatus_.SetNotificationsEnabled(true); |
| 2253 if (scheduler()) { | 2273 if (scheduler()) { |
| 2254 scheduler()->set_notifications_enabled(true); | 2274 scheduler()->set_notifications_enabled(true); |
| 2255 } | 2275 } |
| 2256 // TODO(akalin): Separate onNotificationStateChange into | 2276 // TODO(akalin): Separate onNotificationStateChange into |
| 2257 // enabled/disabled events. | 2277 // enabled/disabled events. |
| 2258 if (js_event_handler_.IsInitialized()) { | 2278 if (js_event_handler_.IsInitialized()) { |
| 2259 DictionaryValue details; | 2279 DictionaryValue details; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2279 js_event_handler_.Call(FROM_HERE, | 2299 js_event_handler_.Call(FROM_HERE, |
| 2280 &JsEventHandler::HandleJsEvent, | 2300 &JsEventHandler::HandleJsEvent, |
| 2281 "onNotificationStateChange", | 2301 "onNotificationStateChange", |
| 2282 JsEventDetails(&details)); | 2302 JsEventDetails(&details)); |
| 2283 } | 2303 } |
| 2284 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 2304 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 2285 // error. | 2305 // error. |
| 2286 } | 2306 } |
| 2287 | 2307 |
| 2288 void SyncManager::SyncInternal::OnIncomingNotification( | 2308 void SyncManager::SyncInternal::OnIncomingNotification( |
| 2289 const syncer::ModelTypePayloadMap& type_payloads, | 2309 const ObjectIdPayloadMap& id_payloads, |
| 2290 syncer::IncomingNotificationSource source) { | 2310 syncer::IncomingNotificationSource source) { |
| 2291 DCHECK(thread_checker_.CalledOnValidThread()); | 2311 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2312 ModelTypePayloadMap type_payloads = |
| 2313 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); |
| 2292 if (source == syncer::LOCAL_NOTIFICATION) { | 2314 if (source == syncer::LOCAL_NOTIFICATION) { |
| 2293 if (scheduler()) { | 2315 if (scheduler()) { |
| 2294 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2316 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| 2295 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 2317 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 2296 syncer::NUDGE_SOURCE_LOCAL_REFRESH, | 2318 syncer::NUDGE_SOURCE_LOCAL_REFRESH, |
| 2297 type_payloads, FROM_HERE); | 2319 type_payloads, FROM_HERE); |
| 2298 } | 2320 } |
| 2299 } else if (!type_payloads.empty()) { | 2321 } else if (!type_payloads.empty()) { |
| 2300 if (scheduler()) { | 2322 if (scheduler()) { |
| 2301 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2323 scheduler()->ScheduleNudgeWithPayloadsAsync( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2403 | 2425 |
| 2404 void SyncManager::SimulateDisableNotificationsForTest(int reason) { | 2426 void SyncManager::SimulateDisableNotificationsForTest(int reason) { |
| 2405 DCHECK(thread_checker_.CalledOnValidThread()); | 2427 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2406 data_->OnNotificationsDisabled( | 2428 data_->OnNotificationsDisabled( |
| 2407 static_cast<syncer::NotificationsDisabledReason>(reason)); | 2429 static_cast<syncer::NotificationsDisabledReason>(reason)); |
| 2408 } | 2430 } |
| 2409 | 2431 |
| 2410 void SyncManager::TriggerOnIncomingNotificationForTest( | 2432 void SyncManager::TriggerOnIncomingNotificationForTest( |
| 2411 ModelTypeSet model_types) { | 2433 ModelTypeSet model_types) { |
| 2412 DCHECK(thread_checker_.CalledOnValidThread()); | 2434 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2413 syncer::ModelTypePayloadMap model_types_with_payloads = | 2435 ModelTypePayloadMap type_payloads = |
| 2414 syncer::ModelTypePayloadMapFromEnumSet(model_types, | 2436 ModelTypePayloadMapFromEnumSet(model_types, std::string()); |
| 2415 std::string()); | 2437 data_->OnIncomingNotification( |
| 2416 | 2438 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
| 2417 data_->OnIncomingNotification(model_types_with_payloads, | 2439 REMOTE_NOTIFICATION); |
| 2418 syncer::REMOTE_NOTIFICATION); | |
| 2419 } | 2440 } |
| 2420 | 2441 |
| 2421 const char* ConnectionStatusToString(ConnectionStatus status) { | 2442 const char* ConnectionStatusToString(ConnectionStatus status) { |
| 2422 switch (status) { | 2443 switch (status) { |
| 2423 case CONNECTION_OK: | 2444 case CONNECTION_OK: |
| 2424 return "CONNECTION_OK"; | 2445 return "CONNECTION_OK"; |
| 2425 case CONNECTION_AUTH_ERROR: | 2446 case CONNECTION_AUTH_ERROR: |
| 2426 return "CONNECTION_AUTH_ERROR"; | 2447 return "CONNECTION_AUTH_ERROR"; |
| 2427 case CONNECTION_SERVER_ERROR: | 2448 case CONNECTION_SERVER_ERROR: |
| 2428 return "CONNECTION_SERVER_ERROR"; | 2449 return "CONNECTION_SERVER_ERROR"; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 share->directory->GetDownloadProgress(i.Get(), &marker); | 2490 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2470 | 2491 |
| 2471 if (marker.token().empty()) | 2492 if (marker.token().empty()) |
| 2472 result.Put(i.Get()); | 2493 result.Put(i.Get()); |
| 2473 | 2494 |
| 2474 } | 2495 } |
| 2475 return result; | 2496 return result; |
| 2476 } | 2497 } |
| 2477 | 2498 |
| 2478 } // namespace syncer | 2499 } // namespace syncer |
| OLD | NEW |