Chromium Code Reviews| 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" |
| 37 #include "chrome/browser/sync/js/js_mutation_event_observer.h" | 38 #include "chrome/browser/sync/js/js_mutation_event_observer.h" |
| 38 #include "chrome/browser/sync/js/js_reply_handler.h" | 39 #include "chrome/browser/sync/js/js_reply_handler.h" |
| 39 #include "chrome/browser/sync/js/js_sync_manager_observer.h" | 40 #include "chrome/browser/sync/js/js_sync_manager_observer.h" |
| 40 #include "chrome/browser/sync/notifier/sync_notifier.h" | 41 #include "chrome/browser/sync/notifier/sync_notifier.h" |
| 41 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 42 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
| 42 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 43 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
| 43 #include "chrome/browser/sync/protocol/sync.pb.h" | 44 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 44 #include "chrome/browser/sync/syncable/directory_change_delegate.h" | 45 #include "chrome/browser/sync/syncable/directory_change_delegate.h" |
| 45 #include "chrome/browser/sync/syncable/directory_manager.h" | 46 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 46 #include "chrome/browser/sync/syncable/model_type.h" | 47 #include "chrome/browser/sync/syncable/model_type.h" |
| 47 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 48 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
| 48 #include "chrome/browser/sync/syncable/syncable.h" | 49 #include "chrome/browser/sync/syncable/syncable.h" |
| 49 #include "chrome/browser/sync/util/cryptographer.h" | 50 #include "chrome/browser/sync/util/cryptographer.h" |
| 50 #include "chrome/common/chrome_switches.h" | 51 #include "chrome/common/chrome_switches.h" |
| 51 #include "net/base/network_change_notifier.h" | 52 #include "net/base/network_change_notifier.h" |
| 52 | 53 |
| 54 #include "chrome/browser/sync/internal_api/debug_info_event_listener.cc" | |
|
tim (not reviewing)
2011/10/14 01:23:21
yikes... pretty sure you meant to remove this :)
lipalani1
2011/10/14 18:31:10
Done.
| |
| 55 | |
| 53 using std::string; | 56 using std::string; |
| 54 | 57 |
| 55 using base::TimeDelta; | 58 using base::TimeDelta; |
| 56 using browser_sync::AllStatus; | 59 using browser_sync::AllStatus; |
| 57 using browser_sync::Cryptographer; | 60 using browser_sync::Cryptographer; |
| 58 using browser_sync::JsArgList; | 61 using browser_sync::JsArgList; |
| 59 using browser_sync::JsBackend; | 62 using browser_sync::JsBackend; |
| 60 using browser_sync::JsEventDetails; | 63 using browser_sync::JsEventDetails; |
| 61 using browser_sync::JsEventHandler; | 64 using browser_sync::JsEventHandler; |
| 62 using browser_sync::JsEventHandler; | 65 using browser_sync::JsEventHandler; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 explicit SyncInternal(const std::string& name) | 132 explicit SyncInternal(const std::string& name) |
| 130 : name_(name), | 133 : name_(name), |
| 131 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 134 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 132 change_observers_( | 135 change_observers_( |
| 133 new ObserverListThreadSafe<SyncManager::ChangeObserver>()), | 136 new ObserverListThreadSafe<SyncManager::ChangeObserver>()), |
| 134 registrar_(NULL), | 137 registrar_(NULL), |
| 135 change_delegate_(NULL), | 138 change_delegate_(NULL), |
| 136 initialized_(false), | 139 initialized_(false), |
| 137 setup_for_test_mode_(false), | 140 setup_for_test_mode_(false), |
| 138 observing_ip_address_changes_(false), | 141 observing_ip_address_changes_(false), |
| 139 created_on_loop_(MessageLoop::current()) { | 142 created_on_loop_(MessageLoop::current()), |
| 143 debug_info_event_listener_() { | |
|
tim (not reviewing)
2011/10/14 01:23:21
this initializer isn't needed, right?
lipalani1
2011/10/14 18:31:10
Done.
| |
| 140 // Pre-fill |notification_info_map_|. | 144 // Pre-fill |notification_info_map_|. |
| 141 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 145 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 142 i < syncable::MODEL_TYPE_COUNT; ++i) { | 146 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 143 notification_info_map_.insert( | 147 notification_info_map_.insert( |
| 144 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); | 148 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); |
| 145 } | 149 } |
| 146 | 150 |
| 147 // Bind message handlers. | 151 // Bind message handlers. |
| 148 BindJsMessageHandler( | 152 BindJsMessageHandler( |
| 149 "getNotificationState", | 153 "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 | 548 // Map used to store the notification info to be displayed in |
| 545 // about:sync page. | 549 // about:sync page. |
| 546 NotificationInfoMap notification_info_map_; | 550 NotificationInfoMap notification_info_map_; |
| 547 | 551 |
| 548 // These are for interacting with chrome://sync-internals. | 552 // These are for interacting with chrome://sync-internals. |
| 549 JsMessageHandlerMap js_message_handlers_; | 553 JsMessageHandlerMap js_message_handlers_; |
| 550 WeakHandle<JsEventHandler> js_event_handler_; | 554 WeakHandle<JsEventHandler> js_event_handler_; |
| 551 JsSyncManagerObserver js_sync_manager_observer_; | 555 JsSyncManagerObserver js_sync_manager_observer_; |
| 552 JsMutationEventObserver js_mutation_event_observer_; | 556 JsMutationEventObserver js_mutation_event_observer_; |
| 553 | 557 |
| 558 // This is for keeping track of client events to send to the server. | |
| 559 DebugInfoEventListener debug_info_event_listener_; | |
| 560 | |
| 554 MessageLoop* const created_on_loop_; | 561 MessageLoop* const created_on_loop_; |
| 555 }; | 562 }; |
| 556 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 563 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
| 557 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 564 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
| 558 | 565 |
| 559 SyncManager::ChangeDelegate::~ChangeDelegate() {} | 566 SyncManager::ChangeDelegate::~ChangeDelegate() {} |
| 560 | 567 |
| 561 SyncManager::ChangeObserver::~ChangeObserver() {} | 568 SyncManager::ChangeObserver::~ChangeObserver() {} |
| 562 | 569 |
| 563 SyncManager::Observer::~Observer() {} | 570 SyncManager::Observer::~Observer() {} |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 | 766 |
| 760 registrar_ = model_safe_worker_registrar; | 767 registrar_ = model_safe_worker_registrar; |
| 761 change_delegate_ = change_delegate; | 768 change_delegate_ = change_delegate; |
| 762 setup_for_test_mode_ = setup_for_test_mode; | 769 setup_for_test_mode_ = setup_for_test_mode; |
| 763 | 770 |
| 764 sync_notifier_.reset(sync_notifier); | 771 sync_notifier_.reset(sync_notifier); |
| 765 | 772 |
| 766 AddObserver(&js_sync_manager_observer_); | 773 AddObserver(&js_sync_manager_observer_); |
| 767 SetJsEventHandler(event_handler); | 774 SetJsEventHandler(event_handler); |
| 768 | 775 |
| 776 AddObserver(&debug_info_event_listener_); | |
| 777 | |
| 769 share_.dir_manager.reset(new DirectoryManager(database_location)); | 778 share_.dir_manager.reset(new DirectoryManager(database_location)); |
| 770 | 779 |
| 771 connection_manager_.reset(new SyncAPIServerConnectionManager( | 780 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 772 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 781 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
| 773 | 782 |
| 774 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 783 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 775 observing_ip_address_changes_ = true; | 784 observing_ip_address_changes_ = true; |
| 776 | 785 |
| 777 connection_manager()->AddListener(this); | 786 connection_manager()->AddListener(this); |
| 778 | 787 |
| 779 // Test mode does not use a syncer context or syncer thread. | 788 // Test mode does not use a syncer context or syncer thread. |
| 780 if (!setup_for_test_mode_) { | 789 if (!setup_for_test_mode_) { |
| 781 // Build a SyncSessionContext and store the worker in it. | 790 // Build a SyncSessionContext and store the worker in it. |
| 782 VLOG(1) << "Sync is bringing up SyncSessionContext."; | 791 VLOG(1) << "Sync is bringing up SyncSessionContext."; |
| 783 std::vector<SyncEngineEventListener*> listeners; | 792 std::vector<SyncEngineEventListener*> listeners; |
| 784 listeners.push_back(&allstatus_); | 793 listeners.push_back(&allstatus_); |
| 785 listeners.push_back(this); | 794 listeners.push_back(this); |
| 786 SyncSessionContext* context = new SyncSessionContext( | 795 SyncSessionContext* context = new SyncSessionContext( |
| 787 connection_manager_.get(), | 796 connection_manager_.get(), |
| 788 dir_manager(), | 797 dir_manager(), |
| 789 model_safe_worker_registrar, | 798 model_safe_worker_registrar, |
| 790 listeners); | 799 listeners, |
| 800 &debug_info_event_listener_); | |
| 791 context->set_account_name(credentials.email); | 801 context->set_account_name(credentials.email); |
| 792 // The SyncScheduler takes ownership of |context|. | 802 // The SyncScheduler takes ownership of |context|. |
| 793 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); | 803 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); |
| 794 } | 804 } |
| 795 | 805 |
| 796 bool signed_in = SignIn(credentials); | 806 bool signed_in = SignIn(credentials); |
| 797 | 807 |
| 798 if (signed_in || setup_for_test_mode_) { | 808 if (signed_in || setup_for_test_mode_) { |
| 799 if (scheduler()) { | 809 if (scheduler()) { |
| 800 scheduler()->Start( | 810 scheduler()->Start( |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 | 1274 |
| 1265 // Prevent any in-flight method calls from running. Also | 1275 // Prevent any in-flight method calls from running. Also |
| 1266 // invalidates |weak_handle_this_|. | 1276 // invalidates |weak_handle_this_|. |
| 1267 weak_ptr_factory_.InvalidateWeakPtrs(); | 1277 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 1268 | 1278 |
| 1269 scheduler_.reset(); | 1279 scheduler_.reset(); |
| 1270 | 1280 |
| 1271 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1281 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1272 RemoveObserver(&js_sync_manager_observer_); | 1282 RemoveObserver(&js_sync_manager_observer_); |
| 1273 | 1283 |
| 1284 RemoveObserver(&debug_info_event_listener_); | |
| 1285 | |
| 1274 if (sync_notifier_.get()) { | 1286 if (sync_notifier_.get()) { |
| 1275 sync_notifier_->RemoveObserver(this); | 1287 sync_notifier_->RemoveObserver(this); |
| 1276 } | 1288 } |
| 1277 sync_notifier_.reset(); | 1289 sync_notifier_.reset(); |
| 1278 | 1290 |
| 1279 if (connection_manager_.get()) { | 1291 if (connection_manager_.get()) { |
| 1280 connection_manager_->RemoveListener(this); | 1292 connection_manager_->RemoveListener(this); |
| 1281 } | 1293 } |
| 1282 connection_manager_.reset(); | 1294 connection_manager_.reset(); |
| 1283 | 1295 |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2059 | 2071 |
| 2060 for (syncable::ModelTypeSet::const_iterator i = types.begin(); | 2072 for (syncable::ModelTypeSet::const_iterator i = types.begin(); |
| 2061 i != types.end(); ++i) { | 2073 i != types.end(); ++i) { |
| 2062 if (!lookup->initial_sync_ended_for_type(*i)) | 2074 if (!lookup->initial_sync_ended_for_type(*i)) |
| 2063 return false; | 2075 return false; |
| 2064 } | 2076 } |
| 2065 return true; | 2077 return true; |
| 2066 } | 2078 } |
| 2067 | 2079 |
| 2068 } // namespace sync_api | 2080 } // namespace sync_api |
| OLD | NEW |