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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 explicit SyncInternal(const std::string& name) | 130 explicit SyncInternal(const std::string& name) |
130 : name_(name), | 131 : name_(name), |
131 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 132 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
132 change_observers_( | 133 change_observers_( |
133 new ObserverListThreadSafe<SyncManager::ChangeObserver>()), | 134 new ObserverListThreadSafe<SyncManager::ChangeObserver>()), |
134 registrar_(NULL), | 135 registrar_(NULL), |
135 change_delegate_(NULL), | 136 change_delegate_(NULL), |
136 initialized_(false), | 137 initialized_(false), |
137 setup_for_test_mode_(false), | 138 setup_for_test_mode_(false), |
138 observing_ip_address_changes_(false), | 139 observing_ip_address_changes_(false), |
139 created_on_loop_(MessageLoop::current()) { | 140 created_on_loop_(MessageLoop::current()), |
| 141 debug_info_event_listener_() { |
140 // Pre-fill |notification_info_map_|. | 142 // Pre-fill |notification_info_map_|. |
141 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 143 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
142 i < syncable::MODEL_TYPE_COUNT; ++i) { | 144 i < syncable::MODEL_TYPE_COUNT; ++i) { |
143 notification_info_map_.insert( | 145 notification_info_map_.insert( |
144 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); | 146 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); |
145 } | 147 } |
146 | 148 |
147 // Bind message handlers. | 149 // Bind message handlers. |
148 BindJsMessageHandler( | 150 BindJsMessageHandler( |
149 "getNotificationState", | 151 "getNotificationState", |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 // Map used to store the notification info to be displayed in | 546 // Map used to store the notification info to be displayed in |
545 // about:sync page. | 547 // about:sync page. |
546 NotificationInfoMap notification_info_map_; | 548 NotificationInfoMap notification_info_map_; |
547 | 549 |
548 // These are for interacting with chrome://sync-internals. | 550 // These are for interacting with chrome://sync-internals. |
549 JsMessageHandlerMap js_message_handlers_; | 551 JsMessageHandlerMap js_message_handlers_; |
550 WeakHandle<JsEventHandler> js_event_handler_; | 552 WeakHandle<JsEventHandler> js_event_handler_; |
551 JsSyncManagerObserver js_sync_manager_observer_; | 553 JsSyncManagerObserver js_sync_manager_observer_; |
552 JsMutationEventObserver js_mutation_event_observer_; | 554 JsMutationEventObserver js_mutation_event_observer_; |
553 | 555 |
| 556 // This is for keeping track of client events to send to the server. |
| 557 DebugInfoEventListener debug_info_event_listener_; |
| 558 |
554 MessageLoop* const created_on_loop_; | 559 MessageLoop* const created_on_loop_; |
555 }; | 560 }; |
556 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 561 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
557 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 562 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
558 | 563 |
559 SyncManager::ChangeDelegate::~ChangeDelegate() {} | 564 SyncManager::ChangeDelegate::~ChangeDelegate() {} |
560 | 565 |
561 SyncManager::ChangeObserver::~ChangeObserver() {} | 566 SyncManager::ChangeObserver::~ChangeObserver() {} |
562 | 567 |
563 SyncManager::Observer::~Observer() {} | 568 SyncManager::Observer::~Observer() {} |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 764 |
760 registrar_ = model_safe_worker_registrar; | 765 registrar_ = model_safe_worker_registrar; |
761 change_delegate_ = change_delegate; | 766 change_delegate_ = change_delegate; |
762 setup_for_test_mode_ = setup_for_test_mode; | 767 setup_for_test_mode_ = setup_for_test_mode; |
763 | 768 |
764 sync_notifier_.reset(sync_notifier); | 769 sync_notifier_.reset(sync_notifier); |
765 | 770 |
766 AddObserver(&js_sync_manager_observer_); | 771 AddObserver(&js_sync_manager_observer_); |
767 SetJsEventHandler(event_handler); | 772 SetJsEventHandler(event_handler); |
768 | 773 |
| 774 AddObserver(&debug_info_event_listener_); |
| 775 |
769 share_.dir_manager.reset(new DirectoryManager(database_location)); | 776 share_.dir_manager.reset(new DirectoryManager(database_location)); |
770 | 777 |
771 connection_manager_.reset(new SyncAPIServerConnectionManager( | 778 connection_manager_.reset(new SyncAPIServerConnectionManager( |
772 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 779 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
773 | 780 |
774 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 781 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
775 observing_ip_address_changes_ = true; | 782 observing_ip_address_changes_ = true; |
776 | 783 |
777 connection_manager()->AddListener(this); | 784 connection_manager()->AddListener(this); |
778 | 785 |
779 // Test mode does not use a syncer context or syncer thread. | 786 // Test mode does not use a syncer context or syncer thread. |
780 if (!setup_for_test_mode_) { | 787 if (!setup_for_test_mode_) { |
781 // Build a SyncSessionContext and store the worker in it. | 788 // Build a SyncSessionContext and store the worker in it. |
782 VLOG(1) << "Sync is bringing up SyncSessionContext."; | 789 VLOG(1) << "Sync is bringing up SyncSessionContext."; |
783 std::vector<SyncEngineEventListener*> listeners; | 790 std::vector<SyncEngineEventListener*> listeners; |
784 listeners.push_back(&allstatus_); | 791 listeners.push_back(&allstatus_); |
785 listeners.push_back(this); | 792 listeners.push_back(this); |
786 SyncSessionContext* context = new SyncSessionContext( | 793 SyncSessionContext* context = new SyncSessionContext( |
787 connection_manager_.get(), | 794 connection_manager_.get(), |
788 dir_manager(), | 795 dir_manager(), |
789 model_safe_worker_registrar, | 796 model_safe_worker_registrar, |
790 listeners); | 797 listeners, |
| 798 &debug_info_event_listener_); |
791 context->set_account_name(credentials.email); | 799 context->set_account_name(credentials.email); |
792 // The SyncScheduler takes ownership of |context|. | 800 // The SyncScheduler takes ownership of |context|. |
793 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); | 801 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); |
794 } | 802 } |
795 | 803 |
796 bool signed_in = SignIn(credentials); | 804 bool signed_in = SignIn(credentials); |
797 | 805 |
798 if (signed_in || setup_for_test_mode_) { | 806 if (signed_in || setup_for_test_mode_) { |
799 if (scheduler()) { | 807 if (scheduler()) { |
800 scheduler()->Start( | 808 scheduler()->Start( |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 | 1272 |
1265 // Prevent any in-flight method calls from running. Also | 1273 // Prevent any in-flight method calls from running. Also |
1266 // invalidates |weak_handle_this_|. | 1274 // invalidates |weak_handle_this_|. |
1267 weak_ptr_factory_.InvalidateWeakPtrs(); | 1275 weak_ptr_factory_.InvalidateWeakPtrs(); |
1268 | 1276 |
1269 scheduler_.reset(); | 1277 scheduler_.reset(); |
1270 | 1278 |
1271 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1279 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
1272 RemoveObserver(&js_sync_manager_observer_); | 1280 RemoveObserver(&js_sync_manager_observer_); |
1273 | 1281 |
| 1282 RemoveObserver(&debug_info_event_listener_); |
| 1283 |
1274 if (sync_notifier_.get()) { | 1284 if (sync_notifier_.get()) { |
1275 sync_notifier_->RemoveObserver(this); | 1285 sync_notifier_->RemoveObserver(this); |
1276 } | 1286 } |
1277 sync_notifier_.reset(); | 1287 sync_notifier_.reset(); |
1278 | 1288 |
1279 if (connection_manager_.get()) { | 1289 if (connection_manager_.get()) { |
1280 connection_manager_->RemoveListener(this); | 1290 connection_manager_->RemoveListener(this); |
1281 } | 1291 } |
1282 connection_manager_.reset(); | 1292 connection_manager_.reset(); |
1283 | 1293 |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2069 | 2079 |
2070 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2080 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
2071 i != types.end(); ++i) { | 2081 i != types.end(); ++i) { |
2072 if (!lookup->initial_sync_ended_for_type(*i)) | 2082 if (!lookup->initial_sync_ended_for_type(*i)) |
2073 return false; | 2083 return false; |
2074 } | 2084 } |
2075 return true; | 2085 return true; |
2076 } | 2086 } |
2077 | 2087 |
2078 } // namespace sync_api | 2088 } // namespace sync_api |
OLD | NEW |