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