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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <bitset> | 8 #include <bitset> |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 using browser_sync::sessions::SyncSessionContext; | 102 using browser_sync::sessions::SyncSessionContext; |
103 using std::list; | 103 using std::list; |
104 using std::hex; | 104 using std::hex; |
105 using std::string; | 105 using std::string; |
106 using std::vector; | 106 using std::vector; |
107 using syncable::Directory; | 107 using syncable::Directory; |
108 using syncable::DirectoryManager; | 108 using syncable::DirectoryManager; |
109 using syncable::Entry; | 109 using syncable::Entry; |
110 using syncable::EntryKernelMutationSet; | 110 using syncable::EntryKernelMutationSet; |
111 using syncable::kEncryptedString; | 111 using syncable::kEncryptedString; |
| 112 using syncable::ModelType; |
112 using syncable::ModelTypeBitSet; | 113 using syncable::ModelTypeBitSet; |
113 using syncable::WriterTag; | 114 using syncable::WriterTag; |
114 using syncable::SPECIFICS; | 115 using syncable::SPECIFICS; |
115 using sync_pb::AutofillProfileSpecifics; | 116 using sync_pb::AutofillProfileSpecifics; |
116 | 117 |
117 namespace { | 118 namespace { |
118 | 119 |
119 typedef GoogleServiceAuthError AuthError; | 120 typedef GoogleServiceAuthError AuthError; |
120 | 121 |
121 static const int kThreadExitTimeoutMsec = 60000; | 122 static const int kThreadExitTimeoutMsec = 60000; |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 // SyncManager's implementation: SyncManager::SyncInternal | 1217 // SyncManager's implementation: SyncManager::SyncInternal |
1217 class SyncManager::SyncInternal | 1218 class SyncManager::SyncInternal |
1218 : public net::NetworkChangeNotifier::IPAddressObserver, | 1219 : public net::NetworkChangeNotifier::IPAddressObserver, |
1219 public sync_notifier::SyncNotifierObserver, | 1220 public sync_notifier::SyncNotifierObserver, |
1220 public JsBackend, | 1221 public JsBackend, |
1221 public SyncEngineEventListener, | 1222 public SyncEngineEventListener, |
1222 public ServerConnectionEventListener, | 1223 public ServerConnectionEventListener, |
1223 public syncable::DirectoryChangeDelegate { | 1224 public syncable::DirectoryChangeDelegate { |
1224 static const int kDefaultNudgeDelayMilliseconds; | 1225 static const int kDefaultNudgeDelayMilliseconds; |
1225 static const int kPreferencesNudgeDelayMilliseconds; | 1226 static const int kPreferencesNudgeDelayMilliseconds; |
1226 // TODO(akalin): Remove this once we have the delay controllable | |
1227 // from the server. | |
1228 static const int kSessionsNudgeDelayMilliseconds; | |
1229 public: | 1227 public: |
1230 explicit SyncInternal(const std::string& name) | 1228 explicit SyncInternal(const std::string& name) |
1231 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 1229 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
1232 registrar_(NULL), | 1230 registrar_(NULL), |
1233 initialized_(false), | 1231 initialized_(false), |
1234 setup_for_test_mode_(false), | 1232 setup_for_test_mode_(false), |
1235 observing_ip_address_changes_(false) { | 1233 observing_ip_address_changes_(false) { |
1236 // Pre-fill |notification_info_map_|. | 1234 // Pre-fill |notification_info_map_|. |
1237 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 1235 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
1238 i < syncable::MODEL_TYPE_COUNT; ++i) { | 1236 i < syncable::MODEL_TYPE_COUNT; ++i) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 // Return the currently active (validated) username for use with syncable | 1367 // Return the currently active (validated) username for use with syncable |
1370 // types. | 1368 // types. |
1371 const std::string& username_for_share() const { | 1369 const std::string& username_for_share() const { |
1372 return share_.name; | 1370 return share_.name; |
1373 } | 1371 } |
1374 | 1372 |
1375 Status GetStatus(); | 1373 Status GetStatus(); |
1376 | 1374 |
1377 void RequestNudge(const tracked_objects::Location& nudge_location); | 1375 void RequestNudge(const tracked_objects::Location& nudge_location); |
1378 | 1376 |
1379 void RequestNudgeWithDataTypes(const TimeDelta& delay, | 1377 void RequestNudgeForDataType( |
1380 browser_sync::NudgeSource source, const ModelTypeBitSet& types, | 1378 const tracked_objects::Location& nudge_location, |
1381 const tracked_objects::Location& nudge_location); | 1379 const ModelType& type); |
1382 | 1380 |
1383 void RequestEarlyExit(); | 1381 void RequestEarlyExit(); |
1384 | 1382 |
1385 // See SyncManager::Shutdown for information. | 1383 // See SyncManager::Shutdown for information. |
1386 void Shutdown(); | 1384 void Shutdown(); |
1387 | 1385 |
1388 // If this is a deletion for a password, sets the legacy | 1386 // If this is a deletion for a password, sets the legacy |
1389 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets | 1387 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets |
1390 // |buffer|'s specifics field to contain the unencrypted data. | 1388 // |buffer|'s specifics field to contain the unencrypted data. |
1391 void SetExtraChangeRecordData(int64 id, | 1389 void SetExtraChangeRecordData(int64 id, |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 NotificationInfoMap notification_info_map_; | 1629 NotificationInfoMap notification_info_map_; |
1632 | 1630 |
1633 // These are for interacting with chrome://sync-internals. | 1631 // These are for interacting with chrome://sync-internals. |
1634 JsMessageHandlerMap js_message_handlers_; | 1632 JsMessageHandlerMap js_message_handlers_; |
1635 WeakHandle<JsEventHandler> js_event_handler_; | 1633 WeakHandle<JsEventHandler> js_event_handler_; |
1636 JsSyncManagerObserver js_sync_manager_observer_; | 1634 JsSyncManagerObserver js_sync_manager_observer_; |
1637 JsTransactionObserver js_transaction_observer_; | 1635 JsTransactionObserver js_transaction_observer_; |
1638 }; | 1636 }; |
1639 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1637 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1640 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1638 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
1641 const int SyncManager::SyncInternal::kSessionsNudgeDelayMilliseconds = 10000; | |
1642 | 1639 |
1643 SyncManager::Observer::~Observer() {} | 1640 SyncManager::Observer::~Observer() {} |
1644 | 1641 |
1645 SyncManager::SyncManager(const std::string& name) | 1642 SyncManager::SyncManager(const std::string& name) |
1646 : data_(new SyncInternal(name)) {} | 1643 : data_(new SyncInternal(name)) {} |
1647 | 1644 |
1648 SyncManager::Status::Status() | 1645 SyncManager::Status::Status() |
1649 : summary(INVALID), | 1646 : summary(INVALID), |
1650 authenticated(false), | 1647 authenticated(false), |
1651 server_up(false), | 1648 server_up(false), |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2458 | 2455 |
2459 // Found real mutation. | 2456 // Found real mutation. |
2460 if (mutated_model_type == syncable::UNSPECIFIED) { | 2457 if (mutated_model_type == syncable::UNSPECIFIED) { |
2461 mutated_model_type = model_type; | 2458 mutated_model_type = model_type; |
2462 break; | 2459 break; |
2463 } | 2460 } |
2464 } | 2461 } |
2465 | 2462 |
2466 // Nudge if necessary. | 2463 // Nudge if necessary. |
2467 if (mutated_model_type != syncable::UNSPECIFIED) { | 2464 if (mutated_model_type != syncable::UNSPECIFIED) { |
2468 int nudge_delay; | |
2469 switch (mutated_model_type) { | |
2470 case syncable::PREFERENCES: | |
2471 nudge_delay = kPreferencesNudgeDelayMilliseconds; | |
2472 case syncable::SESSIONS: | |
2473 nudge_delay = kSessionsNudgeDelayMilliseconds; | |
2474 default: | |
2475 nudge_delay = kDefaultNudgeDelayMilliseconds; | |
2476 } | |
2477 syncable::ModelTypeBitSet model_types; | |
2478 model_types.set(mutated_model_type); | |
2479 if (weak_handle_this_.IsInitialized()) { | 2465 if (weak_handle_this_.IsInitialized()) { |
2480 weak_handle_this_.Call(FROM_HERE, | 2466 weak_handle_this_.Call(FROM_HERE, |
2481 &SyncInternal::RequestNudgeWithDataTypes, | 2467 &SyncInternal::RequestNudgeForDataType, |
2482 TimeDelta::FromMilliseconds(nudge_delay), | 2468 FROM_HERE, |
2483 browser_sync::NUDGE_SOURCE_LOCAL, | 2469 mutated_model_type); |
2484 model_types, | |
2485 FROM_HERE); | |
2486 } else { | 2470 } else { |
2487 NOTREACHED(); | 2471 NOTREACHED(); |
2488 } | 2472 } |
2489 } | 2473 } |
2490 } | 2474 } |
2491 | 2475 |
2492 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, | 2476 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, |
2493 syncable::ModelType type, ChangeReorderBuffer* buffer, | 2477 syncable::ModelType type, ChangeReorderBuffer* buffer, |
2494 Cryptographer* cryptographer, const syncable::EntryKernel& original, | 2478 Cryptographer* cryptographer, const syncable::EntryKernel& original, |
2495 bool existed_before, bool exists_now) { | 2479 bool existed_before, bool exists_now) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 } | 2544 } |
2561 | 2545 |
2562 void SyncManager::SyncInternal::RequestNudge( | 2546 void SyncManager::SyncInternal::RequestNudge( |
2563 const tracked_objects::Location& location) { | 2547 const tracked_objects::Location& location) { |
2564 if (scheduler()) | 2548 if (scheduler()) |
2565 scheduler()->ScheduleNudge( | 2549 scheduler()->ScheduleNudge( |
2566 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, | 2550 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, |
2567 ModelTypeBitSet(), location); | 2551 ModelTypeBitSet(), location); |
2568 } | 2552 } |
2569 | 2553 |
2570 void SyncManager::SyncInternal::RequestNudgeWithDataTypes( | 2554 |
2571 const TimeDelta& delay, | 2555 void SyncManager::SyncInternal::RequestNudgeForDataType( |
2572 browser_sync::NudgeSource source, const ModelTypeBitSet& types, | 2556 const tracked_objects::Location& nudge_location, |
2573 const tracked_objects::Location& nudge_location) { | 2557 const ModelType& type) { |
2574 if (!scheduler()) { | 2558 if (!scheduler()) { |
2575 NOTREACHED(); | 2559 NOTREACHED(); |
2576 return; | 2560 return; |
2577 } | 2561 } |
2578 scheduler()->ScheduleNudge(delay, source, types, nudge_location); | 2562 base::TimeDelta nudge_delay; |
| 2563 switch (type) { |
| 2564 case syncable::PREFERENCES: |
| 2565 nudge_delay = |
| 2566 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds); |
| 2567 break; |
| 2568 case syncable::SESSIONS: |
| 2569 nudge_delay = scheduler()->sessions_commit_delay(); |
| 2570 break; |
| 2571 default: |
| 2572 nudge_delay = |
| 2573 TimeDelta::FromMilliseconds(kPreferencesNudgeDelayMilliseconds); |
| 2574 break; |
| 2575 } |
| 2576 syncable::ModelTypeBitSet types; |
| 2577 types.set(type); |
| 2578 scheduler()->ScheduleNudge(nudge_delay, |
| 2579 browser_sync::NUDGE_SOURCE_LOCAL, |
| 2580 types, |
| 2581 nudge_location); |
2579 } | 2582 } |
2580 | 2583 |
2581 void SyncManager::SyncInternal::OnSyncEngineEvent( | 2584 void SyncManager::SyncInternal::OnSyncEngineEvent( |
2582 const SyncEngineEvent& event) { | 2585 const SyncEngineEvent& event) { |
2583 DCHECK(thread_checker_.CalledOnValidThread()); | 2586 DCHECK(thread_checker_.CalledOnValidThread()); |
2584 if (!HaveObservers()) { | 2587 if (!HaveObservers()) { |
2585 LOG(INFO) | 2588 LOG(INFO) |
2586 << "OnSyncEngineEvent returning because observers_.size() is zero"; | 2589 << "OnSyncEngineEvent returning because observers_.size() is zero"; |
2587 return; | 2590 return; |
2588 } | 2591 } |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3074 void SyncManager::TriggerOnIncomingNotificationForTest( | 3077 void SyncManager::TriggerOnIncomingNotificationForTest( |
3075 const syncable::ModelTypeBitSet& model_types) { | 3078 const syncable::ModelTypeBitSet& model_types) { |
3076 syncable::ModelTypePayloadMap model_types_with_payloads = | 3079 syncable::ModelTypePayloadMap model_types_with_payloads = |
3077 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3080 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3078 std::string()); | 3081 std::string()); |
3079 | 3082 |
3080 data_->OnIncomingNotification(model_types_with_payloads); | 3083 data_->OnIncomingNotification(model_types_with_payloads); |
3081 } | 3084 } |
3082 | 3085 |
3083 } // namespace sync_api | 3086 } // namespace sync_api |
OLD | NEW |