Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 NOTREACHED(); | 107 NOTREACHED(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 return GetUpdatesCallerInfo::UNKNOWN; | 110 return GetUpdatesCallerInfo::UNKNOWN; |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace | 113 } // namespace |
| 114 | 114 |
| 115 namespace sync_api { | 115 namespace sync_api { |
| 116 | 116 |
| 117 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200; | |
| 118 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000; | |
| 119 | |
| 120 // Nudge delay for datatypes that piggy back their change with other changes. | |
| 121 const int SyncManager::kPiggybackNudgeDelay = 2 * 60 * 60 * 1000; | |
|
tim (not reviewing)
2011/12/09 23:07:22
I'm a bit confused with the relation to the period
lipalani1
2011/12/15 01:35:16
I went back and forth. The advantage is that if it
tim (not reviewing)
2011/12/15 20:59:15
Short-poll sounds good, but shouldn't we tie it to
| |
| 122 | |
| 117 ////////////////////////////////////////////////////////////////////////// | 123 ////////////////////////////////////////////////////////////////////////// |
| 118 // SyncManager's implementation: SyncManager::SyncInternal | 124 // SyncManager's implementation: SyncManager::SyncInternal |
| 119 class SyncManager::SyncInternal | 125 class SyncManager::SyncInternal |
| 120 : public net::NetworkChangeNotifier::IPAddressObserver, | 126 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 121 public browser_sync::Cryptographer::Observer, | 127 public browser_sync::Cryptographer::Observer, |
| 122 public sync_notifier::SyncNotifierObserver, | 128 public sync_notifier::SyncNotifierObserver, |
| 123 public JsBackend, | 129 public JsBackend, |
| 124 public SyncEngineEventListener, | 130 public SyncEngineEventListener, |
| 125 public ServerConnectionEventListener, | 131 public ServerConnectionEventListener, |
| 126 public syncable::DirectoryChangeDelegate { | 132 public syncable::DirectoryChangeDelegate { |
| 127 static const int kDefaultNudgeDelayMilliseconds; | |
| 128 static const int kPreferencesNudgeDelayMilliseconds; | |
| 129 public: | 133 public: |
| 130 explicit SyncInternal(const std::string& name) | 134 explicit SyncInternal(const std::string& name) |
| 131 : name_(name), | 135 : name_(name), |
| 132 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 136 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 133 registrar_(NULL), | 137 registrar_(NULL), |
| 134 change_delegate_(NULL), | 138 change_delegate_(NULL), |
| 135 initialized_(false), | 139 initialized_(false), |
| 136 setup_for_test_mode_(false), | 140 setup_for_test_mode_(false), |
| 137 observing_ip_address_changes_(false), | 141 observing_ip_address_changes_(false), |
| 138 created_on_loop_(MessageLoop::current()) { | 142 created_on_loop_(MessageLoop::current()) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 } | 299 } |
| 296 | 300 |
| 297 Status GetStatus(); | 301 Status GetStatus(); |
| 298 | 302 |
| 299 void RequestNudge(const tracked_objects::Location& nudge_location); | 303 void RequestNudge(const tracked_objects::Location& nudge_location); |
| 300 | 304 |
| 301 void RequestNudgeForDataType( | 305 void RequestNudgeForDataType( |
| 302 const tracked_objects::Location& nudge_location, | 306 const tracked_objects::Location& nudge_location, |
| 303 const ModelType& type); | 307 const ModelType& type); |
| 304 | 308 |
| 309 TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type); | |
| 310 | |
| 305 // See SyncManager::Shutdown* for information. | 311 // See SyncManager::Shutdown* for information. |
| 306 void StopSyncingForShutdown(const base::Closure& callback); | 312 void StopSyncingForShutdown(const base::Closure& callback); |
| 307 void ShutdownOnSyncThread(); | 313 void ShutdownOnSyncThread(); |
| 308 | 314 |
| 309 // If this is a deletion for a password, sets the legacy | 315 // If this is a deletion for a password, sets the legacy |
| 310 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets | 316 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets |
| 311 // |buffer|'s specifics field to contain the unencrypted data. | 317 // |buffer|'s specifics field to contain the unencrypted data. |
| 312 void SetExtraChangeRecordData(int64 id, | 318 void SetExtraChangeRecordData(int64 id, |
| 313 syncable::ModelType type, | 319 syncable::ModelType type, |
| 314 ChangeReorderBuffer* buffer, | 320 ChangeReorderBuffer* buffer, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 | 466 |
| 461 // JS message handlers. | 467 // JS message handlers. |
| 462 JsArgList GetNotificationState(const JsArgList& args); | 468 JsArgList GetNotificationState(const JsArgList& args); |
| 463 JsArgList GetNotificationInfo(const JsArgList& args); | 469 JsArgList GetNotificationInfo(const JsArgList& args); |
| 464 JsArgList GetRootNodeDetails(const JsArgList& args); | 470 JsArgList GetRootNodeDetails(const JsArgList& args); |
| 465 JsArgList GetNodeSummariesById(const JsArgList& args); | 471 JsArgList GetNodeSummariesById(const JsArgList& args); |
| 466 JsArgList GetNodeDetailsById(const JsArgList& args); | 472 JsArgList GetNodeDetailsById(const JsArgList& args); |
| 467 JsArgList GetChildNodeIds(const JsArgList& args); | 473 JsArgList GetChildNodeIds(const JsArgList& args); |
| 468 JsArgList FindNodesContainingString(const JsArgList& args); | 474 JsArgList FindNodesContainingString(const JsArgList& args); |
| 469 | 475 |
| 476 TimeDelta GetNudgeDelayTimeDeltaFromType( | |
|
tim (not reviewing)
2011/12/09 23:07:22
I see an argument for a simple NudgeStrategy class
lipalani1
2011/12/15 01:35:16
Done.
| |
| 477 const NudgeDelayType& delay_type, const ModelType& model_type); | |
| 478 | |
| 479 | |
| 470 const std::string name_; | 480 const std::string name_; |
| 471 | 481 |
| 472 base::ThreadChecker thread_checker_; | 482 base::ThreadChecker thread_checker_; |
| 473 | 483 |
| 474 base::WeakPtrFactory<SyncInternal> weak_ptr_factory_; | 484 base::WeakPtrFactory<SyncInternal> weak_ptr_factory_; |
| 475 | 485 |
| 476 // Thread-safe handle used by | 486 // Thread-safe handle used by |
| 477 // HandleCalculateChangesChangeEventFromSyncApi(), which can be | 487 // HandleCalculateChangesChangeEventFromSyncApi(), which can be |
| 478 // called from any thread. Valid only between between calls to | 488 // called from any thread. Valid only between between calls to |
| 479 // Init() and Shutdown(). | 489 // Init() and Shutdown(). |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 JsMessageHandlerMap js_message_handlers_; | 552 JsMessageHandlerMap js_message_handlers_; |
| 543 WeakHandle<JsEventHandler> js_event_handler_; | 553 WeakHandle<JsEventHandler> js_event_handler_; |
| 544 JsSyncManagerObserver js_sync_manager_observer_; | 554 JsSyncManagerObserver js_sync_manager_observer_; |
| 545 JsMutationEventObserver js_mutation_event_observer_; | 555 JsMutationEventObserver js_mutation_event_observer_; |
| 546 | 556 |
| 547 // This is for keeping track of client events to send to the server. | 557 // This is for keeping track of client events to send to the server. |
| 548 DebugInfoEventListener debug_info_event_listener_; | 558 DebugInfoEventListener debug_info_event_listener_; |
| 549 | 559 |
| 550 MessageLoop* const created_on_loop_; | 560 MessageLoop* const created_on_loop_; |
| 551 }; | 561 }; |
| 552 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | |
| 553 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | |
| 554 | 562 |
| 555 SyncManager::ChangeDelegate::~ChangeDelegate() {} | 563 SyncManager::ChangeDelegate::~ChangeDelegate() {} |
| 556 | 564 |
| 557 SyncManager::ChangeObserver::~ChangeObserver() {} | 565 SyncManager::ChangeObserver::~ChangeObserver() {} |
| 558 | 566 |
| 559 SyncManager::Observer::~Observer() {} | 567 SyncManager::Observer::~Observer() {} |
| 560 | 568 |
| 561 SyncManager::SyncManager(const std::string& name) | 569 SyncManager::SyncManager(const std::string& name) |
| 562 : data_(new SyncInternal(name)) {} | 570 : data_(new SyncInternal(name)) {} |
| 563 | 571 |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 } | 1545 } |
| 1538 | 1546 |
| 1539 void SyncManager::SyncInternal::RequestNudge( | 1547 void SyncManager::SyncInternal::RequestNudge( |
| 1540 const tracked_objects::Location& location) { | 1548 const tracked_objects::Location& location) { |
| 1541 if (scheduler()) | 1549 if (scheduler()) |
| 1542 scheduler()->ScheduleNudge( | 1550 scheduler()->ScheduleNudge( |
| 1543 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, | 1551 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, |
| 1544 ModelTypeBitSet(), location); | 1552 ModelTypeBitSet(), location); |
| 1545 } | 1553 } |
| 1546 | 1554 |
| 1555 namespace { | |
| 1556 NudgeDelayType GetNudgeDelayType(const ModelType& type) { | |
| 1557 switch (type) { | |
| 1558 case syncable::AUTOFILL: | |
| 1559 case syncable::AUTOFILL_PROFILE: | |
| 1560 return PIGGY_BACK_WITH_ANOTHER_CHANGE; | |
| 1561 case syncable::PREFERENCES: | |
| 1562 case syncable::SESSIONS: | |
| 1563 return CUSTOM; | |
| 1564 default: | |
| 1565 return IMMEDIATE; | |
| 1566 } | |
| 1567 } | |
| 1568 } // namespace | |
| 1569 | |
| 1570 TimeDelta SyncManager::SyncInternal::GetNudgeDelayTimeDeltaFromType( | |
| 1571 const NudgeDelayType& delay_type, const ModelType& model_type) { | |
| 1572 | |
| 1573 TimeDelta delay = TimeDelta::FromMilliseconds( | |
| 1574 SyncManager::kDefaultNudgeDelayMilliseconds); | |
| 1575 switch (delay_type) { | |
| 1576 case IMMEDIATE: | |
| 1577 delay = TimeDelta::FromMilliseconds( | |
| 1578 SyncManager::kDefaultNudgeDelayMilliseconds); | |
| 1579 break; | |
| 1580 case PIGGY_BACK_WITH_ANOTHER_CHANGE: | |
| 1581 delay = TimeDelta::FromMilliseconds( | |
| 1582 SyncManager::kPiggybackNudgeDelay); | |
| 1583 break; | |
| 1584 case CUSTOM: | |
| 1585 switch (model_type) { | |
| 1586 case syncable::PREFERENCES: | |
| 1587 delay = TimeDelta::FromMilliseconds( | |
| 1588 SyncManager::kPreferencesNudgeDelayMilliseconds); | |
| 1589 break; | |
| 1590 case syncable::SESSIONS: | |
| 1591 delay = scheduler()->sessions_commit_delay(); | |
| 1592 break; | |
| 1593 default: | |
| 1594 NOTREACHED(); | |
| 1595 } | |
| 1596 break; | |
| 1597 default: | |
| 1598 NOTREACHED(); | |
| 1599 } | |
| 1600 | |
| 1601 return delay; | |
| 1602 } | |
| 1603 | |
| 1604 TimeDelta SyncManager::SyncInternal::GetNudgeDelayTimeDelta( | |
| 1605 const ModelType& model_type) { | |
| 1606 NudgeDelayType delay_type = GetNudgeDelayType(model_type); | |
| 1607 return GetNudgeDelayTimeDeltaFromType(delay_type, | |
| 1608 model_type); | |
| 1609 } | |
| 1610 | |
| 1611 | |
| 1547 void SyncManager::SyncInternal::RequestNudgeForDataType( | 1612 void SyncManager::SyncInternal::RequestNudgeForDataType( |
| 1548 const tracked_objects::Location& nudge_location, | 1613 const tracked_objects::Location& nudge_location, |
| 1549 const ModelType& type) { | 1614 const ModelType& type) { |
| 1550 if (!scheduler()) { | 1615 if (!scheduler()) { |
| 1551 NOTREACHED(); | 1616 NOTREACHED(); |
| 1552 return; | 1617 return; |
| 1553 } | 1618 } |
| 1554 base::TimeDelta nudge_delay; | 1619 base::TimeDelta nudge_delay = GetNudgeDelayTimeDelta(type); |
| 1555 switch (type) { | |
| 1556 case syncable::PREFERENCES: | |
| 1557 nudge_delay = | |
| 1558 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds); | |
| 1559 break; | |
| 1560 case syncable::SESSIONS: | |
| 1561 nudge_delay = scheduler()->sessions_commit_delay(); | |
| 1562 break; | |
| 1563 default: | |
| 1564 nudge_delay = | |
| 1565 TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds); | |
| 1566 break; | |
| 1567 } | |
| 1568 syncable::ModelTypeBitSet types; | 1620 syncable::ModelTypeBitSet types; |
| 1569 types.set(type); | 1621 types.set(type); |
| 1570 scheduler()->ScheduleNudge(nudge_delay, | 1622 scheduler()->ScheduleNudge(nudge_delay, |
| 1571 browser_sync::NUDGE_SOURCE_LOCAL, | 1623 browser_sync::NUDGE_SOURCE_LOCAL, |
| 1572 types, | 1624 types, |
| 1573 nudge_location); | 1625 nudge_location); |
| 1574 } | 1626 } |
| 1575 | 1627 |
| 1576 void SyncManager::SyncInternal::OnSyncEngineEvent( | 1628 void SyncManager::SyncInternal::OnSyncEngineEvent( |
| 1577 const SyncEngineEvent& event) { | 1629 const SyncEngineEvent& event) { |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1980 UserShare* SyncManager::GetUserShare() const { | 2032 UserShare* SyncManager::GetUserShare() const { |
| 1981 return data_->GetUserShare(); | 2033 return data_->GetUserShare(); |
| 1982 } | 2034 } |
| 1983 | 2035 |
| 1984 void SyncManager::RefreshEncryption() { | 2036 void SyncManager::RefreshEncryption() { |
| 1985 DCHECK(thread_checker_.CalledOnValidThread()); | 2037 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1986 if (data_->UpdateCryptographerAndNigori()) | 2038 if (data_->UpdateCryptographerAndNigori()) |
| 1987 data_->RefreshEncryption(); | 2039 data_->RefreshEncryption(); |
| 1988 } | 2040 } |
| 1989 | 2041 |
| 2042 TimeDelta SyncManager::GetNudgeDelayTimeDelta( | |
| 2043 const ModelType& model_type) { | |
| 2044 return data_->GetNudgeDelayTimeDelta(model_type); | |
| 2045 } | |
| 2046 | |
| 1990 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { | 2047 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { |
| 1991 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2048 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1992 return GetEncryptedTypes(&trans); | 2049 return GetEncryptedTypes(&trans); |
| 1993 } | 2050 } |
| 1994 | 2051 |
| 1995 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) | 2052 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) |
| 1996 const { | 2053 const { |
| 1997 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2054 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1998 ReadNode node(&trans); | 2055 ReadNode node(&trans); |
| 1999 if (!node.InitByTagLookup(kNigoriTag)) { | 2056 if (!node.InitByTagLookup(kNigoriTag)) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2082 lookup->GetDownloadProgress(*i, &marker); | 2139 lookup->GetDownloadProgress(*i, &marker); |
| 2083 | 2140 |
| 2084 if (marker.token().empty()) | 2141 if (marker.token().empty()) |
| 2085 result.insert(*i); | 2142 result.insert(*i); |
| 2086 | 2143 |
| 2087 } | 2144 } |
| 2088 return result; | 2145 return result; |
| 2089 } | 2146 } |
| 2090 | 2147 |
| 2091 } // namespace sync_api | 2148 } // namespace sync_api |
| OLD | NEW |