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

Side by Side Diff: components/sync/core_impl/sync_manager_impl.cc

Issue 2258873003: [Sync] Move sessions/ to engine/cycle/ and rename things to match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 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
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 "components/sync/core_impl/sync_manager_impl.h" 5 #include "components/sync/core_impl/sync_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 22 matching lines...) Expand all
33 #include "components/sync/core/read_node.h" 33 #include "components/sync/core/read_node.h"
34 #include "components/sync/core/read_transaction.h" 34 #include "components/sync/core/read_transaction.h"
35 #include "components/sync/core/user_share.h" 35 #include "components/sync/core/user_share.h"
36 #include "components/sync/core/write_node.h" 36 #include "components/sync/core/write_node.h"
37 #include "components/sync/core/write_transaction.h" 37 #include "components/sync/core/write_transaction.h"
38 #include "components/sync/core_impl/change_reorder_buffer.h" 38 #include "components/sync/core_impl/change_reorder_buffer.h"
39 #include "components/sync/core_impl/model_type_connector_proxy.h" 39 #include "components/sync/core_impl/model_type_connector_proxy.h"
40 #include "components/sync/core_impl/syncapi_internal.h" 40 #include "components/sync/core_impl/syncapi_internal.h"
41 #include "components/sync/core_impl/syncapi_server_connection_manager.h" 41 #include "components/sync/core_impl/syncapi_server_connection_manager.h"
42 #include "components/sync/engine/polling_constants.h" 42 #include "components/sync/engine/polling_constants.h"
43 #include "components/sync/engine_impl/cycle/directory_type_debug_info_emitter.h"
43 #include "components/sync/engine_impl/sync_scheduler.h" 44 #include "components/sync/engine_impl/sync_scheduler.h"
44 #include "components/sync/engine_impl/syncer_types.h" 45 #include "components/sync/engine_impl/syncer_types.h"
45 #include "components/sync/protocol/proto_value_conversions.h" 46 #include "components/sync/protocol/proto_value_conversions.h"
46 #include "components/sync/protocol/sync.pb.h" 47 #include "components/sync/protocol/sync.pb.h"
47 #include "components/sync/sessions_impl/directory_type_debug_info_emitter.h"
48 #include "components/sync/syncable/directory.h" 48 #include "components/sync/syncable/directory.h"
49 #include "components/sync/syncable/entry.h" 49 #include "components/sync/syncable/entry.h"
50 #include "components/sync/syncable/in_memory_directory_backing_store.h" 50 #include "components/sync/syncable/in_memory_directory_backing_store.h"
51 #include "components/sync/syncable/on_disk_directory_backing_store.h" 51 #include "components/sync/syncable/on_disk_directory_backing_store.h"
52 52
53 using base::TimeDelta; 53 using base::TimeDelta;
54 using sync_pb::GetUpdatesCallerInfo; 54 using sync_pb::GetUpdatesCallerInfo;
55 55
56 class GURL; 56 class GURL;
57 57
58 namespace syncer { 58 namespace syncer {
59 59
60 using sessions::SyncSessionContext;
61 using syncable::ImmutableWriteTransactionInfo; 60 using syncable::ImmutableWriteTransactionInfo;
62 using syncable::SPECIFICS; 61 using syncable::SPECIFICS;
63 using syncable::UNIQUE_POSITION; 62 using syncable::UNIQUE_POSITION;
64 63
65 namespace { 64 namespace {
66 65
67 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason( 66 GetUpdatesCallerInfo::GetUpdatesSource GetSourceFromReason(
68 ConfigureReason reason) { 67 ConfigureReason reason) {
69 switch (reason) { 68 switch (reason) {
70 case CONFIGURE_REASON_RECONFIGURATION: 69 case CONFIGURE_REASON_RECONFIGURATION:
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 297
299 DVLOG(1) << "Setting sync client ID: " << sync_id; 298 DVLOG(1) << "Setting sync client ID: " << sync_id;
300 allstatus_.SetSyncId(sync_id); 299 allstatus_.SetSyncId(sync_id);
301 DVLOG(1) << "Setting invalidator client ID: " << args->invalidator_client_id; 300 DVLOG(1) << "Setting invalidator client ID: " << args->invalidator_client_id;
302 allstatus_.SetInvalidatorClientId(args->invalidator_client_id); 301 allstatus_.SetInvalidatorClientId(args->invalidator_client_id);
303 302
304 model_type_registry_.reset( 303 model_type_registry_.reset(
305 new ModelTypeRegistry(args->workers, directory(), this)); 304 new ModelTypeRegistry(args->workers, directory(), this));
306 sync_encryption_handler_->AddObserver(model_type_registry_.get()); 305 sync_encryption_handler_->AddObserver(model_type_registry_.get());
307 306
308 // Build a SyncSessionContext and store the worker in it. 307 // Build a SyncCycleContext and store the worker in it.
309 DVLOG(1) << "Sync is bringing up SyncSessionContext."; 308 DVLOG(1) << "Sync is bringing up SyncCycleContext.";
310 std::vector<SyncEngineEventListener*> listeners; 309 std::vector<SyncEngineEventListener*> listeners;
311 listeners.push_back(&allstatus_); 310 listeners.push_back(&allstatus_);
312 listeners.push_back(this); 311 listeners.push_back(this);
313 session_context_ = args->internal_components_factory->BuildContext( 312 cycle_context_ = args->internal_components_factory->BuildContext(
314 connection_manager_.get(), directory(), args->extensions_activity, 313 connection_manager_.get(), directory(), args->extensions_activity,
315 listeners, &debug_info_event_listener_, model_type_registry_.get(), 314 listeners, &debug_info_event_listener_, model_type_registry_.get(),
316 args->invalidator_client_id); 315 args->invalidator_client_id);
317 scheduler_ = args->internal_components_factory->BuildScheduler( 316 scheduler_ = args->internal_components_factory->BuildScheduler(
318 name_, session_context_.get(), args->cancelation_signal); 317 name_, cycle_context_.get(), args->cancelation_signal);
319 318
320 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); 319 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time());
321 320
322 initialized_ = true; 321 initialized_ = true;
323 322
324 net::NetworkChangeNotifier::AddIPAddressObserver(this); 323 net::NetworkChangeNotifier::AddIPAddressObserver(this);
325 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 324 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
326 observing_network_connectivity_changes_ = true; 325 observing_network_connectivity_changes_ = true;
327 326
328 UpdateCredentials(args->credentials); 327 UpdateCredentials(args->credentials);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 392
394 void SyncManagerImpl::StartSyncingNormally( 393 void SyncManagerImpl::StartSyncingNormally(
395 const ModelSafeRoutingInfo& routing_info, 394 const ModelSafeRoutingInfo& routing_info,
396 base::Time last_poll_time) { 395 base::Time last_poll_time) {
397 // Start the sync scheduler. 396 // Start the sync scheduler.
398 // TODO(sync): We always want the newest set of routes when we switch back 397 // TODO(sync): We always want the newest set of routes when we switch back
399 // to normal mode. Figure out how to enforce set_routing_info is always 398 // to normal mode. Figure out how to enforce set_routing_info is always
400 // appropriately set and that it's only modified when switching to normal 399 // appropriately set and that it's only modified when switching to normal
401 // mode. 400 // mode.
402 DCHECK(thread_checker_.CalledOnValidThread()); 401 DCHECK(thread_checker_.CalledOnValidThread());
403 session_context_->SetRoutingInfo(routing_info); 402 cycle_context_->SetRoutingInfo(routing_info);
404 scheduler_->Start(SyncScheduler::NORMAL_MODE, last_poll_time); 403 scheduler_->Start(SyncScheduler::NORMAL_MODE, last_poll_time);
405 } 404 }
406 405
407 syncable::Directory* SyncManagerImpl::directory() { 406 syncable::Directory* SyncManagerImpl::directory() {
408 return share_.directory.get(); 407 return share_.directory.get();
409 } 408 }
410 409
411 const SyncScheduler* SyncManagerImpl::scheduler() const { 410 const SyncScheduler* SyncManagerImpl::scheduler() const {
412 return scheduler_.get(); 411 return scheduler_.get();
413 } 412 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 DCHECK(to_purge.HasAll(to_unapply)); 473 DCHECK(to_purge.HasAll(to_unapply));
475 return directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply); 474 return directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply);
476 } 475 }
477 476
478 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { 477 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) {
479 DCHECK(thread_checker_.CalledOnValidThread()); 478 DCHECK(thread_checker_.CalledOnValidThread());
480 DCHECK(initialized_); 479 DCHECK(initialized_);
481 DCHECK(!credentials.account_id.empty()); 480 DCHECK(!credentials.account_id.empty());
482 DCHECK(!credentials.sync_token.empty()); 481 DCHECK(!credentials.sync_token.empty());
483 DCHECK(!credentials.scope_set.empty()); 482 DCHECK(!credentials.scope_set.empty());
484 session_context_->set_account_name(credentials.email); 483 cycle_context_->set_account_name(credentials.email);
485 484
486 observing_network_connectivity_changes_ = true; 485 observing_network_connectivity_changes_ = true;
487 if (!connection_manager_->SetAuthToken(credentials.sync_token)) 486 if (!connection_manager_->SetAuthToken(credentials.sync_token))
488 return; // Auth token is known to be invalid, so exit early. 487 return; // Auth token is known to be invalid, so exit early.
489 488
490 scheduler_->OnCredentialsUpdated(); 489 scheduler_->OnCredentialsUpdated();
491 490
492 // TODO(zea): pass the credential age to the debug info event listener. 491 // TODO(zea): pass the credential age to the debug info event listener.
493 } 492 }
494 493
495 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { 494 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) {
496 DCHECK(thread_checker_.CalledOnValidThread()); 495 DCHECK(thread_checker_.CalledOnValidThread());
497 observers_.AddObserver(observer); 496 observers_.AddObserver(observer);
498 } 497 }
499 498
500 void SyncManagerImpl::RemoveObserver(SyncManager::Observer* observer) { 499 void SyncManagerImpl::RemoveObserver(SyncManager::Observer* observer) {
501 DCHECK(thread_checker_.CalledOnValidThread()); 500 DCHECK(thread_checker_.CalledOnValidThread());
502 observers_.RemoveObserver(observer); 501 observers_.RemoveObserver(observer);
503 } 502 }
504 503
505 void SyncManagerImpl::ShutdownOnSyncThread(ShutdownReason reason) { 504 void SyncManagerImpl::ShutdownOnSyncThread(ShutdownReason reason) {
506 DCHECK(thread_checker_.CalledOnValidThread()); 505 DCHECK(thread_checker_.CalledOnValidThread());
507 506
508 // Prevent any in-flight method calls from running. Also 507 // Prevent any in-flight method calls from running. Also
509 // invalidates |weak_handle_this_| and |change_observer_|. 508 // invalidates |weak_handle_this_| and |change_observer_|.
510 weak_ptr_factory_.InvalidateWeakPtrs(); 509 weak_ptr_factory_.InvalidateWeakPtrs();
511 js_mutation_event_observer_.InvalidateWeakPtrs(); 510 js_mutation_event_observer_.InvalidateWeakPtrs();
512 511
513 scheduler_.reset(); 512 scheduler_.reset();
514 session_context_.reset(); 513 cycle_context_.reset();
515 514
516 if (model_type_registry_) 515 if (model_type_registry_)
517 sync_encryption_handler_->RemoveObserver(model_type_registry_.get()); 516 sync_encryption_handler_->RemoveObserver(model_type_registry_.get());
518 517
519 model_type_registry_.reset(); 518 model_type_registry_.reset();
520 519
521 if (sync_encryption_handler_) { 520 if (sync_encryption_handler_) {
522 sync_encryption_handler_->RemoveObserver(&debug_info_event_listener_); 521 sync_encryption_handler_->RemoveObserver(&debug_info_event_listener_);
523 sync_encryption_handler_->RemoveObserver(this); 522 sync_encryption_handler_->RemoveObserver(this);
524 } 523 }
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 favicon_sync_node.GetExperimentsSpecifics() 937 favicon_sync_node.GetExperimentsSpecifics()
939 .favicon_sync() 938 .favicon_sync()
940 .favicon_sync_limit(); 939 .favicon_sync_limit();
941 found_experiment = true; 940 found_experiment = true;
942 } 941 }
943 942
944 ReadNode pre_commit_update_avoidance_node(&trans); 943 ReadNode pre_commit_update_avoidance_node(&trans);
945 if (pre_commit_update_avoidance_node.InitByClientTagLookup( 944 if (pre_commit_update_avoidance_node.InitByClientTagLookup(
946 syncer::EXPERIMENTS, syncer::kPreCommitUpdateAvoidanceTag) == 945 syncer::EXPERIMENTS, syncer::kPreCommitUpdateAvoidanceTag) ==
947 BaseNode::INIT_OK) { 946 BaseNode::INIT_OK) {
948 session_context_->set_server_enabled_pre_commit_update_avoidance( 947 cycle_context_->set_server_enabled_pre_commit_update_avoidance(
949 pre_commit_update_avoidance_node.GetExperimentsSpecifics() 948 pre_commit_update_avoidance_node.GetExperimentsSpecifics()
950 .pre_commit_update_avoidance() 949 .pre_commit_update_avoidance()
951 .enabled()); 950 .enabled());
952 // We don't bother setting found_experiment. The frontend doesn't need to 951 // We don't bother setting found_experiment. The frontend doesn't need to
953 // know about this. 952 // know about this.
954 } 953 }
955 954
956 ReadNode gcm_invalidations_node(&trans); 955 ReadNode gcm_invalidations_node(&trans);
957 if (gcm_invalidations_node.InitByClientTagLookup( 956 if (gcm_invalidations_node.InitByClientTagLookup(
958 syncer::EXPERIMENTS, syncer::kGCMInvalidationsTag) == 957 syncer::EXPERIMENTS, syncer::kGCMInvalidationsTag) ==
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 void SyncManagerImpl::ClearServerData(const ClearServerDataCallback& callback) { 1003 void SyncManagerImpl::ClearServerData(const ClearServerDataCallback& callback) {
1005 DCHECK(thread_checker_.CalledOnValidThread()); 1004 DCHECK(thread_checker_.CalledOnValidThread());
1006 scheduler_->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); 1005 scheduler_->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time());
1007 ClearParams params(callback); 1006 ClearParams params(callback);
1008 scheduler_->ScheduleClearServerData(params); 1007 scheduler_->ScheduleClearServerData(params);
1009 } 1008 }
1010 1009
1011 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, 1010 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch,
1012 bool empty_jar) { 1011 bool empty_jar) {
1013 DCHECK(thread_checker_.CalledOnValidThread()); 1012 DCHECK(thread_checker_.CalledOnValidThread());
1014 session_context_->set_cookie_jar_mismatch(account_mismatch); 1013 cycle_context_->set_cookie_jar_mismatch(account_mismatch);
1015 session_context_->set_cookie_jar_empty(empty_jar); 1014 cycle_context_->set_cookie_jar_empty(empty_jar);
1016 } 1015 }
1017 1016
1018 } // namespace syncer 1017 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core_impl/sync_manager_impl.h ('k') | components/sync/core_impl/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698