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

Side by Side Diff: chrome/browser/sync/engine/syncer_thread_adapter.cc

Issue 6874018: make new syncer thread the default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload before submit. Created 9 years, 8 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/time.h"
6 #include "base/tracked.h"
7 #include "chrome/browser/sync/engine/syncer_thread_adapter.h"
8 #include "chrome/browser/sync/syncable/model_type.h"
9
10 using base::TimeDelta;
11 using syncable::ModelTypeBitSet;
12
13 namespace browser_sync {
14
15 SyncerThreadAdapter::SyncerThreadAdapter(sessions::SyncSessionContext* context,
16 bool using_new_impl)
17 : legacy_(NULL), new_impl_(NULL), using_new_impl_(using_new_impl) {
18 if (using_new_impl_) {
19 new_impl_.reset(new s3::SyncerThread(context, new Syncer()));
20 } else {
21 legacy_ = new SyncerThread(context);
22 }
23 }
24
25 SyncerThreadAdapter::~SyncerThreadAdapter() {
26 legacy_ = NULL;
27 new_impl_.reset();
28 }
29
30 void SyncerThreadAdapter::WatchConnectionManager(
31 ServerConnectionManager* conn_mgr) {
32 DCHECK(!using_new_impl_);
33 legacy_->WatchConnectionManager(conn_mgr);
34 }
35
36 bool SyncerThreadAdapter::Start() {
37 if (using_new_impl_) {
38 new_impl_->Start(s3::SyncerThread::NORMAL_MODE, NULL);
39 return true;
40 } else {
41 return legacy_->Start();
42 }
43 }
44
45 bool SyncerThreadAdapter::Stop(int max_wait) {
46 if (using_new_impl_) {
47 new_impl_->Stop();
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 }
79
80 void SyncerThreadAdapter::NudgeSyncer(int milliseconds_from_now,
81 SyncerThread::NudgeSource source,
82 const tracked_objects::Location& nudge_location) {
83 if (using_new_impl_) {
84 if (source == SyncerThread::kClearPrivateData) {
85 new_impl_->ScheduleClearUserData();
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 }
95 }
96
97 void SyncerThreadAdapter::NudgeSyncerWithDataTypes(
98 int milliseconds_from_now,
99 SyncerThread::NudgeSource source,
100 const syncable::ModelTypeBitSet& model_types,
101 const tracked_objects::Location& nudge_location) {
102 DCHECK_NE(SyncerThread::kClearPrivateData, source);
103 if (using_new_impl_) {
104 new_impl_->ScheduleNudge(
105 TimeDelta::FromMilliseconds(milliseconds_from_now),
106 LegacyToNewSyncerThreadSource(source), model_types,
107 nudge_location);
108 } else {
109 legacy_->NudgeSyncerWithDataTypes(milliseconds_from_now, source,
110 model_types);
111 }
112 }
113
114 void SyncerThreadAdapter::NudgeSyncerWithPayloads(
115 int milliseconds_from_now,
116 SyncerThread::NudgeSource source,
117 const syncable::ModelTypePayloadMap& model_types_with_payloads,
118 const tracked_objects::Location& nudge_location) {
119 DCHECK_NE(SyncerThread::kClearPrivateData, source);
120 if (using_new_impl_) {
121 new_impl_->ScheduleNudgeWithPayloads(
122 TimeDelta::FromMilliseconds(milliseconds_from_now),
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 }
130
131 void SyncerThreadAdapter::SetNotificationsEnabled(bool enabled) {
132 if (using_new_impl_)
133 new_impl_->set_notifications_enabled(enabled);
134 else
135 legacy_->SetNotificationsEnabled(enabled);
136 }
137
138 void SyncerThreadAdapter::CreateSyncer(const std::string& dirname) {
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();
146 }
147
148 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_thread_adapter.h ('k') | chrome/browser/sync/engine/syncer_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698