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

Side by Side Diff: sync/internal_api/test/fake_sync_manager.cc

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/internal_api/public/test/fake_sync_manager.h" 5 #include "sync/internal_api/public/test/fake_sync_manager.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/run_loop.h"
12 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
15 #include "sync/internal_api/public/http_post_provider_factory.h" 16 #include "sync/internal_api/public/http_post_provider_factory.h"
16 #include "sync/internal_api/public/internal_components_factory.h" 17 #include "sync/internal_api/public/internal_components_factory.h"
17 #include "sync/internal_api/public/util/weak_handle.h" 18 #include "sync/internal_api/public/util/weak_handle.h"
18 #include "sync/notifier/notifications_disabled_reason.h" 19 #include "sync/notifier/notifications_disabled_reason.h"
19 #include "sync/notifier/object_id_payload_map.h" 20 #include "sync/notifier/object_id_payload_map.h"
20 #include "sync/notifier/sync_notifier.h" 21 #include "sync/notifier/sync_notifier.h"
21 22
22 namespace syncer { 23 namespace syncer {
23 24
24 FakeSyncManager::FakeSyncManager() {} 25 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types,
26 ModelTypeSet progress_marker_types,
27 ModelTypeSet configure_fail_types) :
28 initial_sync_ended_types_(initial_sync_ended_types),
29 progress_marker_types_(progress_marker_types),
30 configure_fail_types_(configure_fail_types) {}
25 31
26 FakeSyncManager::~FakeSyncManager() {} 32 FakeSyncManager::~FakeSyncManager() {}
27 33
28 void FakeSyncManager::set_initial_sync_ended_types(ModelTypeSet types) {
29 initial_sync_ended_types_ = types;
30 }
31
32 void FakeSyncManager::set_progress_marker_types(ModelTypeSet types) {
33 progress_marker_types_ = types;
34 }
35
36 void FakeSyncManager::set_configure_fail_types(ModelTypeSet types) {
37 configure_fail_types_ = types;
38 }
39
40 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() { 34 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() {
41 ModelTypeSet cleaned_types = cleaned_types_; 35 ModelTypeSet cleaned_types = cleaned_types_;
42 cleaned_types_.Clear(); 36 cleaned_types_.Clear();
43 return cleaned_types; 37 return cleaned_types;
44 } 38 }
45 39
46 ModelTypeSet FakeSyncManager::GetAndResetDownloadedTypes() { 40 ModelTypeSet FakeSyncManager::GetAndResetDownloadedTypes() {
47 ModelTypeSet downloaded_types = downloaded_types_; 41 ModelTypeSet downloaded_types = downloaded_types_;
48 downloaded_types_.Clear(); 42 downloaded_types_.Clear();
49 return downloaded_types; 43 return downloaded_types;
(...skipping 27 matching lines...) Expand all
77 void FakeSyncManager::DisableNotifications( 71 void FakeSyncManager::DisableNotifications(
78 NotificationsDisabledReason reason) { 72 NotificationsDisabledReason reason) {
79 if (!sync_task_runner_->PostTask( 73 if (!sync_task_runner_->PostTask(
80 FROM_HERE, 74 FROM_HERE,
81 base::Bind(&FakeSyncManager::DisableNotificationsOnSyncThread, 75 base::Bind(&FakeSyncManager::DisableNotificationsOnSyncThread,
82 base::Unretained(this), reason))) { 76 base::Unretained(this), reason))) {
83 NOTREACHED(); 77 NOTREACHED();
84 } 78 }
85 } 79 }
86 80
81 namespace {
82
83 void DoNothing() {}
84
85 } // namespace
86
87 void FakeSyncManager::WaitForSyncThread() {
msw 2012/08/07 20:09:30 This pattern seems odd, is there precedent for it
akalin 2012/08/07 23:38:05 I don't think there's a precedent. An alternate w
msw 2012/08/08 00:55:23 Sorry, I don't fully understand what you're doing,
88 // Post a task to |sync_task_runner_| and block until it runs.
89 base::RunLoop run_loop;
90 if (!sync_task_runner_->PostTaskAndReply(
91 FROM_HERE,
92 base::Bind(&DoNothing),
93 run_loop.QuitClosure())) {
94 NOTREACHED();
95 }
96 run_loop.Run();
97 }
98
87 bool FakeSyncManager::Init( 99 bool FakeSyncManager::Init(
88 const FilePath& database_location, 100 const FilePath& database_location,
89 const WeakHandle<JsEventHandler>& event_handler, 101 const WeakHandle<JsEventHandler>& event_handler,
90 const std::string& sync_server_and_path, 102 const std::string& sync_server_and_path,
91 int sync_server_port, 103 int sync_server_port,
92 bool use_ssl, 104 bool use_ssl,
93 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 105 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
94 scoped_ptr<HttpPostProviderFactory> post_factory, 106 scoped_ptr<HttpPostProviderFactory> post_factory,
95 const std::vector<ModelSafeWorker*>& workers, 107 const std::vector<ModelSafeWorker*>& workers,
96 ExtensionsActivityMonitor* extensions_activity_monitor, 108 ExtensionsActivityMonitor* extensions_activity_monitor,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 154 }
143 155
144 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { 156 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) {
145 NOTIMPLEMENTED(); 157 NOTIMPLEMENTED();
146 } 158 }
147 159
148 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { 160 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) {
149 enabled_types_ = types; 161 enabled_types_ = types;
150 } 162 }
151 163
164 void FakeSyncManager::SetInvalidationHandler(
165 const std::string& handler_name,
166 SyncNotifierObserver* handler) {
167 notifier_helper_.SetHandler(handler_name, handler);
168 }
169
152 void FakeSyncManager::UpdateRegisteredInvalidationIds( 170 void FakeSyncManager::UpdateRegisteredInvalidationIds(
153 SyncNotifierObserver* handler, 171 const std::string& handler_name,
154 const ObjectIdSet& ids) { 172 const ObjectIdSet& ids) {
155 notifier_helper_.UpdateRegisteredIds(handler, ids); 173 notifier_helper_.UpdateRegisteredIds(handler_name, ids);
156 } 174 }
157 175
158 void FakeSyncManager::StartSyncingNormally( 176 void FakeSyncManager::StartSyncingNormally(
159 const ModelSafeRoutingInfo& routing_info) { 177 const ModelSafeRoutingInfo& routing_info) {
160 // Do nothing. 178 // Do nothing.
161 } 179 }
162 180
163 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, 181 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase,
164 bool is_explicit) { 182 bool is_explicit) {
165 NOTIMPLEMENTED(); 183 NOTIMPLEMENTED();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 notifier_helper_.EmitOnNotificationsEnabled(); 291 notifier_helper_.EmitOnNotificationsEnabled();
274 } 292 }
275 293
276 void FakeSyncManager::DisableNotificationsOnSyncThread( 294 void FakeSyncManager::DisableNotificationsOnSyncThread(
277 NotificationsDisabledReason reason) { 295 NotificationsDisabledReason reason) {
278 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 296 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
279 notifier_helper_.EmitOnNotificationsDisabled(reason); 297 notifier_helper_.EmitOnNotificationsDisabled(reason);
280 } 298 }
281 299
282 } // namespace syncer 300 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698