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 28 matching lines...) Expand all Loading... | |
39 #include "sync/internal_api/public/util/experiments.h" | 39 #include "sync/internal_api/public/util/experiments.h" |
40 #include "sync/internal_api/public/write_node.h" | 40 #include "sync/internal_api/public/write_node.h" |
41 #include "sync/internal_api/public/write_transaction.h" | 41 #include "sync/internal_api/public/write_transaction.h" |
42 #include "sync/internal_api/syncapi_internal.h" | 42 #include "sync/internal_api/syncapi_internal.h" |
43 #include "sync/internal_api/syncapi_server_connection_manager.h" | 43 #include "sync/internal_api/syncapi_server_connection_manager.h" |
44 #include "sync/js/js_arg_list.h" | 44 #include "sync/js/js_arg_list.h" |
45 #include "sync/js/js_backend.h" | 45 #include "sync/js/js_backend.h" |
46 #include "sync/js/js_event_details.h" | 46 #include "sync/js/js_event_details.h" |
47 #include "sync/js/js_event_handler.h" | 47 #include "sync/js/js_event_handler.h" |
48 #include "sync/js/js_reply_handler.h" | 48 #include "sync/js/js_reply_handler.h" |
49 #include "sync/notifier/invalidation_util.h" | |
49 #include "sync/notifier/notifications_disabled_reason.h" | 50 #include "sync/notifier/notifications_disabled_reason.h" |
50 #include "sync/notifier/sync_notifier.h" | 51 #include "sync/notifier/sync_notifier.h" |
51 #include "sync/notifier/sync_notifier_observer.h" | 52 #include "sync/notifier/sync_notifier_observer.h" |
52 #include "sync/protocol/encryption.pb.h" | 53 #include "sync/protocol/encryption.pb.h" |
53 #include "sync/protocol/proto_value_conversions.h" | 54 #include "sync/protocol/proto_value_conversions.h" |
54 #include "sync/protocol/sync.pb.h" | 55 #include "sync/protocol/sync.pb.h" |
55 #include "sync/syncable/directory.h" | 56 #include "sync/syncable/directory.h" |
56 #include "sync/syncable/directory_change_delegate.h" | 57 #include "sync/syncable/directory_change_delegate.h" |
57 #include "sync/syncable/entry.h" | 58 #include "sync/syncable/entry.h" |
58 #include "sync/syncable/in_memory_directory_backing_store.h" | 59 #include "sync/syncable/in_memory_directory_backing_store.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // Cryptographer::Observer implementation. | 302 // Cryptographer::Observer implementation. |
302 virtual void OnEncryptedTypesChanged( | 303 virtual void OnEncryptedTypesChanged( |
303 syncer::ModelTypeSet encrypted_types, | 304 syncer::ModelTypeSet encrypted_types, |
304 bool encrypt_everything) OVERRIDE; | 305 bool encrypt_everything) OVERRIDE; |
305 | 306 |
306 // SyncNotifierObserver implementation. | 307 // SyncNotifierObserver implementation. |
307 virtual void OnNotificationsEnabled() OVERRIDE; | 308 virtual void OnNotificationsEnabled() OVERRIDE; |
308 virtual void OnNotificationsDisabled( | 309 virtual void OnNotificationsDisabled( |
309 syncer::NotificationsDisabledReason reason) OVERRIDE; | 310 syncer::NotificationsDisabledReason reason) OVERRIDE; |
310 virtual void OnIncomingNotification( | 311 virtual void OnIncomingNotification( |
311 const syncer::ModelTypePayloadMap& type_payloads, | 312 const ObjectIdPayloadMap& id_payloads, |
312 syncer::IncomingNotificationSource source) OVERRIDE; | 313 syncer::IncomingNotificationSource source) OVERRIDE; |
313 | 314 |
314 void AddObserver(SyncManager::Observer* observer); | 315 void AddObserver(SyncManager::Observer* observer); |
315 void RemoveObserver(SyncManager::Observer* observer); | 316 void RemoveObserver(SyncManager::Observer* observer); |
316 | 317 |
317 // Accessors for the private members. | 318 // Accessors for the private members. |
318 syncable::Directory* directory() { return share_.directory.get(); } | 319 syncable::Directory* directory() { return share_.directory.get(); } |
319 SyncAPIServerConnectionManager* connection_manager() { | 320 SyncAPIServerConnectionManager* connection_manager() { |
320 return connection_manager_.get(); | 321 return connection_manager_.get(); |
321 } | 322 } |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 // on the UI thread and if shutdown wins then that tasks would execute on | 987 // on the UI thread and if shutdown wins then that tasks would execute on |
987 // a freed pointer. This is because UI thread is not shut down. | 988 // a freed pointer. This is because UI thread is not shut down. |
988 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 989 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
989 OnInitializationComplete( | 990 OnInitializationComplete( |
990 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 991 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
991 success)); | 992 success)); |
992 | 993 |
993 if (!success && testing_mode_ == NON_TEST) | 994 if (!success && testing_mode_ == NON_TEST) |
994 return false; | 995 return false; |
995 | 996 |
996 sync_notifier_->AddObserver(this); | |
997 | |
998 return success; | 997 return success; |
999 } | 998 } |
1000 | 999 |
1001 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( | 1000 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( |
1002 const std::string& chrome_version, | 1001 const std::string& chrome_version, |
1003 const base::Closure& done_callback) { | 1002 const base::Closure& done_callback) { |
1004 DCHECK(initialized_); | 1003 DCHECK(initialized_); |
1005 syncer::GetSessionName( | 1004 syncer::GetSessionName( |
1006 blocking_task_runner_, | 1005 blocking_task_runner_, |
1007 base::Bind( | 1006 base::Bind( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 credentials.email, credentials.sync_token); | 1226 credentials.email, credentials.sync_token); |
1228 if (initialized_ && scheduler()) { | 1227 if (initialized_ && scheduler()) { |
1229 scheduler()->OnCredentialsUpdated(); | 1228 scheduler()->OnCredentialsUpdated(); |
1230 } | 1229 } |
1231 } | 1230 } |
1232 } | 1231 } |
1233 | 1232 |
1234 void SyncManagerImpl::SyncInternal::UpdateEnabledTypes( | 1233 void SyncManagerImpl::SyncInternal::UpdateEnabledTypes( |
1235 const ModelTypeSet& enabled_types) { | 1234 const ModelTypeSet& enabled_types) { |
1236 DCHECK(thread_checker_.CalledOnValidThread()); | 1235 DCHECK(thread_checker_.CalledOnValidThread()); |
1237 sync_notifier_->UpdateEnabledTypes(enabled_types); | 1236 sync_notifier_->UpdateRegisteredIds(this, |
1237 ModelTypeSetToObjectIdSet(enabled_types)); | |
1238 } | 1238 } |
1239 | 1239 |
1240 void SyncManagerImpl::SyncInternal::SetEncryptionPassphrase( | 1240 void SyncManagerImpl::SyncInternal::SetEncryptionPassphrase( |
1241 const std::string& passphrase, | 1241 const std::string& passphrase, |
1242 bool is_explicit) { | 1242 bool is_explicit) { |
1243 // We do not accept empty passphrases. | 1243 // We do not accept empty passphrases. |
1244 if (passphrase.empty()) { | 1244 if (passphrase.empty()) { |
1245 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 1245 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
1246 return; | 1246 return; |
1247 } | 1247 } |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1715 | 1715 |
1716 scheduler_.reset(); | 1716 scheduler_.reset(); |
1717 session_context_.reset(); | 1717 session_context_.reset(); |
1718 | 1718 |
1719 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1719 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
1720 RemoveObserver(&js_sync_manager_observer_); | 1720 RemoveObserver(&js_sync_manager_observer_); |
1721 | 1721 |
1722 RemoveObserver(&debug_info_event_listener_); | 1722 RemoveObserver(&debug_info_event_listener_); |
1723 | 1723 |
1724 if (sync_notifier_.get()) { | 1724 if (sync_notifier_.get()) { |
1725 sync_notifier_->RemoveObserver(this); | 1725 sync_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); |
1726 } | 1726 } |
1727 sync_notifier_.reset(); | 1727 sync_notifier_.reset(); |
1728 | 1728 |
1729 if (connection_manager_.get()) { | 1729 if (connection_manager_.get()) { |
1730 connection_manager_->RemoveListener(this); | 1730 connection_manager_->RemoveListener(this); |
1731 } | 1731 } |
1732 connection_manager_.reset(); | 1732 connection_manager_.reset(); |
1733 | 1733 |
1734 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1734 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
1735 observing_ip_address_changes_ = false; | 1735 observing_ip_address_changes_ = false; |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2340 js_event_handler_.Call(FROM_HERE, | 2340 js_event_handler_.Call(FROM_HERE, |
2341 &JsEventHandler::HandleJsEvent, | 2341 &JsEventHandler::HandleJsEvent, |
2342 "onNotificationStateChange", | 2342 "onNotificationStateChange", |
2343 JsEventDetails(&details)); | 2343 JsEventDetails(&details)); |
2344 } | 2344 } |
2345 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 2345 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
2346 // error. | 2346 // error. |
2347 } | 2347 } |
2348 | 2348 |
2349 void SyncManagerImpl::SyncInternal::OnIncomingNotification( | 2349 void SyncManagerImpl::SyncInternal::OnIncomingNotification( |
2350 const syncer::ModelTypePayloadMap& type_payloads, | 2350 const ObjectIdPayloadMap& id_payloads, |
2351 syncer::IncomingNotificationSource source) { | 2351 syncer::IncomingNotificationSource source) { |
2352 DCHECK(thread_checker_.CalledOnValidThread()); | 2352 DCHECK(thread_checker_.CalledOnValidThread()); |
2353 ModelTypePayloadMap type_payloads = | |
akalin
2012/07/19 00:42:06
const ref
dcheng
2012/07/19 18:31:05
Done.
As an aside, do you know if the style guide
akalin
2012/07/19 23:07:26
I don't think so -- I just prefer it myself. I th
| |
2354 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); | |
2353 if (source == syncer::LOCAL_NOTIFICATION) { | 2355 if (source == syncer::LOCAL_NOTIFICATION) { |
2354 if (scheduler()) { | 2356 if (scheduler()) { |
2355 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2357 scheduler()->ScheduleNudgeWithPayloadsAsync( |
2356 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 2358 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
2357 syncer::NUDGE_SOURCE_LOCAL_REFRESH, | 2359 syncer::NUDGE_SOURCE_LOCAL_REFRESH, |
2358 type_payloads, FROM_HERE); | 2360 type_payloads, FROM_HERE); |
2359 } | 2361 } |
2360 } else if (!type_payloads.empty()) { | 2362 } else if (!type_payloads.empty()) { |
2361 if (scheduler()) { | 2363 if (scheduler()) { |
2362 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2364 scheduler()->ScheduleNudgeWithPayloadsAsync( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2474 | 2476 |
2475 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { | 2477 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { |
2476 DCHECK(thread_checker_.CalledOnValidThread()); | 2478 DCHECK(thread_checker_.CalledOnValidThread()); |
2477 data_->OnNotificationsDisabled( | 2479 data_->OnNotificationsDisabled( |
2478 static_cast<syncer::NotificationsDisabledReason>(reason)); | 2480 static_cast<syncer::NotificationsDisabledReason>(reason)); |
2479 } | 2481 } |
2480 | 2482 |
2481 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( | 2483 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( |
2482 ModelTypeSet model_types) { | 2484 ModelTypeSet model_types) { |
2483 DCHECK(thread_checker_.CalledOnValidThread()); | 2485 DCHECK(thread_checker_.CalledOnValidThread()); |
2484 syncer::ModelTypePayloadMap model_types_with_payloads = | 2486 ModelTypePayloadMap type_payloads = |
akalin
2012/07/19 00:42:06
const ref
dcheng
2012/07/19 18:31:05
Done.
| |
2485 syncer::ModelTypePayloadMapFromEnumSet(model_types, | 2487 ModelTypePayloadMapFromEnumSet(model_types, std::string()); |
2486 std::string()); | 2488 data_->OnIncomingNotification( |
2487 | 2489 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
2488 data_->OnIncomingNotification(model_types_with_payloads, | 2490 REMOTE_NOTIFICATION); |
2489 syncer::REMOTE_NOTIFICATION); | |
2490 } | 2491 } |
2491 | 2492 |
2492 // static. | 2493 // static. |
2493 int SyncManagerImpl::GetDefaultNudgeDelay() { | 2494 int SyncManagerImpl::GetDefaultNudgeDelay() { |
2494 return kDefaultNudgeDelayMilliseconds; | 2495 return kDefaultNudgeDelayMilliseconds; |
2495 } | 2496 } |
2496 | 2497 |
2497 // static. | 2498 // static. |
2498 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 2499 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
2499 return kPreferencesNudgeDelayMilliseconds; | 2500 return kPreferencesNudgeDelayMilliseconds; |
2500 } | 2501 } |
2501 | 2502 |
2502 } // namespace syncer | 2503 } // namespace syncer |
OLD | NEW |