Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

Issue 8787006: Delay autofill commits to reduce client to server traffic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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:21 Perhaps this could be controlled via ClientCommand
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
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
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(
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
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 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 } 1550 }
1543 1551
1544 void SyncManager::SyncInternal::RequestNudge( 1552 void SyncManager::SyncInternal::RequestNudge(
1545 const tracked_objects::Location& location) { 1553 const tracked_objects::Location& location) {
1546 if (scheduler()) 1554 if (scheduler())
1547 scheduler()->ScheduleNudge( 1555 scheduler()->ScheduleNudge(
1548 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, 1556 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL,
1549 ModelTypeBitSet(), location); 1557 ModelTypeBitSet(), location);
1550 } 1558 }
1551 1559
1560 namespace {
1561 NudgeDelayType GetNudgeDelayType(const ModelType& type) {
1562 switch (type) {
1563 case syncable::AUTOFILL:
1564 case syncable::AUTOFILL_PROFILE:
1565 return PIGGY_BACK_WITH_ANOTHER_CHANGE;
1566 case syncable::PREFERENCES:
1567 case syncable::SESSIONS:
1568 return CUSTOM;
1569 default:
1570 return IMMEDIATE;
1571 }
1572 }
1573 } // namespace
1574
1575 TimeDelta SyncManager::SyncInternal::GetNudgeDelayTimeDeltaFromType(
1576 const NudgeDelayType& delay_type, const ModelType& model_type) {
1577
1578 TimeDelta delay = TimeDelta::FromMilliseconds(
1579 SyncManager::kDefaultNudgeDelayMilliseconds);
1580 switch (delay_type) {
1581 case IMMEDIATE:
1582 delay = TimeDelta::FromMilliseconds(
1583 SyncManager::kDefaultNudgeDelayMilliseconds);
1584 break;
1585 case PIGGY_BACK_WITH_ANOTHER_CHANGE:
1586 delay = TimeDelta::FromMilliseconds(
1587 SyncManager::kPiggybackNudgeDelay);
1588 break;
1589 case CUSTOM:
1590 switch (model_type) {
1591 case syncable::PREFERENCES:
1592 delay = TimeDelta::FromMilliseconds(
1593 SyncManager::kPreferencesNudgeDelayMilliseconds);
1594 break;
1595 case syncable::SESSIONS:
1596 delay = scheduler()->sessions_commit_delay();
1597 break;
1598 default:
1599 NOTREACHED();
1600 }
1601 break;
1602 default:
1603 NOTREACHED();
1604 }
1605
1606 return delay;
1607 }
1608
1609 TimeDelta SyncManager::SyncInternal::GetNudgeDelayTimeDelta(
1610 const ModelType& model_type) {
1611 NudgeDelayType delay_type = GetNudgeDelayType(model_type);
1612 return GetNudgeDelayTimeDeltaFromType(delay_type,
1613 model_type);
1614 }
1615
1616
1552 void SyncManager::SyncInternal::RequestNudgeForDataType( 1617 void SyncManager::SyncInternal::RequestNudgeForDataType(
1553 const tracked_objects::Location& nudge_location, 1618 const tracked_objects::Location& nudge_location,
1554 const ModelType& type) { 1619 const ModelType& type) {
1555 if (!scheduler()) { 1620 if (!scheduler()) {
1556 NOTREACHED(); 1621 NOTREACHED();
1557 return; 1622 return;
1558 } 1623 }
1559 base::TimeDelta nudge_delay; 1624 base::TimeDelta nudge_delay = GetNudgeDelayTimeDelta(type);
1560 switch (type) {
1561 case syncable::PREFERENCES:
1562 nudge_delay =
1563 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds);
1564 break;
1565 case syncable::SESSIONS:
1566 nudge_delay = scheduler()->sessions_commit_delay();
1567 break;
1568 default:
1569 nudge_delay =
1570 TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds);
1571 break;
1572 }
1573 syncable::ModelTypeBitSet types; 1625 syncable::ModelTypeBitSet types;
1574 types.set(type); 1626 types.set(type);
1575 scheduler()->ScheduleNudge(nudge_delay, 1627 scheduler()->ScheduleNudge(nudge_delay,
1576 browser_sync::NUDGE_SOURCE_LOCAL, 1628 browser_sync::NUDGE_SOURCE_LOCAL,
1577 types, 1629 types,
1578 nudge_location); 1630 nudge_location);
1579 } 1631 }
1580 1632
1581 void SyncManager::SyncInternal::OnSyncEngineEvent( 1633 void SyncManager::SyncInternal::OnSyncEngineEvent(
1582 const SyncEngineEvent& event) { 1634 const SyncEngineEvent& event) {
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 UserShare* SyncManager::GetUserShare() const { 2037 UserShare* SyncManager::GetUserShare() const {
1986 return data_->GetUserShare(); 2038 return data_->GetUserShare();
1987 } 2039 }
1988 2040
1989 void SyncManager::RefreshEncryption() { 2041 void SyncManager::RefreshEncryption() {
1990 DCHECK(thread_checker_.CalledOnValidThread()); 2042 DCHECK(thread_checker_.CalledOnValidThread());
1991 if (data_->UpdateCryptographerAndNigori()) 2043 if (data_->UpdateCryptographerAndNigori())
1992 data_->RefreshEncryption(); 2044 data_->RefreshEncryption();
1993 } 2045 }
1994 2046
2047 TimeDelta SyncManager::GetNudgeDelayTimeDelta(
2048 const ModelType& model_type) {
2049 return data_->GetNudgeDelayTimeDelta(model_type);
2050 }
2051
1995 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { 2052 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const {
1996 ReadTransaction trans(FROM_HERE, GetUserShare()); 2053 ReadTransaction trans(FROM_HERE, GetUserShare());
1997 return GetEncryptedTypes(&trans); 2054 return GetEncryptedTypes(&trans);
1998 } 2055 }
1999 2056
2000 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) 2057 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add)
2001 const { 2058 const {
2002 ReadTransaction trans(FROM_HERE, GetUserShare()); 2059 ReadTransaction trans(FROM_HERE, GetUserShare());
2003 ReadNode node(&trans); 2060 ReadNode node(&trans);
2004 if (!node.InitByTagLookup(kNigoriTag)) { 2061 if (!node.InitByTagLookup(kNigoriTag)) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 lookup->GetDownloadProgress(*i, &marker); 2144 lookup->GetDownloadProgress(*i, &marker);
2088 2145
2089 if (marker.token().empty()) 2146 if (marker.token().empty())
2090 result.insert(*i); 2147 result.insert(*i);
2091 2148
2092 } 2149 }
2093 return result; 2150 return result;
2094 } 2151 }
2095 2152
2096 } // namespace sync_api 2153 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698