| 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 "base/time.h" | 5 #include "base/time.h" |
| 6 #include "base/tracked.h" | 6 #include "base/tracked.h" |
| 7 #include "chrome/browser/sync/engine/syncer_thread_adapter.h" | 7 #include "chrome/browser/sync/engine/syncer_thread_adapter.h" |
| 8 #include "chrome/browser/sync/syncable/model_type.h" | 8 #include "chrome/browser/sync/syncable/model_type.h" |
| 9 | 9 |
| 10 using base::TimeDelta; | 10 using base::TimeDelta; |
| 11 using syncable::ModelTypeBitSet; | 11 using syncable::ModelTypeBitSet; |
| 12 | 12 |
| 13 namespace browser_sync { | 13 namespace browser_sync { |
| 14 | 14 |
| 15 SyncerThreadAdapter::SyncerThreadAdapter(sessions::SyncSessionContext* context, | 15 SyncerThreadAdapter::SyncerThreadAdapter(sessions::SyncSessionContext* context) |
| 16 bool using_new_impl) | 16 : new_impl_(NULL) { |
| 17 : legacy_(NULL), new_impl_(NULL), using_new_impl_(using_new_impl) { | 17 new_impl_.reset(new SyncerThread(context, new Syncer())); |
| 18 if (using_new_impl_) { | |
| 19 new_impl_.reset(new s3::SyncerThread(context, new Syncer())); | |
| 20 } else { | |
| 21 legacy_ = new SyncerThread(context); | |
| 22 } | |
| 23 } | 18 } |
| 24 | 19 |
| 25 SyncerThreadAdapter::~SyncerThreadAdapter() { | 20 SyncerThreadAdapter::~SyncerThreadAdapter() { |
| 26 legacy_ = NULL; | |
| 27 new_impl_.reset(); | 21 new_impl_.reset(); |
| 28 } | 22 } |
| 29 | 23 |
| 30 void SyncerThreadAdapter::WatchConnectionManager( | |
| 31 ServerConnectionManager* conn_mgr) { | |
| 32 DCHECK(!using_new_impl_); | |
| 33 legacy_->WatchConnectionManager(conn_mgr); | |
| 34 } | |
| 35 | |
| 36 bool SyncerThreadAdapter::Start() { | 24 bool SyncerThreadAdapter::Start() { |
| 37 if (using_new_impl_) { | 25 new_impl_->Start(SyncerThread::NORMAL_MODE, NULL); |
| 38 new_impl_->Start(s3::SyncerThread::NORMAL_MODE, NULL); | 26 return true; |
| 39 return true; | |
| 40 } else { | |
| 41 return legacy_->Start(); | |
| 42 } | |
| 43 } | 27 } |
| 44 | 28 |
| 45 bool SyncerThreadAdapter::Stop(int max_wait) { | 29 bool SyncerThreadAdapter::Stop(int max_wait) { |
| 46 if (using_new_impl_) { | 30 new_impl_->Stop(); |
| 47 new_impl_->Stop(); | 31 return true; |
| 48 return true; | |
| 49 } else { | |
| 50 return legacy_->Stop(max_wait); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 bool SyncerThreadAdapter::RequestPause() { | |
| 55 DCHECK(!using_new_impl_); | |
| 56 return legacy_->RequestPause(); | |
| 57 } | |
| 58 | |
| 59 bool SyncerThreadAdapter::RequestResume() { | |
| 60 DCHECK(!using_new_impl_); | |
| 61 return legacy_->RequestResume(); | |
| 62 } | |
| 63 | |
| 64 s3::NudgeSource LegacyToNewSyncerThreadSource(SyncerThread::NudgeSource s) { | |
| 65 switch (s) { | |
| 66 case SyncerThread::kNotification: | |
| 67 return s3::NUDGE_SOURCE_NOTIFICATION; | |
| 68 case SyncerThread::kContinuation: | |
| 69 return s3::NUDGE_SOURCE_CONTINUATION; | |
| 70 case SyncerThread::kLocal: | |
| 71 return s3::NUDGE_SOURCE_LOCAL; | |
| 72 case SyncerThread::kUnknown: | |
| 73 return s3::NUDGE_SOURCE_UNKNOWN; | |
| 74 default: | |
| 75 NOTREACHED(); | |
| 76 return s3::NUDGE_SOURCE_UNKNOWN; | |
| 77 } | |
| 78 } | 32 } |
| 79 | 33 |
| 80 void SyncerThreadAdapter::NudgeSyncer(int milliseconds_from_now, | 34 void SyncerThreadAdapter::NudgeSyncer(int milliseconds_from_now, |
| 81 SyncerThread::NudgeSource source, | 35 NudgeSource source, |
| 82 const tracked_objects::Location& nudge_location) { | 36 const tracked_objects::Location& nudge_location) { |
| 83 if (using_new_impl_) { | 37 if (source == CLEAR_USER_PRIVATE_DATA) { |
| 84 if (source == SyncerThread::kClearPrivateData) { | 38 new_impl_->ScheduleClearUserData(); |
| 85 new_impl_->ScheduleClearUserData(); | 39 return; |
| 86 return; | |
| 87 } | |
| 88 new_impl_->ScheduleNudge( | |
| 89 TimeDelta::FromMilliseconds(milliseconds_from_now), | |
| 90 LegacyToNewSyncerThreadSource(source), ModelTypeBitSet(), | |
| 91 nudge_location); | |
| 92 } else { | |
| 93 legacy_->NudgeSyncer(milliseconds_from_now, source); | |
| 94 } | 40 } |
| 41 new_impl_->ScheduleNudge( |
| 42 TimeDelta::FromMilliseconds(milliseconds_from_now), |
| 43 source, ModelTypeBitSet(), |
| 44 nudge_location); |
| 95 } | 45 } |
| 96 | 46 |
| 97 void SyncerThreadAdapter::NudgeSyncerWithDataTypes( | 47 void SyncerThreadAdapter::NudgeSyncerWithDataTypes( |
| 98 int milliseconds_from_now, | 48 int milliseconds_from_now, |
| 99 SyncerThread::NudgeSource source, | 49 NudgeSource source, |
| 100 const syncable::ModelTypeBitSet& model_types, | 50 const syncable::ModelTypeBitSet& model_types, |
| 101 const tracked_objects::Location& nudge_location) { | 51 const tracked_objects::Location& nudge_location) { |
| 102 DCHECK_NE(SyncerThread::kClearPrivateData, source); | 52 DCHECK_NE(CLEAR_USER_PRIVATE_DATA, source); |
| 103 if (using_new_impl_) { | 53 new_impl_->ScheduleNudge( |
| 104 new_impl_->ScheduleNudge( | 54 TimeDelta::FromMilliseconds(milliseconds_from_now), |
| 105 TimeDelta::FromMilliseconds(milliseconds_from_now), | 55 source, model_types, |
| 106 LegacyToNewSyncerThreadSource(source), model_types, | 56 nudge_location); |
| 107 nudge_location); | |
| 108 } else { | |
| 109 legacy_->NudgeSyncerWithDataTypes(milliseconds_from_now, source, | |
| 110 model_types); | |
| 111 } | |
| 112 } | 57 } |
| 113 | 58 |
| 114 void SyncerThreadAdapter::NudgeSyncerWithPayloads( | 59 void SyncerThreadAdapter::NudgeSyncerWithPayloads( |
| 115 int milliseconds_from_now, | 60 int milliseconds_from_now, |
| 116 SyncerThread::NudgeSource source, | 61 NudgeSource source, |
| 117 const syncable::ModelTypePayloadMap& model_types_with_payloads, | 62 const syncable::ModelTypePayloadMap& model_types_with_payloads, |
| 118 const tracked_objects::Location& nudge_location) { | 63 const tracked_objects::Location& nudge_location) { |
| 119 DCHECK_NE(SyncerThread::kClearPrivateData, source); | 64 new_impl_->ScheduleNudgeWithPayloads( |
| 120 if (using_new_impl_) { | 65 TimeDelta::FromMilliseconds(milliseconds_from_now), |
| 121 new_impl_->ScheduleNudgeWithPayloads( | 66 source, model_types_with_payloads, |
| 122 TimeDelta::FromMilliseconds(milliseconds_from_now), | 67 nudge_location); |
| 123 LegacyToNewSyncerThreadSource(source), model_types_with_payloads, | |
| 124 nudge_location); | |
| 125 } else { | |
| 126 legacy_->NudgeSyncerWithPayloads(milliseconds_from_now, source, | |
| 127 model_types_with_payloads); | |
| 128 } | |
| 129 } | 68 } |
| 130 | 69 |
| 131 void SyncerThreadAdapter::SetNotificationsEnabled(bool enabled) { | 70 void SyncerThreadAdapter::SetNotificationsEnabled(bool enabled) { |
| 132 if (using_new_impl_) | 71 new_impl_->set_notifications_enabled(enabled); |
| 133 new_impl_->set_notifications_enabled(enabled); | |
| 134 else | |
| 135 legacy_->SetNotificationsEnabled(enabled); | |
| 136 } | 72 } |
| 137 | 73 |
| 138 void SyncerThreadAdapter::CreateSyncer(const std::string& dirname) { | 74 SyncerThread* SyncerThreadAdapter::new_impl() { |
| 139 if (!using_new_impl_) | |
| 140 legacy_->CreateSyncer(dirname); | |
| 141 // No-op if using new impl. | |
| 142 } | |
| 143 | |
| 144 s3::SyncerThread* SyncerThreadAdapter::new_impl() { | |
| 145 return new_impl_.get(); | 75 return new_impl_.get(); |
| 146 } | 76 } |
| 147 | 77 |
| 148 } // namespace browser_sync | 78 } // namespace browser_sync |
| OLD | NEW |