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 "chrome/browser/sync/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/sync_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/observer_list_threadsafe.h" | 15 #include "base/observer_list_threadsafe.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/sync/engine/all_status.h" | 18 #include "chrome/browser/sync/engine/all_status.h" |
19 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 19 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
20 #include "chrome/browser/sync/engine/nigori_util.h" | 20 #include "chrome/browser/sync/engine/nigori_util.h" |
21 #include "chrome/browser/sync/engine/syncapi_internal.h" | 21 #include "chrome/browser/sync/engine/syncapi_internal.h" |
22 #include "chrome/browser/sync/engine/syncer_types.h" | 22 #include "chrome/browser/sync/engine/syncer_types.h" |
23 #include "chrome/browser/sync/engine/sync_scheduler.h" | 23 #include "chrome/browser/sync/engine/sync_scheduler.h" |
24 #include "chrome/browser/sync/internal_api/base_node.h" | 24 #include "chrome/browser/sync/internal_api/base_node.h" |
25 #include "chrome/browser/sync/internal_api/change_reorder_buffer.h" | 25 #include "chrome/browser/sync/internal_api/change_reorder_buffer.h" |
26 #include "chrome/browser/sync/internal_api/configure_reason.h" | 26 #include "chrome/browser/sync/internal_api/configure_reason.h" |
27 #include "chrome/browser/sync/internal_api/debug_info_event_listener.h" | |
28 #include "chrome/browser/sync/internal_api/read_node.h" | 27 #include "chrome/browser/sync/internal_api/read_node.h" |
29 #include "chrome/browser/sync/internal_api/read_transaction.h" | 28 #include "chrome/browser/sync/internal_api/read_transaction.h" |
30 #include "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h" | 29 #include "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h" |
31 #include "chrome/browser/sync/internal_api/user_share.h" | 30 #include "chrome/browser/sync/internal_api/user_share.h" |
32 #include "chrome/browser/sync/internal_api/write_node.h" | 31 #include "chrome/browser/sync/internal_api/write_node.h" |
33 #include "chrome/browser/sync/internal_api/write_transaction.h" | 32 #include "chrome/browser/sync/internal_api/write_transaction.h" |
34 #include "chrome/browser/sync/js/js_arg_list.h" | 33 #include "chrome/browser/sync/js/js_arg_list.h" |
35 #include "chrome/browser/sync/js/js_backend.h" | 34 #include "chrome/browser/sync/js/js_backend.h" |
36 #include "chrome/browser/sync/js/js_event_details.h" | 35 #include "chrome/browser/sync/js/js_event_details.h" |
37 #include "chrome/browser/sync/js/js_event_handler.h" | 36 #include "chrome/browser/sync/js/js_event_handler.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 // Map used to store the notification info to be displayed in | 544 // Map used to store the notification info to be displayed in |
546 // about:sync page. | 545 // about:sync page. |
547 NotificationInfoMap notification_info_map_; | 546 NotificationInfoMap notification_info_map_; |
548 | 547 |
549 // These are for interacting with chrome://sync-internals. | 548 // These are for interacting with chrome://sync-internals. |
550 JsMessageHandlerMap js_message_handlers_; | 549 JsMessageHandlerMap js_message_handlers_; |
551 WeakHandle<JsEventHandler> js_event_handler_; | 550 WeakHandle<JsEventHandler> js_event_handler_; |
552 JsSyncManagerObserver js_sync_manager_observer_; | 551 JsSyncManagerObserver js_sync_manager_observer_; |
553 JsMutationEventObserver js_mutation_event_observer_; | 552 JsMutationEventObserver js_mutation_event_observer_; |
554 | 553 |
555 // This is for keeping track of client events to send to the server. | |
556 DebugInfoEventListener debug_info_event_listener_; | |
557 | |
558 MessageLoop* const created_on_loop_; | 554 MessageLoop* const created_on_loop_; |
559 }; | 555 }; |
560 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 556 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
561 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 557 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
562 | 558 |
563 SyncManager::ChangeDelegate::~ChangeDelegate() {} | 559 SyncManager::ChangeDelegate::~ChangeDelegate() {} |
564 | 560 |
565 SyncManager::ChangeObserver::~ChangeObserver() {} | 561 SyncManager::ChangeObserver::~ChangeObserver() {} |
566 | 562 |
567 SyncManager::Observer::~Observer() {} | 563 SyncManager::Observer::~Observer() {} |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 759 |
764 registrar_ = model_safe_worker_registrar; | 760 registrar_ = model_safe_worker_registrar; |
765 change_delegate_ = change_delegate; | 761 change_delegate_ = change_delegate; |
766 setup_for_test_mode_ = setup_for_test_mode; | 762 setup_for_test_mode_ = setup_for_test_mode; |
767 | 763 |
768 sync_notifier_.reset(sync_notifier); | 764 sync_notifier_.reset(sync_notifier); |
769 | 765 |
770 AddObserver(&js_sync_manager_observer_); | 766 AddObserver(&js_sync_manager_observer_); |
771 SetJsEventHandler(event_handler); | 767 SetJsEventHandler(event_handler); |
772 | 768 |
773 AddObserver(&debug_info_event_listener_); | |
774 | |
775 share_.dir_manager.reset(new DirectoryManager(database_location)); | 769 share_.dir_manager.reset(new DirectoryManager(database_location)); |
776 | 770 |
777 connection_manager_.reset(new SyncAPIServerConnectionManager( | 771 connection_manager_.reset(new SyncAPIServerConnectionManager( |
778 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 772 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
779 | 773 |
780 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 774 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
781 observing_ip_address_changes_ = true; | 775 observing_ip_address_changes_ = true; |
782 | 776 |
783 connection_manager()->AddListener(this); | 777 connection_manager()->AddListener(this); |
784 | 778 |
785 // Test mode does not use a syncer context or syncer thread. | 779 // Test mode does not use a syncer context or syncer thread. |
786 if (!setup_for_test_mode_) { | 780 if (!setup_for_test_mode_) { |
787 // Build a SyncSessionContext and store the worker in it. | 781 // Build a SyncSessionContext and store the worker in it. |
788 VLOG(1) << "Sync is bringing up SyncSessionContext."; | 782 VLOG(1) << "Sync is bringing up SyncSessionContext."; |
789 std::vector<SyncEngineEventListener*> listeners; | 783 std::vector<SyncEngineEventListener*> listeners; |
790 listeners.push_back(&allstatus_); | 784 listeners.push_back(&allstatus_); |
791 listeners.push_back(this); | 785 listeners.push_back(this); |
792 SyncSessionContext* context = new SyncSessionContext( | 786 SyncSessionContext* context = new SyncSessionContext( |
793 connection_manager_.get(), | 787 connection_manager_.get(), |
794 dir_manager(), | 788 dir_manager(), |
795 model_safe_worker_registrar, | 789 model_safe_worker_registrar, |
796 listeners, | 790 listeners); |
797 &debug_info_event_listener_); | |
798 context->set_account_name(credentials.email); | 791 context->set_account_name(credentials.email); |
799 // The SyncScheduler takes ownership of |context|. | 792 // The SyncScheduler takes ownership of |context|. |
800 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); | 793 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); |
801 } | 794 } |
802 | 795 |
803 bool signed_in = SignIn(credentials); | 796 bool signed_in = SignIn(credentials); |
804 | 797 |
805 if (signed_in || setup_for_test_mode_) { | 798 if (signed_in || setup_for_test_mode_) { |
806 if (scheduler()) { | 799 if (scheduler()) { |
807 scheduler()->Start( | 800 scheduler()->Start( |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 | 1264 |
1272 // Prevent any in-flight method calls from running. Also | 1265 // Prevent any in-flight method calls from running. Also |
1273 // invalidates |weak_handle_this_|. | 1266 // invalidates |weak_handle_this_|. |
1274 weak_ptr_factory_.InvalidateWeakPtrs(); | 1267 weak_ptr_factory_.InvalidateWeakPtrs(); |
1275 | 1268 |
1276 scheduler_.reset(); | 1269 scheduler_.reset(); |
1277 | 1270 |
1278 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1271 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
1279 RemoveObserver(&js_sync_manager_observer_); | 1272 RemoveObserver(&js_sync_manager_observer_); |
1280 | 1273 |
1281 RemoveObserver(&debug_info_event_listener_); | |
1282 | |
1283 if (sync_notifier_.get()) { | 1274 if (sync_notifier_.get()) { |
1284 sync_notifier_->RemoveObserver(this); | 1275 sync_notifier_->RemoveObserver(this); |
1285 } | 1276 } |
1286 sync_notifier_.reset(); | 1277 sync_notifier_.reset(); |
1287 | 1278 |
1288 if (connection_manager_.get()) { | 1279 if (connection_manager_.get()) { |
1289 connection_manager_->RemoveListener(this); | 1280 connection_manager_->RemoveListener(this); |
1290 } | 1281 } |
1291 connection_manager_.reset(); | 1282 connection_manager_.reset(); |
1292 | 1283 |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 | 2069 |
2079 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2070 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
2080 i != types.end(); ++i) { | 2071 i != types.end(); ++i) { |
2081 if (!lookup->initial_sync_ended_for_type(*i)) | 2072 if (!lookup->initial_sync_ended_for_type(*i)) |
2082 return false; | 2073 return false; |
2083 } | 2074 } |
2084 return true; | 2075 return true; |
2085 } | 2076 } |
2086 | 2077 |
2087 } // namespace sync_api | 2078 } // namespace sync_api |
OLD | NEW |