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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 7 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static const FilePath::CharType kSyncDataFolderName[] = 54 static const FilePath::CharType kSyncDataFolderName[] =
55 FILE_PATH_LITERAL("Sync Data"); 55 FILE_PATH_LITERAL("Sync Data");
56 56
57 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; 57 typedef TokenService::TokenAvailableDetails TokenAvailableDetails;
58 58
59 typedef GoogleServiceAuthError AuthError; 59 typedef GoogleServiceAuthError AuthError;
60 60
61 namespace browser_sync { 61 namespace browser_sync {
62 62
63 using content::BrowserThread; 63 using content::BrowserThread;
64 using csync::sessions::SyncSessionSnapshot; 64 using syncer::sessions::SyncSessionSnapshot;
65 using csync::SyncCredentials; 65 using syncer::SyncCredentials;
66 66
67 // Helper macros to log with the syncer thread name; useful when there 67 // Helper macros to log with the syncer thread name; useful when there
68 // are multiple syncers involved. 68 // are multiple syncers involved.
69 69
70 #define SLOG(severity) LOG(severity) << name_ << ": " 70 #define SLOG(severity) LOG(severity) << name_ << ": "
71 71
72 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 72 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
73 73
74 class SyncBackendHost::Core 74 class SyncBackendHost::Core
75 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, 75 : public base::RefCountedThreadSafe<SyncBackendHost::Core>,
76 public csync::SyncManager::Observer { 76 public syncer::SyncManager::Observer {
77 public: 77 public:
78 Core(const std::string& name, 78 Core(const std::string& name,
79 const FilePath& sync_data_folder_path, 79 const FilePath& sync_data_folder_path,
80 const base::WeakPtr<SyncBackendHost>& backend); 80 const base::WeakPtr<SyncBackendHost>& backend);
81 81
82 // SyncManager::Observer implementation. The Core just acts like an air 82 // SyncManager::Observer implementation. The Core just acts like an air
83 // traffic controller here, forwarding incoming messages to appropriate 83 // traffic controller here, forwarding incoming messages to appropriate
84 // landing threads. 84 // landing threads.
85 virtual void OnSyncCycleCompleted( 85 virtual void OnSyncCycleCompleted(
86 const csync::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; 86 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE;
87 virtual void OnInitializationComplete( 87 virtual void OnInitializationComplete(
88 const csync::WeakHandle<csync::JsBackend>& js_backend, 88 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
89 bool success) OVERRIDE; 89 bool success) OVERRIDE;
90 virtual void OnConnectionStatusChange( 90 virtual void OnConnectionStatusChange(
91 csync::ConnectionStatus status) OVERRIDE; 91 syncer::ConnectionStatus status) OVERRIDE;
92 virtual void OnPassphraseRequired( 92 virtual void OnPassphraseRequired(
93 csync::PassphraseRequiredReason reason, 93 syncer::PassphraseRequiredReason reason,
94 const sync_pb::EncryptedData& pending_keys) OVERRIDE; 94 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
95 virtual void OnPassphraseAccepted() OVERRIDE; 95 virtual void OnPassphraseAccepted() OVERRIDE;
96 virtual void OnBootstrapTokenUpdated( 96 virtual void OnBootstrapTokenUpdated(
97 const std::string& bootstrap_token) OVERRIDE; 97 const std::string& bootstrap_token) OVERRIDE;
98 virtual void OnStopSyncingPermanently() OVERRIDE; 98 virtual void OnStopSyncingPermanently() OVERRIDE;
99 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; 99 virtual void OnUpdatedToken(const std::string& token) OVERRIDE;
100 virtual void OnEncryptedTypesChanged( 100 virtual void OnEncryptedTypesChanged(
101 syncable::ModelTypeSet encrypted_types, 101 syncable::ModelTypeSet encrypted_types,
102 bool encrypt_everything) OVERRIDE; 102 bool encrypt_everything) OVERRIDE;
103 virtual void OnEncryptionComplete() OVERRIDE; 103 virtual void OnEncryptionComplete() OVERRIDE;
104 virtual void OnActionableError( 104 virtual void OnActionableError(
105 const csync::SyncProtocolError& sync_error) OVERRIDE; 105 const syncer::SyncProtocolError& sync_error) OVERRIDE;
106 106
107 // Note: 107 // Note:
108 // 108 //
109 // The Do* methods are the various entry points from our 109 // The Do* methods are the various entry points from our
110 // SyncBackendHost. They are all called on the sync thread to 110 // SyncBackendHost. They are all called on the sync thread to
111 // actually perform synchronous (and potentially blocking) syncapi 111 // actually perform synchronous (and potentially blocking) syncapi
112 // operations. 112 // operations.
113 // 113 //
114 // Called to perform initialization of the syncapi on behalf of 114 // Called to perform initialization of the syncapi on behalf of
115 // SyncBackendHost::Initialize. 115 // SyncBackendHost::Initialize.
116 void DoInitialize(const DoInitializeOptions& options); 116 void DoInitialize(const DoInitializeOptions& options);
117 117
118 // Called to perform credential update on behalf of 118 // Called to perform credential update on behalf of
119 // SyncBackendHost::UpdateCredentials 119 // SyncBackendHost::UpdateCredentials
120 void DoUpdateCredentials(const csync::SyncCredentials& credentials); 120 void DoUpdateCredentials(const syncer::SyncCredentials& credentials);
121 121
122 // Called when the user disables or enables a sync type. 122 // Called when the user disables or enables a sync type.
123 void DoUpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); 123 void DoUpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types);
124 124
125 // Called to tell the syncapi to start syncing (generally after 125 // Called to tell the syncapi to start syncing (generally after
126 // initialization and authentication). 126 // initialization and authentication).
127 void DoStartSyncing(const csync::ModelSafeRoutingInfo& routing_info); 127 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info);
128 128
129 // Called to cleanup disabled types. 129 // Called to cleanup disabled types.
130 void DoRequestCleanupDisabledTypes( 130 void DoRequestCleanupDisabledTypes(
131 const csync::ModelSafeRoutingInfo& routing_info); 131 const syncer::ModelSafeRoutingInfo& routing_info);
132 132
133 // Called to set the passphrase for encryption. 133 // Called to set the passphrase for encryption.
134 void DoSetEncryptionPassphrase(const std::string& passphrase, 134 void DoSetEncryptionPassphrase(const std::string& passphrase,
135 bool is_explicit); 135 bool is_explicit);
136 136
137 // Called to decrypt the pending keys. 137 // Called to decrypt the pending keys.
138 void DoSetDecryptionPassphrase(const std::string& passphrase); 138 void DoSetDecryptionPassphrase(const std::string& passphrase);
139 139
140 // Called to turn on encryption of all sync data as well as 140 // Called to turn on encryption of all sync data as well as
141 // reencrypt everything. 141 // reencrypt everything.
(...skipping 11 matching lines...) Expand all
153 // a blocking call). This causes syncapi thread-exit handlers 153 // a blocking call). This causes syncapi thread-exit handlers
154 // to run and make use of cached pointers to various components 154 // to run and make use of cached pointers to various components
155 // owned implicitly by us. 155 // owned implicitly by us.
156 // 3) Destroy this Core. That will delete syncapi components in a 156 // 3) Destroy this Core. That will delete syncapi components in a
157 // safe order because the thread that was using them has exited 157 // safe order because the thread that was using them has exited
158 // (in step 2). 158 // (in step 2).
159 void DoStopSyncManagerForShutdown(const base::Closure& closure); 159 void DoStopSyncManagerForShutdown(const base::Closure& closure);
160 void DoShutdown(bool stopping_sync); 160 void DoShutdown(bool stopping_sync);
161 161
162 virtual void DoRequestConfig( 162 virtual void DoRequestConfig(
163 const csync::ModelSafeRoutingInfo& routing_info, 163 const syncer::ModelSafeRoutingInfo& routing_info,
164 syncable::ModelTypeSet types_to_config, 164 syncable::ModelTypeSet types_to_config,
165 csync::ConfigureReason reason); 165 syncer::ConfigureReason reason);
166 166
167 // Start the configuration mode. |callback| is called on the sync 167 // Start the configuration mode. |callback| is called on the sync
168 // thread. 168 // thread.
169 virtual void DoStartConfiguration(const base::Closure& callback); 169 virtual void DoStartConfiguration(const base::Closure& callback);
170 170
171 // Set the base request context to use when making HTTP calls. 171 // Set the base request context to use when making HTTP calls.
172 // This method will add a reference to the context to persist it 172 // This method will add a reference to the context to persist it
173 // on the IO thread. Must be removed from IO thread. 173 // on the IO thread. Must be removed from IO thread.
174 174
175 csync::SyncManager* sync_manager() { return sync_manager_.get(); } 175 syncer::SyncManager* sync_manager() { return sync_manager_.get(); }
176 176
177 // Delete the sync data folder to cleanup backend data. Happens the first 177 // Delete the sync data folder to cleanup backend data. Happens the first
178 // time sync is enabled for a user (to prevent accidentally reusing old 178 // time sync is enabled for a user (to prevent accidentally reusing old
179 // sync databases), as well as shutdown when you're no longer syncing. 179 // sync databases), as well as shutdown when you're no longer syncing.
180 void DeleteSyncDataFolder(); 180 void DeleteSyncDataFolder();
181 181
182 // A callback from the SyncerThread when it is safe to continue config. 182 // A callback from the SyncerThread when it is safe to continue config.
183 void FinishConfigureDataTypes(); 183 void FinishConfigureDataTypes();
184 184
185 private: 185 private:
(...skipping 16 matching lines...) Expand all
202 // initialization. 202 // initialization.
203 void SaveChanges(); 203 void SaveChanges();
204 204
205 // Name used for debugging. 205 // Name used for debugging.
206 const std::string name_; 206 const std::string name_;
207 207
208 // Path of the folder that stores the sync data files. 208 // Path of the folder that stores the sync data files.
209 const FilePath sync_data_folder_path_; 209 const FilePath sync_data_folder_path_;
210 210
211 // Our parent SyncBackendHost. 211 // Our parent SyncBackendHost.
212 csync::WeakHandle<SyncBackendHost> host_; 212 syncer::WeakHandle<SyncBackendHost> host_;
213 213
214 // The loop where all the sync backend operations happen. 214 // The loop where all the sync backend operations happen.
215 // Non-NULL only between calls to DoInitialize() and DoShutdown(). 215 // Non-NULL only between calls to DoInitialize() and DoShutdown().
216 MessageLoop* sync_loop_; 216 MessageLoop* sync_loop_;
217 217
218 // Our parent's registrar (not owned). Non-NULL only between 218 // Our parent's registrar (not owned). Non-NULL only between
219 // calls to DoInitialize() and DoShutdown(). 219 // calls to DoInitialize() and DoShutdown().
220 SyncBackendRegistrar* registrar_; 220 SyncBackendRegistrar* registrar_;
221 221
222 // The timer used to periodically call SaveChanges. 222 // The timer used to periodically call SaveChanges.
223 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; 223 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_;
224 224
225 // Our encryptor, which uses Chrome's encryption functions. 225 // Our encryptor, which uses Chrome's encryption functions.
226 ChromeEncryptor encryptor_; 226 ChromeEncryptor encryptor_;
227 227
228 // The top-level syncapi entry point. Lives on the sync thread. 228 // The top-level syncapi entry point. Lives on the sync thread.
229 scoped_ptr<csync::SyncManager> sync_manager_; 229 scoped_ptr<syncer::SyncManager> sync_manager_;
230 230
231 DISALLOW_COPY_AND_ASSIGN(Core); 231 DISALLOW_COPY_AND_ASSIGN(Core);
232 }; 232 };
233 233
234 namespace { 234 namespace {
235 235
236 // Parses the given command line for notifier options. 236 // Parses the given command line for notifier options.
237 notifier::NotifierOptions ParseNotifierOptions( 237 notifier::NotifierOptions ParseNotifierOptions(
238 const CommandLine& command_line, 238 const CommandLine& command_line,
239 const scoped_refptr<net::URLRequestContextGetter>& 239 const scoped_refptr<net::URLRequestContextGetter>&
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 sync_thread_("Chrome_SyncThread"), 305 sync_thread_("Chrome_SyncThread"),
306 frontend_loop_(MessageLoop::current()), 306 frontend_loop_(MessageLoop::current()),
307 profile_(profile), 307 profile_(profile),
308 name_("Unknown"), 308 name_("Unknown"),
309 initialization_state_(NOT_ATTEMPTED), 309 initialization_state_(NOT_ATTEMPTED),
310 chrome_sync_notification_bridge_(profile_), 310 chrome_sync_notification_bridge_(profile_),
311 sync_notifier_factory_( 311 sync_notifier_factory_(
312 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 312 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
313 profile_->GetRequestContext()), 313 profile_->GetRequestContext()),
314 content::GetUserAgent(GURL()), 314 content::GetUserAgent(GURL()),
315 base::WeakPtr<csync::InvalidationStateTracker>()), 315 base::WeakPtr<syncer::InvalidationStateTracker>()),
316 frontend_(NULL) { 316 frontend_(NULL) {
317 } 317 }
318 318
319 SyncBackendHost::~SyncBackendHost() { 319 SyncBackendHost::~SyncBackendHost() {
320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
321 DCHECK(!registrar_.get()); 321 DCHECK(!registrar_.get());
322 } 322 }
323 323
324 namespace { 324 namespace {
325 325
(...skipping 22 matching lines...) Expand all
348 return user_agent; 348 return user_agent;
349 } 349 }
350 350
351 user_agent += version_info.Version(); 351 user_agent += version_info.Version();
352 user_agent += " (" + version_info.LastChange() + ")"; 352 user_agent += " (" + version_info.LastChange() + ")";
353 if (!version_info.IsOfficialBuild()) 353 if (!version_info.IsOfficialBuild())
354 user_agent += "-devel"; 354 user_agent += "-devel";
355 return user_agent; 355 return user_agent;
356 } 356 }
357 357
358 csync::HttpPostProviderFactory* MakeHttpBridgeFactory( 358 syncer::HttpPostProviderFactory* MakeHttpBridgeFactory(
359 const scoped_refptr<net::URLRequestContextGetter>& getter) { 359 const scoped_refptr<net::URLRequestContextGetter>& getter) {
360 return new HttpBridgeFactory(getter, MakeUserAgentForSyncApi()); 360 return new HttpBridgeFactory(getter, MakeUserAgentForSyncApi());
361 } 361 }
362 362
363 } // namespace 363 } // namespace
364 364
365 void SyncBackendHost::Initialize( 365 void SyncBackendHost::Initialize(
366 SyncFrontend* frontend, 366 SyncFrontend* frontend,
367 const csync::WeakHandle<csync::JsEventHandler>& event_handler, 367 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
368 const GURL& sync_service_url, 368 const GURL& sync_service_url,
369 syncable::ModelTypeSet initial_types, 369 syncable::ModelTypeSet initial_types,
370 const SyncCredentials& credentials, 370 const SyncCredentials& credentials,
371 bool delete_sync_data_folder, 371 bool delete_sync_data_folder,
372 csync::UnrecoverableErrorHandler* unrecoverable_error_handler, 372 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
373 csync::ReportUnrecoverableErrorFunction 373 syncer::ReportUnrecoverableErrorFunction
374 report_unrecoverable_error_function) { 374 report_unrecoverable_error_function) {
375 if (!sync_thread_.Start()) 375 if (!sync_thread_.Start())
376 return; 376 return;
377 377
378 frontend_ = frontend; 378 frontend_ = frontend;
379 DCHECK(frontend); 379 DCHECK(frontend);
380 380
381 syncable::ModelTypeSet initial_types_with_nigori(initial_types); 381 syncable::ModelTypeSet initial_types_with_nigori(initial_types);
382 CHECK(sync_prefs_.get()); 382 CHECK(sync_prefs_.get());
383 if (sync_prefs_->HasSyncSetupCompleted()) { 383 if (sync_prefs_->HasSyncSetupCompleted()) {
384 initial_types_with_nigori.Put(syncable::NIGORI); 384 initial_types_with_nigori.Put(syncable::NIGORI);
385 } 385 }
386 386
387 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori, 387 registrar_.reset(new SyncBackendRegistrar(initial_types_with_nigori,
388 name_, 388 name_,
389 profile_, 389 profile_,
390 sync_thread_.message_loop())); 390 sync_thread_.message_loop()));
391 csync::ModelSafeRoutingInfo routing_info; 391 syncer::ModelSafeRoutingInfo routing_info;
392 std::vector<csync::ModelSafeWorker*> workers; 392 std::vector<syncer::ModelSafeWorker*> workers;
393 registrar_->GetModelSafeRoutingInfo(&routing_info); 393 registrar_->GetModelSafeRoutingInfo(&routing_info);
394 registrar_->GetWorkers(&workers); 394 registrar_->GetWorkers(&workers);
395 395
396 initialization_state_ = CREATING_SYNC_MANAGER; 396 initialization_state_ = CREATING_SYNC_MANAGER;
397 InitCore(DoInitializeOptions( 397 InitCore(DoInitializeOptions(
398 sync_thread_.message_loop(), 398 sync_thread_.message_loop(),
399 registrar_.get(), 399 registrar_.get(),
400 routing_info, 400 routing_info,
401 workers, 401 workers,
402 &extensions_activity_monitor_, 402 &extensions_activity_monitor_,
403 event_handler, 403 event_handler,
404 sync_service_url, 404 sync_service_url,
405 base::Bind(&MakeHttpBridgeFactory, 405 base::Bind(&MakeHttpBridgeFactory,
406 make_scoped_refptr(profile_->GetRequestContext())), 406 make_scoped_refptr(profile_->GetRequestContext())),
407 credentials, 407 credentials,
408 &chrome_sync_notification_bridge_, 408 &chrome_sync_notification_bridge_,
409 &sync_notifier_factory_, 409 &sync_notifier_factory_,
410 delete_sync_data_folder, 410 delete_sync_data_folder,
411 sync_prefs_->GetEncryptionBootstrapToken(), 411 sync_prefs_->GetEncryptionBootstrapToken(),
412 csync::SyncManager::NON_TEST, 412 syncer::SyncManager::NON_TEST,
413 unrecoverable_error_handler, 413 unrecoverable_error_handler,
414 report_unrecoverable_error_function)); 414 report_unrecoverable_error_function));
415 } 415 }
416 416
417 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 417 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
418 sync_thread_.message_loop()->PostTask(FROM_HERE, 418 sync_thread_.message_loop()->PostTask(FROM_HERE,
419 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), 419 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(),
420 credentials)); 420 credentials));
421 } 421 }
422 422
423 void SyncBackendHost::StartSyncingWithServer() { 423 void SyncBackendHost::StartSyncingWithServer() {
424 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; 424 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
425 425
426 csync::ModelSafeRoutingInfo routing_info; 426 syncer::ModelSafeRoutingInfo routing_info;
427 registrar_->GetModelSafeRoutingInfo(&routing_info); 427 registrar_->GetModelSafeRoutingInfo(&routing_info);
428 428
429 sync_thread_.message_loop()->PostTask(FROM_HERE, 429 sync_thread_.message_loop()->PostTask(FROM_HERE,
430 base::Bind(&SyncBackendHost::Core::DoStartSyncing, 430 base::Bind(&SyncBackendHost::Core::DoStartSyncing,
431 core_.get(), routing_info)); 431 core_.get(), routing_info));
432 } 432 }
433 433
434 void SyncBackendHost::SetEncryptionPassphrase(const std::string& passphrase, 434 void SyncBackendHost::SetEncryptionPassphrase(const std::string& passphrase,
435 bool is_explicit) { 435 bool is_explicit) {
436 if (!IsNigoriEnabled()) { 436 if (!IsNigoriEnabled()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 stop_thread_start_time; 578 stop_thread_start_time;
579 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", 579 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime",
580 stop_sync_thread_time); 580 stop_sync_thread_time);
581 581
582 registrar_.reset(); 582 registrar_.reset();
583 frontend_ = NULL; 583 frontend_ = NULL;
584 core_ = NULL; // Releases reference to core_. 584 core_ = NULL; // Releases reference to core_.
585 } 585 }
586 586
587 void SyncBackendHost::ConfigureDataTypes( 587 void SyncBackendHost::ConfigureDataTypes(
588 csync::ConfigureReason reason, 588 syncer::ConfigureReason reason,
589 syncable::ModelTypeSet types_to_add, 589 syncable::ModelTypeSet types_to_add,
590 syncable::ModelTypeSet types_to_remove, 590 syncable::ModelTypeSet types_to_remove,
591 NigoriState nigori_state, 591 NigoriState nigori_state,
592 base::Callback<void(syncable::ModelTypeSet)> ready_task, 592 base::Callback<void(syncable::ModelTypeSet)> ready_task,
593 base::Callback<void()> retry_callback) { 593 base::Callback<void()> retry_callback) {
594 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; 594 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add;
595 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; 595 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove;
596 if (nigori_state == WITH_NIGORI) { 596 if (nigori_state == WITH_NIGORI) {
597 types_to_add_with_nigori.Put(syncable::NIGORI); 597 types_to_add_with_nigori.Put(syncable::NIGORI);
598 types_to_remove_with_nigori.Remove(syncable::NIGORI); 598 types_to_remove_with_nigori.Remove(syncable::NIGORI);
(...skipping 12 matching lines...) Expand all
611 pending_config_mode_state_->added_types = 611 pending_config_mode_state_->added_types =
612 registrar_->ConfigureDataTypes(types_to_add_with_nigori, 612 registrar_->ConfigureDataTypes(types_to_add_with_nigori,
613 types_to_remove_with_nigori); 613 types_to_remove_with_nigori);
614 pending_config_mode_state_->reason = reason; 614 pending_config_mode_state_->reason = reason;
615 pending_config_mode_state_->retry_callback = retry_callback; 615 pending_config_mode_state_->retry_callback = retry_callback;
616 616
617 // Cleanup disabled types before starting configuration so that 617 // Cleanup disabled types before starting configuration so that
618 // callers can assume that the data types are cleaned up once 618 // callers can assume that the data types are cleaned up once
619 // configuration is done. 619 // configuration is done.
620 if (!types_to_remove_with_nigori.Empty()) { 620 if (!types_to_remove_with_nigori.Empty()) {
621 csync::ModelSafeRoutingInfo routing_info; 621 syncer::ModelSafeRoutingInfo routing_info;
622 registrar_->GetModelSafeRoutingInfo(&routing_info); 622 registrar_->GetModelSafeRoutingInfo(&routing_info);
623 sync_thread_.message_loop()->PostTask( 623 sync_thread_.message_loop()->PostTask(
624 FROM_HERE, 624 FROM_HERE,
625 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes, 625 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes,
626 core_.get(), 626 core_.get(),
627 routing_info)); 627 routing_info));
628 } 628 }
629 629
630 StartConfiguration( 630 StartConfiguration(
631 base::Bind(&SyncBackendHost::Core::FinishConfigureDataTypes, 631 base::Bind(&SyncBackendHost::Core::FinishConfigureDataTypes,
632 core_.get())); 632 core_.get()));
633 } 633 }
634 634
635 void SyncBackendHost::StartConfiguration(const base::Closure& callback) { 635 void SyncBackendHost::StartConfiguration(const base::Closure& callback) {
636 // Put syncer in the config mode. DTM will put us in normal mode once it is 636 // Put syncer in the config mode. DTM will put us in normal mode once it is
637 // done. This is to ensure we dont do a normal sync when we are doing model 637 // done. This is to ensure we dont do a normal sync when we are doing model
638 // association. 638 // association.
639 sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 639 sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
640 &SyncBackendHost::Core::DoStartConfiguration, core_.get(), callback)); 640 &SyncBackendHost::Core::DoStartConfiguration, core_.get(), callback));
641 } 641 }
642 642
643 void SyncBackendHost::EnableEncryptEverything() { 643 void SyncBackendHost::EnableEncryptEverything() {
644 sync_thread_.message_loop()->PostTask(FROM_HERE, 644 sync_thread_.message_loop()->PostTask(FROM_HERE,
645 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything, 645 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything,
646 core_.get())); 646 core_.get()));
647 } 647 }
648 648
649 void SyncBackendHost::ActivateDataType( 649 void SyncBackendHost::ActivateDataType(
650 syncable::ModelType type, csync::ModelSafeGroup group, 650 syncable::ModelType type, syncer::ModelSafeGroup group,
651 ChangeProcessor* change_processor) { 651 ChangeProcessor* change_processor) {
652 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); 652 registrar_->ActivateDataType(type, group, change_processor, GetUserShare());
653 } 653 }
654 654
655 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) { 655 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) {
656 registrar_->DeactivateDataType(type); 656 registrar_->DeactivateDataType(type);
657 } 657 }
658 658
659 csync::UserShare* SyncBackendHost::GetUserShare() const { 659 syncer::UserShare* SyncBackendHost::GetUserShare() const {
660 DCHECK(initialized()); 660 DCHECK(initialized());
661 return core_->sync_manager()->GetUserShare(); 661 return core_->sync_manager()->GetUserShare();
662 } 662 }
663 663
664 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { 664 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() {
665 DCHECK(initialized()); 665 DCHECK(initialized());
666 return core_->sync_manager()->GetDetailedStatus(); 666 return core_->sync_manager()->GetDetailedStatus();
667 } 667 }
668 668
669 SyncSessionSnapshot SyncBackendHost::GetLastSessionSnapshot() const { 669 SyncSessionSnapshot SyncBackendHost::GetLastSessionSnapshot() const {
(...skipping 12 matching lines...) Expand all
682 bool SyncBackendHost::IsUsingExplicitPassphrase() { 682 bool SyncBackendHost::IsUsingExplicitPassphrase() {
683 // This should only be called once the nigori node has been downloaded, as 683 // This should only be called once the nigori node has been downloaded, as
684 // otherwise we have no idea what kind of passphrase we are using. This will 684 // otherwise we have no idea what kind of passphrase we are using. This will
685 // NOTREACH in sync_manager and return false if we fail to load the nigori 685 // NOTREACH in sync_manager and return false if we fail to load the nigori
686 // node. 686 // node.
687 return IsNigoriEnabled() && 687 return IsNigoriEnabled() &&
688 core_->sync_manager()->IsUsingExplicitPassphrase(); 688 core_->sync_manager()->IsUsingExplicitPassphrase();
689 } 689 }
690 690
691 bool SyncBackendHost::IsCryptographerReady( 691 bool SyncBackendHost::IsCryptographerReady(
692 const csync::BaseTransaction* trans) const { 692 const syncer::BaseTransaction* trans) const {
693 return initialized() && trans->GetCryptographer()->is_ready(); 693 return initialized() && trans->GetCryptographer()->is_ready();
694 } 694 }
695 695
696 void SyncBackendHost::GetModelSafeRoutingInfo( 696 void SyncBackendHost::GetModelSafeRoutingInfo(
697 csync::ModelSafeRoutingInfo* out) const { 697 syncer::ModelSafeRoutingInfo* out) const {
698 if (initialized()) { 698 if (initialized()) {
699 CHECK(registrar_.get()); 699 CHECK(registrar_.get());
700 registrar_->GetModelSafeRoutingInfo(out); 700 registrar_->GetModelSafeRoutingInfo(out);
701 } else { 701 } else {
702 NOTREACHED(); 702 NOTREACHED();
703 } 703 }
704 } 704 }
705 705
706 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { 706 void SyncBackendHost::InitCore(const DoInitializeOptions& options) {
707 sync_thread_.message_loop()->PostTask(FROM_HERE, 707 sync_thread_.message_loop()->PostTask(FROM_HERE,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 // In the case of additions, on the next sync cycle, the syncer should 784 // In the case of additions, on the next sync cycle, the syncer should
785 // notice that the routing info has changed and start the process of 785 // notice that the routing info has changed and start the process of
786 // downloading updates for newly added data types. Once this is 786 // downloading updates for newly added data types. Once this is
787 // complete, the configure_state_.ready_task_ is run via an 787 // complete, the configure_state_.ready_task_ is run via an
788 // OnInitializationComplete notification. 788 // OnInitializationComplete notification.
789 789
790 SDVLOG(1) << "Syncer in config mode. SBH executing " 790 SDVLOG(1) << "Syncer in config mode. SBH executing "
791 << "FinishConfigureDataTypesOnFrontendLoop"; 791 << "FinishConfigureDataTypesOnFrontendLoop";
792 792
793 793
794 csync::ModelSafeRoutingInfo routing_info; 794 syncer::ModelSafeRoutingInfo routing_info;
795 registrar_->GetModelSafeRoutingInfo(&routing_info); 795 registrar_->GetModelSafeRoutingInfo(&routing_info);
796 const syncable::ModelTypeSet enabled_types = 796 const syncable::ModelTypeSet enabled_types =
797 GetRoutingInfoTypes(routing_info); 797 GetRoutingInfoTypes(routing_info);
798 798
799 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has 799 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has
800 // to happen on the UI thread. 800 // to happen on the UI thread.
801 chrome_sync_notification_bridge_.UpdateEnabledTypes(enabled_types); 801 chrome_sync_notification_bridge_.UpdateEnabledTypes(enabled_types);
802 802
803 if (pending_config_mode_state_->added_types.Empty() && 803 if (pending_config_mode_state_->added_types.Empty() &&
804 !core_->sync_manager()->InitialSyncEndedTypes().HasAll(enabled_types)) { 804 !core_->sync_manager()->InitialSyncEndedTypes().HasAll(enabled_types)) {
805 805
806 // TODO(tim): Log / UMA / count this somehow? 806 // TODO(tim): Log / UMA / count this somehow?
807 // Add only the types with empty progress markers. Note: it is possible 807 // Add only the types with empty progress markers. Note: it is possible
808 // that some types have their initial_sync_ended be false but with non 808 // that some types have their initial_sync_ended be false but with non
809 // empty progress marker. Which is ok as the rest of the changes would 809 // empty progress marker. Which is ok as the rest of the changes would
810 // be downloaded on a regular nudge and initial_sync_ended should be set 810 // be downloaded on a regular nudge and initial_sync_ended should be set
811 // to true. However this is a very corner case. So it is not explicitly 811 // to true. However this is a very corner case. So it is not explicitly
812 // handled. 812 // handled.
813 pending_config_mode_state_->added_types = 813 pending_config_mode_state_->added_types =
814 csync::GetTypesWithEmptyProgressMarkerToken(enabled_types, 814 syncer::GetTypesWithEmptyProgressMarkerToken(enabled_types,
815 GetUserShare()); 815 GetUserShare());
816 } 816 }
817 817
818 // If we've added types, we always want to request a nudge/config (even if 818 // If we've added types, we always want to request a nudge/config (even if
819 // the initial sync is ended), in case we could not decrypt the data. 819 // the initial sync is ended), in case we could not decrypt the data.
820 if (pending_config_mode_state_->added_types.Empty()) { 820 if (pending_config_mode_state_->added_types.Empty()) {
821 SDVLOG(1) << "No new types added; calling ready_task directly"; 821 SDVLOG(1) << "No new types added; calling ready_task directly";
822 // No new types - just notify the caller that the types are available. 822 // No new types - just notify the caller that the types are available.
823 const syncable::ModelTypeSet failed_configuration_types; 823 const syncable::ModelTypeSet failed_configuration_types;
824 pending_config_mode_state_->ready_task.Run(failed_configuration_types); 824 pending_config_mode_state_->ready_task.Run(failed_configuration_types);
825 } else { 825 } else {
826 pending_download_state_.reset(pending_config_mode_state_.release()); 826 pending_download_state_.reset(pending_config_mode_state_.release());
827 827
828 // Always configure nigori if it's enabled. 828 // Always configure nigori if it's enabled.
829 syncable::ModelTypeSet types_to_config = 829 syncable::ModelTypeSet types_to_config =
830 pending_download_state_->added_types; 830 pending_download_state_->added_types;
831 if (IsNigoriEnabled()) { 831 if (IsNigoriEnabled()) {
832 // Note: Nigori is the only type that gets added with a nonempty 832 // Note: Nigori is the only type that gets added with a nonempty
833 // progress marker during config. If the server returns a migration 833 // progress marker during config. If the server returns a migration
834 // error then we will go into unrecoverable error. We dont handle it 834 // error then we will go into unrecoverable error. We dont handle it
835 // explicitly because server might help us out here by not sending a 835 // explicitly because server might help us out here by not sending a
836 // migraiton error for nigori during config. 836 // migraiton error for nigori during config.
837 types_to_config.Put(syncable::NIGORI); 837 types_to_config.Put(syncable::NIGORI);
838 } 838 }
839 SDVLOG(1) << "Types " 839 SDVLOG(1) << "Types "
840 << syncable::ModelTypeSetToString(types_to_config) 840 << syncable::ModelTypeSetToString(types_to_config)
841 << " added; calling DoRequestConfig"; 841 << " added; calling DoRequestConfig";
842 csync::ModelSafeRoutingInfo routing_info; 842 syncer::ModelSafeRoutingInfo routing_info;
843 registrar_->GetModelSafeRoutingInfo(&routing_info); 843 registrar_->GetModelSafeRoutingInfo(&routing_info);
844 sync_thread_.message_loop()->PostTask(FROM_HERE, 844 sync_thread_.message_loop()->PostTask(FROM_HERE,
845 base::Bind(&SyncBackendHost::Core::DoRequestConfig, 845 base::Bind(&SyncBackendHost::Core::DoRequestConfig,
846 core_.get(), 846 core_.get(),
847 routing_info, 847 routing_info,
848 types_to_config, 848 types_to_config,
849 pending_download_state_->reason)); 849 pending_download_state_->reason));
850 } 850 }
851 851
852 pending_config_mode_state_.reset(); 852 pending_config_mode_state_.reset();
853 853
854 // Notify SyncManager (especially the notification listener) about new types. 854 // Notify SyncManager (especially the notification listener) about new types.
855 sync_thread_.message_loop()->PostTask(FROM_HERE, 855 sync_thread_.message_loop()->PostTask(FROM_HERE,
856 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(), 856 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(),
857 enabled_types)); 857 enabled_types));
858 } 858 }
859 859
860 bool SyncBackendHost::IsDownloadingNigoriForTest() const { 860 bool SyncBackendHost::IsDownloadingNigoriForTest() const {
861 return initialization_state_ == DOWNLOADING_NIGORI; 861 return initialization_state_ == DOWNLOADING_NIGORI;
862 } 862 }
863 863
864 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 864 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
865 MessageLoop* sync_loop, 865 MessageLoop* sync_loop,
866 SyncBackendRegistrar* registrar, 866 SyncBackendRegistrar* registrar,
867 const csync::ModelSafeRoutingInfo& routing_info, 867 const syncer::ModelSafeRoutingInfo& routing_info,
868 const std::vector<csync::ModelSafeWorker*>& workers, 868 const std::vector<syncer::ModelSafeWorker*>& workers,
869 csync::ExtensionsActivityMonitor* extensions_activity_monitor, 869 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
870 const csync::WeakHandle<csync::JsEventHandler>& event_handler, 870 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
871 const GURL& service_url, 871 const GURL& service_url,
872 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 872 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
873 const csync::SyncCredentials& credentials, 873 const syncer::SyncCredentials& credentials,
874 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, 874 ChromeSyncNotificationBridge* chrome_sync_notification_bridge,
875 csync::SyncNotifierFactory* sync_notifier_factory, 875 syncer::SyncNotifierFactory* sync_notifier_factory,
876 bool delete_sync_data_folder, 876 bool delete_sync_data_folder,
877 const std::string& restored_key_for_bootstrapping, 877 const std::string& restored_key_for_bootstrapping,
878 csync::SyncManager::TestingMode testing_mode, 878 syncer::SyncManager::TestingMode testing_mode,
879 csync::UnrecoverableErrorHandler* unrecoverable_error_handler, 879 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
880 csync::ReportUnrecoverableErrorFunction 880 syncer::ReportUnrecoverableErrorFunction
881 report_unrecoverable_error_function) 881 report_unrecoverable_error_function)
882 : sync_loop(sync_loop), 882 : sync_loop(sync_loop),
883 registrar(registrar), 883 registrar(registrar),
884 routing_info(routing_info), 884 routing_info(routing_info),
885 workers(workers), 885 workers(workers),
886 extensions_activity_monitor(extensions_activity_monitor), 886 extensions_activity_monitor(extensions_activity_monitor),
887 event_handler(event_handler), 887 event_handler(event_handler),
888 service_url(service_url), 888 service_url(service_url),
889 make_http_bridge_factory_fn(make_http_bridge_factory_fn), 889 make_http_bridge_factory_fn(make_http_bridge_factory_fn),
890 credentials(credentials), 890 credentials(credentials),
(...skipping 20 matching lines...) Expand all
911 DCHECK(backend.get()); 911 DCHECK(backend.get());
912 } 912 }
913 913
914 SyncBackendHost::Core::~Core() { 914 SyncBackendHost::Core::~Core() {
915 DCHECK(!sync_manager_.get()); 915 DCHECK(!sync_manager_.get());
916 DCHECK(!sync_loop_); 916 DCHECK(!sync_loop_);
917 } 917 }
918 918
919 SyncBackendHost::PendingConfigureDataTypesState:: 919 SyncBackendHost::PendingConfigureDataTypesState::
920 PendingConfigureDataTypesState() 920 PendingConfigureDataTypesState()
921 : reason(csync::CONFIGURE_REASON_UNKNOWN), 921 : reason(syncer::CONFIGURE_REASON_UNKNOWN),
922 retry_in_progress(false) {} 922 retry_in_progress(false) {}
923 923
924 SyncBackendHost::PendingConfigureDataTypesState:: 924 SyncBackendHost::PendingConfigureDataTypesState::
925 ~PendingConfigureDataTypesState() {} 925 ~PendingConfigureDataTypesState() {}
926 926
927 void SyncBackendHost::Core::OnSyncCycleCompleted( 927 void SyncBackendHost::Core::OnSyncCycleCompleted(
928 const SyncSessionSnapshot& snapshot) { 928 const SyncSessionSnapshot& snapshot) {
929 if (!sync_loop_) 929 if (!sync_loop_)
930 return; 930 return;
931 DCHECK_EQ(MessageLoop::current(), sync_loop_); 931 DCHECK_EQ(MessageLoop::current(), sync_loop_);
932 host_.Call( 932 host_.Call(
933 FROM_HERE, 933 FROM_HERE,
934 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, 934 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop,
935 snapshot); 935 snapshot);
936 } 936 }
937 937
938 938
939 void SyncBackendHost::Core::OnInitializationComplete( 939 void SyncBackendHost::Core::OnInitializationComplete(
940 const csync::WeakHandle<csync::JsBackend>& js_backend, 940 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
941 bool success) { 941 bool success) {
942 DCHECK_EQ(MessageLoop::current(), sync_loop_); 942 DCHECK_EQ(MessageLoop::current(), sync_loop_);
943 host_.Call( 943 host_.Call(
944 FROM_HERE, 944 FROM_HERE,
945 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 945 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
946 js_backend, success); 946 js_backend, success);
947 947
948 if (success) { 948 if (success) {
949 // Initialization is complete, so we can schedule recurring SaveChanges. 949 // Initialization is complete, so we can schedule recurring SaveChanges.
950 sync_loop_->PostTask(FROM_HERE, 950 sync_loop_->PostTask(FROM_HERE,
951 base::Bind(&Core::StartSavingChanges, this)); 951 base::Bind(&Core::StartSavingChanges, this));
952 } 952 }
953 } 953 }
954 954
955 void SyncBackendHost::Core::OnConnectionStatusChange( 955 void SyncBackendHost::Core::OnConnectionStatusChange(
956 csync::ConnectionStatus status) { 956 syncer::ConnectionStatus status) {
957 if (!sync_loop_) 957 if (!sync_loop_)
958 return; 958 return;
959 DCHECK_EQ(MessageLoop::current(), sync_loop_); 959 DCHECK_EQ(MessageLoop::current(), sync_loop_);
960 host_.Call( 960 host_.Call(
961 FROM_HERE, 961 FROM_HERE,
962 &SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop, status); 962 &SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop, status);
963 } 963 }
964 964
965 void SyncBackendHost::Core::OnPassphraseRequired( 965 void SyncBackendHost::Core::OnPassphraseRequired(
966 csync::PassphraseRequiredReason reason, 966 syncer::PassphraseRequiredReason reason,
967 const sync_pb::EncryptedData& pending_keys) { 967 const sync_pb::EncryptedData& pending_keys) {
968 if (!sync_loop_) 968 if (!sync_loop_)
969 return; 969 return;
970 DCHECK_EQ(MessageLoop::current(), sync_loop_); 970 DCHECK_EQ(MessageLoop::current(), sync_loop_);
971 host_.Call( 971 host_.Call(
972 FROM_HERE, 972 FROM_HERE,
973 &SyncBackendHost::NotifyPassphraseRequired, reason, pending_keys); 973 &SyncBackendHost::NotifyPassphraseRequired, reason, pending_keys);
974 } 974 }
975 975
976 void SyncBackendHost::Core::OnPassphraseAccepted() { 976 void SyncBackendHost::Core::OnPassphraseAccepted() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 if (!sync_loop_) 1027 if (!sync_loop_)
1028 return; 1028 return;
1029 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1029 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1030 // NOTE: We're in a transaction. 1030 // NOTE: We're in a transaction.
1031 host_.Call( 1031 host_.Call(
1032 FROM_HERE, 1032 FROM_HERE,
1033 &SyncBackendHost::NotifyEncryptionComplete); 1033 &SyncBackendHost::NotifyEncryptionComplete);
1034 } 1034 }
1035 1035
1036 void SyncBackendHost::Core::OnActionableError( 1036 void SyncBackendHost::Core::OnActionableError(
1037 const csync::SyncProtocolError& sync_error) { 1037 const syncer::SyncProtocolError& sync_error) {
1038 if (!sync_loop_) 1038 if (!sync_loop_)
1039 return; 1039 return;
1040 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1040 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1041 host_.Call( 1041 host_.Call(
1042 FROM_HERE, 1042 FROM_HERE,
1043 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1043 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1044 sync_error); 1044 sync_error);
1045 } 1045 }
1046 1046
1047 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 1047 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
1048 DCHECK(!sync_loop_); 1048 DCHECK(!sync_loop_);
1049 sync_loop_ = options.sync_loop; 1049 sync_loop_ = options.sync_loop;
1050 DCHECK(sync_loop_); 1050 DCHECK(sync_loop_);
1051 1051
1052 // Blow away the partial or corrupt sync data folder before doing any more 1052 // Blow away the partial or corrupt sync data folder before doing any more
1053 // initialization, if necessary. 1053 // initialization, if necessary.
1054 if (options.delete_sync_data_folder) { 1054 if (options.delete_sync_data_folder) {
1055 DeleteSyncDataFolder(); 1055 DeleteSyncDataFolder();
1056 } 1056 }
1057 1057
1058 // Make sure that the directory exists before initializing the backend. 1058 // Make sure that the directory exists before initializing the backend.
1059 // If it already exists, this will do no harm. 1059 // If it already exists, this will do no harm.
1060 bool success = file_util::CreateDirectory(sync_data_folder_path_); 1060 bool success = file_util::CreateDirectory(sync_data_folder_path_);
1061 DCHECK(success); 1061 DCHECK(success);
1062 1062
1063 DCHECK(!registrar_); 1063 DCHECK(!registrar_);
1064 registrar_ = options.registrar; 1064 registrar_ = options.registrar;
1065 DCHECK(registrar_); 1065 DCHECK(registrar_);
1066 1066
1067 sync_manager_.reset(new csync::SyncManager(name_)); 1067 sync_manager_.reset(new syncer::SyncManager(name_));
1068 sync_manager_->AddObserver(this); 1068 sync_manager_->AddObserver(this);
1069 success = sync_manager_->Init( 1069 success = sync_manager_->Init(
1070 sync_data_folder_path_, 1070 sync_data_folder_path_,
1071 options.event_handler, 1071 options.event_handler,
1072 options.service_url.host() + options.service_url.path(), 1072 options.service_url.host() + options.service_url.path(),
1073 options.service_url.EffectiveIntPort(), 1073 options.service_url.EffectiveIntPort(),
1074 options.service_url.SchemeIsSecure(), 1074 options.service_url.SchemeIsSecure(),
1075 BrowserThread::GetBlockingPool(), 1075 BrowserThread::GetBlockingPool(),
1076 options.make_http_bridge_factory_fn.Run(), 1076 options.make_http_bridge_factory_fn.Run(),
1077 options.routing_info, 1077 options.routing_info,
(...skipping 29 matching lines...) Expand all
1107 sync_manager_->UpdateCredentials(credentials); 1107 sync_manager_->UpdateCredentials(credentials);
1108 } 1108 }
1109 1109
1110 void SyncBackendHost::Core::DoUpdateEnabledTypes( 1110 void SyncBackendHost::Core::DoUpdateEnabledTypes(
1111 const syncable::ModelTypeSet& enabled_types) { 1111 const syncable::ModelTypeSet& enabled_types) {
1112 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1112 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1113 sync_manager_->UpdateEnabledTypes(enabled_types); 1113 sync_manager_->UpdateEnabledTypes(enabled_types);
1114 } 1114 }
1115 1115
1116 void SyncBackendHost::Core::DoStartSyncing( 1116 void SyncBackendHost::Core::DoStartSyncing(
1117 const csync::ModelSafeRoutingInfo& routing_info) { 1117 const syncer::ModelSafeRoutingInfo& routing_info) {
1118 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1118 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1119 sync_manager_->StartSyncingNormally(routing_info); 1119 sync_manager_->StartSyncingNormally(routing_info);
1120 } 1120 }
1121 1121
1122 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes( 1122 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes(
1123 const csync::ModelSafeRoutingInfo& routing_info) { 1123 const syncer::ModelSafeRoutingInfo& routing_info) {
1124 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1124 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1125 sync_manager_->RequestCleanupDisabledTypes(routing_info); 1125 sync_manager_->RequestCleanupDisabledTypes(routing_info);
1126 } 1126 }
1127 1127
1128 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1128 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1129 const std::string& passphrase, 1129 const std::string& passphrase,
1130 bool is_explicit) { 1130 bool is_explicit) {
1131 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1131 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1132 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); 1132 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit);
1133 } 1133 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1170
1171 if (sync_disabled) 1171 if (sync_disabled)
1172 DeleteSyncDataFolder(); 1172 DeleteSyncDataFolder();
1173 1173
1174 sync_loop_ = NULL; 1174 sync_loop_ = NULL;
1175 1175
1176 host_.Reset(); 1176 host_.Reset();
1177 } 1177 }
1178 1178
1179 void SyncBackendHost::Core::DoRequestConfig( 1179 void SyncBackendHost::Core::DoRequestConfig(
1180 const csync::ModelSafeRoutingInfo& routing_info, 1180 const syncer::ModelSafeRoutingInfo& routing_info,
1181 syncable::ModelTypeSet types_to_config, 1181 syncable::ModelTypeSet types_to_config,
1182 csync::ConfigureReason reason) { 1182 syncer::ConfigureReason reason) {
1183 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1183 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1184 sync_manager_->RequestConfig(routing_info, types_to_config, reason); 1184 sync_manager_->RequestConfig(routing_info, types_to_config, reason);
1185 } 1185 }
1186 1186
1187 void SyncBackendHost::Core::DoStartConfiguration( 1187 void SyncBackendHost::Core::DoStartConfiguration(
1188 const base::Closure& callback) { 1188 const base::Closure& callback) {
1189 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1189 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1190 sync_manager_->StartConfigurationMode(callback); 1190 sync_manager_->StartConfigurationMode(callback);
1191 } 1191 }
1192 1192
(...skipping 24 matching lines...) Expand all
1217 this, &Core::SaveChanges); 1217 this, &Core::SaveChanges);
1218 } 1218 }
1219 1219
1220 void SyncBackendHost::Core::SaveChanges() { 1220 void SyncBackendHost::Core::SaveChanges() {
1221 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1221 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1222 sync_manager_->SaveChanges(); 1222 sync_manager_->SaveChanges();
1223 } 1223 }
1224 1224
1225 void SyncBackendHost::AddExperimentalTypes() { 1225 void SyncBackendHost::AddExperimentalTypes() {
1226 CHECK(initialized()); 1226 CHECK(initialized());
1227 csync::Experiments experiments; 1227 syncer::Experiments experiments;
1228 if (core_->sync_manager()->ReceivedExperiment(&experiments)) 1228 if (core_->sync_manager()->ReceivedExperiment(&experiments))
1229 frontend_->OnExperimentsChanged(experiments); 1229 frontend_->OnExperimentsChanged(experiments);
1230 } 1230 }
1231 1231
1232 void SyncBackendHost::OnNigoriDownloadRetry() { 1232 void SyncBackendHost::OnNigoriDownloadRetry() {
1233 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1233 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1234 if (!frontend_) 1234 if (!frontend_)
1235 return; 1235 return;
1236 1236
1237 frontend_->OnSyncConfigureRetry(); 1237 frontend_->OnSyncConfigureRetry();
1238 } 1238 }
1239 1239
1240 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( 1240 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
1241 const csync::WeakHandle<csync::JsBackend>& js_backend, bool success) { 1241 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) {
1242 DCHECK_NE(NOT_ATTEMPTED, initialization_state_); 1242 DCHECK_NE(NOT_ATTEMPTED, initialization_state_);
1243 if (!frontend_) 1243 if (!frontend_)
1244 return; 1244 return;
1245 1245
1246 // We've at least created the sync manager at this point, but if that is all 1246 // We've at least created the sync manager at this point, but if that is all
1247 // we've done we're just beginning the initialization process. 1247 // we've done we're just beginning the initialization process.
1248 if (initialization_state_ == CREATING_SYNC_MANAGER) 1248 if (initialization_state_ == CREATING_SYNC_MANAGER)
1249 initialization_state_ = NOT_INITIALIZED; 1249 initialization_state_ = NOT_INITIALIZED;
1250 1250
1251 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1251 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1252 if (!success) { 1252 if (!success) {
1253 initialization_state_ = NOT_INITIALIZED; 1253 initialization_state_ = NOT_INITIALIZED;
1254 frontend_->OnBackendInitialized( 1254 frontend_->OnBackendInitialized(
1255 csync::WeakHandle<csync::JsBackend>(), false); 1255 syncer::WeakHandle<syncer::JsBackend>(), false);
1256 return; 1256 return;
1257 } 1257 }
1258 1258
1259 // If setup has completed, start off in DOWNLOADING_NIGORI so that 1259 // If setup has completed, start off in DOWNLOADING_NIGORI so that
1260 // we start off by refreshing nigori. 1260 // we start off by refreshing nigori.
1261 CHECK(sync_prefs_.get()); 1261 CHECK(sync_prefs_.get());
1262 if (sync_prefs_->HasSyncSetupCompleted() && 1262 if (sync_prefs_->HasSyncSetupCompleted() &&
1263 initialization_state_ < DOWNLOADING_NIGORI) { 1263 initialization_state_ < DOWNLOADING_NIGORI) {
1264 initialization_state_ = DOWNLOADING_NIGORI; 1264 initialization_state_ = DOWNLOADING_NIGORI;
1265 } 1265 }
1266 1266
1267 // Run initialization state machine. 1267 // Run initialization state machine.
1268 switch (initialization_state_) { 1268 switch (initialization_state_) {
1269 case NOT_INITIALIZED: 1269 case NOT_INITIALIZED:
1270 initialization_state_ = DOWNLOADING_NIGORI; 1270 initialization_state_ = DOWNLOADING_NIGORI;
1271 ConfigureDataTypes( 1271 ConfigureDataTypes(
1272 csync::CONFIGURE_REASON_NEW_CLIENT, 1272 syncer::CONFIGURE_REASON_NEW_CLIENT,
1273 syncable::ModelTypeSet(), 1273 syncable::ModelTypeSet(),
1274 syncable::ModelTypeSet(), 1274 syncable::ModelTypeSet(),
1275 WITH_NIGORI, 1275 WITH_NIGORI,
1276 // Calls back into this function. 1276 // Calls back into this function.
1277 base::Bind( 1277 base::Bind(
1278 &SyncBackendHost:: 1278 &SyncBackendHost::
1279 HandleNigoriConfigurationCompletedOnFrontendLoop, 1279 HandleNigoriConfigurationCompletedOnFrontendLoop,
1280 weak_ptr_factory_.GetWeakPtr(), js_backend), 1280 weak_ptr_factory_.GetWeakPtr(), js_backend),
1281 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, 1281 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry,
1282 weak_ptr_factory_.GetWeakPtr())); 1282 weak_ptr_factory_.GetWeakPtr()));
(...skipping 21 matching lines...) Expand all
1304 } 1304 }
1305 } 1305 }
1306 1306
1307 void SyncBackendHost::PersistEncryptionBootstrapToken( 1307 void SyncBackendHost::PersistEncryptionBootstrapToken(
1308 const std::string& token) { 1308 const std::string& token) {
1309 CHECK(sync_prefs_.get()); 1309 CHECK(sync_prefs_.get());
1310 sync_prefs_->SetEncryptionBootstrapToken(token); 1310 sync_prefs_->SetEncryptionBootstrapToken(token);
1311 } 1311 }
1312 1312
1313 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1313 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1314 const csync::SyncProtocolError& sync_error) { 1314 const syncer::SyncProtocolError& sync_error) {
1315 if (!frontend_) 1315 if (!frontend_)
1316 return; 1316 return;
1317 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1317 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1318 frontend_->OnActionableError(sync_error); 1318 frontend_->OnActionableError(sync_error);
1319 } 1319 }
1320 1320
1321 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1321 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1322 const std::string& passphrase) const { 1322 const std::string& passphrase) const {
1323 DCHECK(cached_pending_keys_.has_blob()); 1323 DCHECK(cached_pending_keys_.has_blob());
1324 DCHECK(!passphrase.empty()); 1324 DCHECK(!passphrase.empty());
1325 csync::Nigori nigori; 1325 syncer::Nigori nigori;
1326 nigori.InitByDerivation("localhost", "dummy", passphrase); 1326 nigori.InitByDerivation("localhost", "dummy", passphrase);
1327 std::string plaintext; 1327 std::string plaintext;
1328 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1328 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
1329 return result; 1329 return result;
1330 } 1330 }
1331 1331
1332 void SyncBackendHost::NotifyPassphraseRequired( 1332 void SyncBackendHost::NotifyPassphraseRequired(
1333 csync::PassphraseRequiredReason reason, 1333 syncer::PassphraseRequiredReason reason,
1334 sync_pb::EncryptedData pending_keys) { 1334 sync_pb::EncryptedData pending_keys) {
1335 if (!frontend_) 1335 if (!frontend_)
1336 return; 1336 return;
1337 1337
1338 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1338 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1339 1339
1340 // Update our cache of the cryptographer's pending keys. 1340 // Update our cache of the cryptographer's pending keys.
1341 cached_pending_keys_ = pending_keys; 1341 cached_pending_keys_ = pending_keys;
1342 1342
1343 frontend_->OnPassphraseRequired(reason, pending_keys); 1343 frontend_->OnPassphraseRequired(reason, pending_keys);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 frontend_->OnEncryptionComplete(); 1382 frontend_->OnEncryptionComplete();
1383 } 1383 }
1384 1384
1385 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { 1385 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() {
1386 if (!frontend_) 1386 if (!frontend_)
1387 return; 1387 return;
1388 frontend_->OnStopSyncingPermanently(); 1388 frontend_->OnStopSyncingPermanently();
1389 } 1389 }
1390 1390
1391 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( 1391 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop(
1392 csync::ConnectionStatus status) { 1392 syncer::ConnectionStatus status) {
1393 if (!frontend_) 1393 if (!frontend_)
1394 return; 1394 return;
1395 1395
1396 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1396 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1397 1397
1398 frontend_->OnConnectionStatusChange(status); 1398 frontend_->OnConnectionStatusChange(status);
1399 } 1399 }
1400 1400
1401 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( 1401 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop(
1402 const csync::WeakHandle<csync::JsBackend>& js_backend, 1402 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
1403 const syncable::ModelTypeSet failed_configuration_types) { 1403 const syncable::ModelTypeSet failed_configuration_types) {
1404 HandleInitializationCompletedOnFrontendLoop( 1404 HandleInitializationCompletedOnFrontendLoop(
1405 js_backend, failed_configuration_types.Empty()); 1405 js_backend, failed_configuration_types.Empty());
1406 } 1406 }
1407 1407
1408 namespace { 1408 namespace {
1409 1409
1410 // Needed because MessageLoop::PostTask is overloaded. 1410 // Needed because MessageLoop::PostTask is overloaded.
1411 void PostClosure(MessageLoop* message_loop, 1411 void PostClosure(MessageLoop* message_loop,
1412 const tracked_objects::Location& from_here, 1412 const tracked_objects::Location& from_here,
(...skipping 12 matching lines...) Expand all
1425 FROM_HERE, 1425 FROM_HERE,
1426 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1426 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1427 core_.get(), sync_thread_done_callback)); 1427 core_.get(), sync_thread_done_callback));
1428 } 1428 }
1429 1429
1430 #undef SDVLOG 1430 #undef SDVLOG
1431 1431
1432 #undef SLOG 1432 #undef SLOG
1433 1433
1434 } // namespace browser_sync 1434 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698