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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/sync/engine/all_status.h" | 17 #include "chrome/browser/sync/engine/all_status.h" |
| 18 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 18 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 19 #include "chrome/browser/sync/engine/nigori_util.h" | 19 #include "chrome/browser/sync/engine/nigori_util.h" |
| 20 #include "chrome/browser/sync/engine/polling_constants.h" | |
| 20 #include "chrome/browser/sync/engine/syncapi_internal.h" | 21 #include "chrome/browser/sync/engine/syncapi_internal.h" |
| 21 #include "chrome/browser/sync/engine/syncer_types.h" | 22 #include "chrome/browser/sync/engine/syncer_types.h" |
| 22 #include "chrome/browser/sync/engine/sync_scheduler.h" | 23 #include "chrome/browser/sync/engine/sync_scheduler.h" |
| 23 #include "chrome/browser/sync/internal_api/base_node.h" | 24 #include "chrome/browser/sync/internal_api/base_node.h" |
| 24 #include "chrome/browser/sync/internal_api/change_reorder_buffer.h" | 25 #include "chrome/browser/sync/internal_api/change_reorder_buffer.h" |
| 25 #include "chrome/browser/sync/internal_api/configure_reason.h" | 26 #include "chrome/browser/sync/internal_api/configure_reason.h" |
| 26 #include "chrome/browser/sync/internal_api/debug_info_event_listener.h" | 27 #include "chrome/browser/sync/internal_api/debug_info_event_listener.h" |
| 27 #include "chrome/browser/sync/internal_api/read_node.h" | 28 #include "chrome/browser/sync/internal_api/read_node.h" |
| 28 #include "chrome/browser/sync/internal_api/read_transaction.h" | 29 #include "chrome/browser/sync/internal_api/read_transaction.h" |
| 29 #include "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h" | 30 #include "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 NOTREACHED(); | 108 NOTREACHED(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 return GetUpdatesCallerInfo::UNKNOWN; | 111 return GetUpdatesCallerInfo::UNKNOWN; |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace | 114 } // namespace |
| 114 | 115 |
| 115 namespace sync_api { | 116 namespace sync_api { |
| 116 | 117 |
| 118 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200; | |
|
tim (not reviewing)
2011/12/16 02:52:10
seems like these should go along with the other co
| |
| 119 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000; | |
| 120 | |
| 117 ////////////////////////////////////////////////////////////////////////// | 121 ////////////////////////////////////////////////////////////////////////// |
| 118 // SyncManager's implementation: SyncManager::SyncInternal | 122 // SyncManager's implementation: SyncManager::SyncInternal |
| 119 class SyncManager::SyncInternal | 123 class SyncManager::SyncInternal |
| 120 : public net::NetworkChangeNotifier::IPAddressObserver, | 124 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 121 public browser_sync::Cryptographer::Observer, | 125 public browser_sync::Cryptographer::Observer, |
| 122 public sync_notifier::SyncNotifierObserver, | 126 public sync_notifier::SyncNotifierObserver, |
| 123 public JsBackend, | 127 public JsBackend, |
| 124 public SyncEngineEventListener, | 128 public SyncEngineEventListener, |
| 125 public ServerConnectionEventListener, | 129 public ServerConnectionEventListener, |
| 126 public syncable::DirectoryChangeDelegate { | 130 public syncable::DirectoryChangeDelegate { |
| 127 static const int kDefaultNudgeDelayMilliseconds; | |
| 128 static const int kPreferencesNudgeDelayMilliseconds; | |
| 129 public: | 131 public: |
| 130 explicit SyncInternal(const std::string& name) | 132 explicit SyncInternal(const std::string& name) |
| 131 : name_(name), | 133 : name_(name), |
| 132 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 134 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 133 registrar_(NULL), | 135 registrar_(NULL), |
| 134 change_delegate_(NULL), | 136 change_delegate_(NULL), |
| 135 initialized_(false), | 137 initialized_(false), |
| 136 setup_for_test_mode_(false), | 138 setup_for_test_mode_(false), |
| 137 observing_ip_address_changes_(false), | 139 observing_ip_address_changes_(false), |
| 138 created_on_loop_(MessageLoop::current()) { | 140 created_on_loop_(MessageLoop::current()) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 virtual void StoreState(const std::string& cookie) OVERRIDE; | 277 virtual void StoreState(const std::string& cookie) OVERRIDE; |
| 276 | 278 |
| 277 void AddObserver(SyncManager::Observer* observer); | 279 void AddObserver(SyncManager::Observer* observer); |
| 278 void RemoveObserver(SyncManager::Observer* observer); | 280 void RemoveObserver(SyncManager::Observer* observer); |
| 279 | 281 |
| 280 // Accessors for the private members. | 282 // Accessors for the private members. |
| 281 DirectoryManager* dir_manager() { return share_.dir_manager.get(); } | 283 DirectoryManager* dir_manager() { return share_.dir_manager.get(); } |
| 282 SyncAPIServerConnectionManager* connection_manager() { | 284 SyncAPIServerConnectionManager* connection_manager() { |
| 283 return connection_manager_.get(); | 285 return connection_manager_.get(); |
| 284 } | 286 } |
| 285 SyncScheduler* scheduler() { return scheduler_.get(); } | 287 SyncScheduler* scheduler() const { return scheduler_.get(); } |
| 286 UserShare* GetUserShare() { | 288 UserShare* GetUserShare() { |
| 287 DCHECK(initialized_); | 289 DCHECK(initialized_); |
| 288 return &share_; | 290 return &share_; |
| 289 } | 291 } |
| 290 | 292 |
| 291 // Return the currently active (validated) username for use with syncable | 293 // Return the currently active (validated) username for use with syncable |
| 292 // types. | 294 // types. |
| 293 const std::string& username_for_share() const { | 295 const std::string& username_for_share() const { |
| 294 return share_.name; | 296 return share_.name; |
| 295 } | 297 } |
| 296 | 298 |
| 297 Status GetStatus(); | 299 Status GetStatus(); |
| 298 | 300 |
| 299 void RequestNudge(const tracked_objects::Location& nudge_location); | 301 void RequestNudge(const tracked_objects::Location& nudge_location); |
| 300 | 302 |
| 301 void RequestNudgeForDataType( | 303 void RequestNudgeForDataType( |
| 302 const tracked_objects::Location& nudge_location, | 304 const tracked_objects::Location& nudge_location, |
| 303 const ModelType& type); | 305 const ModelType& type); |
| 304 | 306 |
| 307 TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type); | |
| 308 | |
| 305 // See SyncManager::Shutdown* for information. | 309 // See SyncManager::Shutdown* for information. |
| 306 void StopSyncingForShutdown(const base::Closure& callback); | 310 void StopSyncingForShutdown(const base::Closure& callback); |
| 307 void ShutdownOnSyncThread(); | 311 void ShutdownOnSyncThread(); |
| 308 | 312 |
| 309 // If this is a deletion for a password, sets the legacy | 313 // If this is a deletion for a password, sets the legacy |
| 310 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets | 314 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets |
| 311 // |buffer|'s specifics field to contain the unencrypted data. | 315 // |buffer|'s specifics field to contain the unencrypted data. |
| 312 void SetExtraChangeRecordData(int64 id, | 316 void SetExtraChangeRecordData(int64 id, |
| 313 syncable::ModelType type, | 317 syncable::ModelType type, |
| 314 ChangeReorderBuffer* buffer, | 318 ChangeReorderBuffer* buffer, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 JsMessageHandlerMap js_message_handlers_; | 546 JsMessageHandlerMap js_message_handlers_; |
| 543 WeakHandle<JsEventHandler> js_event_handler_; | 547 WeakHandle<JsEventHandler> js_event_handler_; |
| 544 JsSyncManagerObserver js_sync_manager_observer_; | 548 JsSyncManagerObserver js_sync_manager_observer_; |
| 545 JsMutationEventObserver js_mutation_event_observer_; | 549 JsMutationEventObserver js_mutation_event_observer_; |
| 546 | 550 |
| 547 // This is for keeping track of client events to send to the server. | 551 // This is for keeping track of client events to send to the server. |
| 548 DebugInfoEventListener debug_info_event_listener_; | 552 DebugInfoEventListener debug_info_event_listener_; |
| 549 | 553 |
| 550 MessageLoop* const created_on_loop_; | 554 MessageLoop* const created_on_loop_; |
| 551 }; | 555 }; |
| 552 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 556 |
| 553 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 557 // A class to calculate nudge delays for types. |
| 558 class NudgeStrategy { | |
| 559 public: | |
| 560 static TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type, | |
| 561 SyncManager::SyncInternal* core) { | |
| 562 NudgeDelayStrategy delay_type = GetNudgeDelayStrategy(model_type); | |
| 563 return GetNudgeDelayTimeDeltaFromType(delay_type, | |
| 564 model_type, | |
| 565 core); | |
| 566 } | |
| 567 | |
| 568 private: | |
| 569 // Possible types of nudge delay for datatypes. | |
| 570 // Note: These are just hints. If a sync happens then all dirty entries | |
| 571 // would be committed as part of the sync. | |
| 572 enum NudgeDelayStrategy { | |
| 573 // Sync right away. | |
| 574 IMMEDIATE, | |
| 575 | |
| 576 // Sync this change while syncing another change. | |
| 577 ACCOMPANY_ONLY, | |
|
tim (not reviewing)
2011/12/16 02:52:10
Based on the fact that we actually _will_ sync it
| |
| 578 | |
| 579 // The datatype does not use one of the predefined wait times but defines | |
| 580 // its own wait time logic for nudge. | |
| 581 CUSTOM, | |
| 582 }; | |
| 583 | |
| 584 static NudgeDelayStrategy GetNudgeDelayStrategy(const ModelType& type) { | |
| 585 switch (type) { | |
| 586 case syncable::AUTOFILL: | |
| 587 case syncable::AUTOFILL_PROFILE: | |
| 588 return ACCOMPANY_ONLY; | |
| 589 case syncable::PREFERENCES: | |
| 590 case syncable::SESSIONS: | |
| 591 return CUSTOM; | |
| 592 default: | |
| 593 return IMMEDIATE; | |
| 594 } | |
| 595 } | |
| 596 | |
| 597 static TimeDelta GetNudgeDelayTimeDeltaFromType( | |
| 598 const NudgeDelayStrategy& delay_type, const ModelType& model_type, | |
| 599 const SyncManager::SyncInternal* core) { | |
| 600 CHECK(core); | |
| 601 TimeDelta delay = TimeDelta::FromMilliseconds( | |
| 602 SyncManager::kDefaultNudgeDelayMilliseconds); | |
| 603 switch (delay_type) { | |
| 604 case IMMEDIATE: | |
| 605 delay = TimeDelta::FromMilliseconds( | |
| 606 SyncManager::kDefaultNudgeDelayMilliseconds); | |
| 607 break; | |
| 608 case ACCOMPANY_ONLY: | |
| 609 delay = TimeDelta::FromSeconds( | |
| 610 browser_sync::kDefaultShortPollIntervalSeconds); | |
| 611 break; | |
| 612 case CUSTOM: | |
| 613 switch (model_type) { | |
| 614 case syncable::PREFERENCES: | |
| 615 delay = TimeDelta::FromMilliseconds( | |
| 616 SyncManager::kPreferencesNudgeDelayMilliseconds); | |
| 617 break; | |
| 618 case syncable::SESSIONS: | |
| 619 delay = core->scheduler()->sessions_commit_delay(); | |
| 620 break; | |
| 621 default: | |
| 622 NOTREACHED(); | |
| 623 } | |
| 624 break; | |
| 625 default: | |
| 626 NOTREACHED(); | |
| 627 } | |
| 628 return delay; | |
| 629 } | |
| 630 }; | |
| 554 | 631 |
| 555 SyncManager::ChangeDelegate::~ChangeDelegate() {} | 632 SyncManager::ChangeDelegate::~ChangeDelegate() {} |
| 556 | 633 |
| 557 SyncManager::ChangeObserver::~ChangeObserver() {} | 634 SyncManager::ChangeObserver::~ChangeObserver() {} |
| 558 | 635 |
| 559 SyncManager::Observer::~Observer() {} | 636 SyncManager::Observer::~Observer() {} |
| 560 | 637 |
| 561 SyncManager::SyncManager(const std::string& name) | 638 SyncManager::SyncManager(const std::string& name) |
| 562 : data_(new SyncInternal(name)) {} | 639 : data_(new SyncInternal(name)) {} |
| 563 | 640 |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 } | 1614 } |
| 1538 | 1615 |
| 1539 void SyncManager::SyncInternal::RequestNudge( | 1616 void SyncManager::SyncInternal::RequestNudge( |
| 1540 const tracked_objects::Location& location) { | 1617 const tracked_objects::Location& location) { |
| 1541 if (scheduler()) | 1618 if (scheduler()) |
| 1542 scheduler()->ScheduleNudge( | 1619 scheduler()->ScheduleNudge( |
| 1543 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, | 1620 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, |
| 1544 ModelTypeSet(), location); | 1621 ModelTypeSet(), location); |
| 1545 } | 1622 } |
| 1546 | 1623 |
| 1624 TimeDelta SyncManager::SyncInternal::GetNudgeDelayTimeDelta( | |
| 1625 const ModelType& model_type) { | |
| 1626 return NudgeStrategy::GetNudgeDelayTimeDelta(model_type, this); | |
| 1627 } | |
| 1628 | |
| 1547 void SyncManager::SyncInternal::RequestNudgeForDataType( | 1629 void SyncManager::SyncInternal::RequestNudgeForDataType( |
| 1548 const tracked_objects::Location& nudge_location, | 1630 const tracked_objects::Location& nudge_location, |
| 1549 const ModelType& type) { | 1631 const ModelType& type) { |
| 1550 if (!scheduler()) { | 1632 if (!scheduler()) { |
| 1551 NOTREACHED(); | 1633 NOTREACHED(); |
| 1552 return; | 1634 return; |
| 1553 } | 1635 } |
| 1554 base::TimeDelta nudge_delay; | 1636 |
| 1555 switch (type) { | 1637 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta(type, |
| 1556 case syncable::PREFERENCES: | 1638 this); |
| 1557 nudge_delay = | 1639 syncable::ModelTypeSet types(type); |
| 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 scheduler()->ScheduleNudge(nudge_delay, | 1640 scheduler()->ScheduleNudge(nudge_delay, |
| 1569 browser_sync::NUDGE_SOURCE_LOCAL, | 1641 browser_sync::NUDGE_SOURCE_LOCAL, |
| 1570 ModelTypeSet(type), | 1642 ModelTypeSet(type), |
| 1571 nudge_location); | 1643 nudge_location); |
| 1572 } | 1644 } |
| 1573 | 1645 |
| 1574 void SyncManager::SyncInternal::OnSyncEngineEvent( | 1646 void SyncManager::SyncInternal::OnSyncEngineEvent( |
| 1575 const SyncEngineEvent& event) { | 1647 const SyncEngineEvent& event) { |
| 1576 DCHECK(thread_checker_.CalledOnValidThread()); | 1648 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1577 // Only send an event if this is due to a cycle ending and this cycle | 1649 // Only send an event if this is due to a cycle ending and this cycle |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1979 UserShare* SyncManager::GetUserShare() const { | 2051 UserShare* SyncManager::GetUserShare() const { |
| 1980 return data_->GetUserShare(); | 2052 return data_->GetUserShare(); |
| 1981 } | 2053 } |
| 1982 | 2054 |
| 1983 void SyncManager::RefreshEncryption() { | 2055 void SyncManager::RefreshEncryption() { |
| 1984 DCHECK(thread_checker_.CalledOnValidThread()); | 2056 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1985 if (data_->UpdateCryptographerAndNigori()) | 2057 if (data_->UpdateCryptographerAndNigori()) |
| 1986 data_->RefreshEncryption(); | 2058 data_->RefreshEncryption(); |
| 1987 } | 2059 } |
| 1988 | 2060 |
| 2061 TimeDelta SyncManager::GetNudgeDelayTimeDelta( | |
| 2062 const ModelType& model_type) { | |
| 2063 return data_->GetNudgeDelayTimeDelta(model_type); | |
| 2064 } | |
| 2065 | |
| 1989 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { | 2066 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { |
| 1990 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2067 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1991 return GetEncryptedTypes(&trans); | 2068 return GetEncryptedTypes(&trans); |
| 1992 } | 2069 } |
| 1993 | 2070 |
| 1994 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) | 2071 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) |
| 1995 const { | 2072 const { |
| 1996 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2073 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1997 ReadNode node(&trans); | 2074 ReadNode node(&trans); |
| 1998 if (!node.InitByTagLookup(kNigoriTag)) { | 2075 if (!node.InitByTagLookup(kNigoriTag)) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2081 lookup->GetDownloadProgress(i.Get(), &marker); | 2158 lookup->GetDownloadProgress(i.Get(), &marker); |
| 2082 | 2159 |
| 2083 if (marker.token().empty()) | 2160 if (marker.token().empty()) |
| 2084 result.Put(i.Get()); | 2161 result.Put(i.Get()); |
| 2085 | 2162 |
| 2086 } | 2163 } |
| 2087 return result; | 2164 return result; |
| 2088 } | 2165 } |
| 2089 | 2166 |
| 2090 } // namespace sync_api | 2167 } // namespace sync_api |
| OLD | NEW |