| OLD | NEW |
| 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 "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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // because the encryption keys don't match (per chrome instantiation). | 115 // because the encryption keys don't match (per chrome instantiation). |
| 116 static const int kNigoriOverwriteLimit = 10; | 116 static const int kNigoriOverwriteLimit = 10; |
| 117 | 117 |
| 118 } // namespace | 118 } // namespace |
| 119 | 119 |
| 120 namespace sync_api { | 120 namespace sync_api { |
| 121 | 121 |
| 122 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200; | 122 const int SyncManager::kDefaultNudgeDelayMilliseconds = 200; |
| 123 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000; | 123 const int SyncManager::kPreferencesNudgeDelayMilliseconds = 2000; |
| 124 | 124 |
| 125 // Maximum count and size for traffic recorder. |
| 126 const unsigned int kMaxMessagesToRecord = 10; |
| 127 const unsigned int kMaxMessageSizeToRecord = 5 * 1024; |
| 128 |
| 125 ////////////////////////////////////////////////////////////////////////// | 129 ////////////////////////////////////////////////////////////////////////// |
| 126 // SyncManager's implementation: SyncManager::SyncInternal | 130 // SyncManager's implementation: SyncManager::SyncInternal |
| 127 class SyncManager::SyncInternal | 131 class SyncManager::SyncInternal |
| 128 : public net::NetworkChangeNotifier::IPAddressObserver, | 132 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 129 public browser_sync::Cryptographer::Observer, | 133 public browser_sync::Cryptographer::Observer, |
| 130 public sync_notifier::SyncNotifierObserver, | 134 public sync_notifier::SyncNotifierObserver, |
| 131 public JsBackend, | 135 public JsBackend, |
| 132 public SyncEngineEventListener, | 136 public SyncEngineEventListener, |
| 133 public ServerConnectionEventListener, | 137 public ServerConnectionEventListener, |
| 134 public syncable::DirectoryChangeDelegate { | 138 public syncable::DirectoryChangeDelegate { |
| 135 public: | 139 public: |
| 136 explicit SyncInternal(const std::string& name) | 140 explicit SyncInternal(const std::string& name) |
| 137 : name_(name), | 141 : name_(name), |
| 138 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 142 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 139 enable_sync_tabs_for_other_clients_(false), | 143 enable_sync_tabs_for_other_clients_(false), |
| 140 registrar_(NULL), | 144 registrar_(NULL), |
| 141 change_delegate_(NULL), | 145 change_delegate_(NULL), |
| 142 initialized_(false), | 146 initialized_(false), |
| 143 testing_mode_(NON_TEST), | 147 testing_mode_(NON_TEST), |
| 144 observing_ip_address_changes_(false), | 148 observing_ip_address_changes_(false), |
| 145 encryptor_(NULL), | 149 encryptor_(NULL), |
| 146 unrecoverable_error_handler_(NULL), | 150 unrecoverable_error_handler_(NULL), |
| 147 report_unrecoverable_error_function_(NULL), | 151 report_unrecoverable_error_function_(NULL), |
| 148 created_on_loop_(MessageLoop::current()), | 152 created_on_loop_(MessageLoop::current()), |
| 149 nigori_overwrite_count_(0) { | 153 nigori_overwrite_count_(0), |
| 154 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord) { |
| 150 // Pre-fill |notification_info_map_|. | 155 // Pre-fill |notification_info_map_|. |
| 151 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 156 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 152 i < syncable::MODEL_TYPE_COUNT; ++i) { | 157 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 153 notification_info_map_.insert( | 158 notification_info_map_.insert( |
| 154 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); | 159 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); |
| 155 } | 160 } |
| 156 | 161 |
| 157 // Bind message handlers. | 162 // Bind message handlers. |
| 158 BindJsMessageHandler( | 163 BindJsMessageHandler( |
| 159 "getNotificationState", | 164 "getNotificationState", |
| 160 &SyncManager::SyncInternal::GetNotificationState); | 165 &SyncManager::SyncInternal::GetNotificationState); |
| 161 BindJsMessageHandler( | 166 BindJsMessageHandler( |
| 162 "getNotificationInfo", | 167 "getNotificationInfo", |
| 163 &SyncManager::SyncInternal::GetNotificationInfo); | 168 &SyncManager::SyncInternal::GetNotificationInfo); |
| 164 BindJsMessageHandler( | 169 BindJsMessageHandler( |
| 165 "getRootNodeDetails", | 170 "getRootNodeDetails", |
| 166 &SyncManager::SyncInternal::GetRootNodeDetails); | 171 &SyncManager::SyncInternal::GetRootNodeDetails); |
| 167 BindJsMessageHandler( | 172 BindJsMessageHandler( |
| 168 "getNodeSummariesById", | 173 "getNodeSummariesById", |
| 169 &SyncManager::SyncInternal::GetNodeSummariesById); | 174 &SyncManager::SyncInternal::GetNodeSummariesById); |
| 170 BindJsMessageHandler( | 175 BindJsMessageHandler( |
| 171 "getNodeDetailsById", | 176 "getNodeDetailsById", |
| 172 &SyncManager::SyncInternal::GetNodeDetailsById); | 177 &SyncManager::SyncInternal::GetNodeDetailsById); |
| 173 BindJsMessageHandler( | 178 BindJsMessageHandler( |
| 174 "getChildNodeIds", | 179 "getChildNodeIds", |
| 175 &SyncManager::SyncInternal::GetChildNodeIds); | 180 &SyncManager::SyncInternal::GetChildNodeIds); |
| 176 BindJsMessageHandler( | 181 BindJsMessageHandler( |
| 177 "findNodesContainingString", | 182 "findNodesContainingString", |
| 178 &SyncManager::SyncInternal::FindNodesContainingString); | 183 &SyncManager::SyncInternal::FindNodesContainingString); |
| 184 BindJsMessageHandler( |
| 185 "getClientServerTraffic", |
| 186 &SyncManager::SyncInternal::GetClientServerTraffic); |
| 179 } | 187 } |
| 180 | 188 |
| 181 virtual ~SyncInternal() { | 189 virtual ~SyncInternal() { |
| 182 CHECK(!initialized_); | 190 CHECK(!initialized_); |
| 183 } | 191 } |
| 184 | 192 |
| 185 bool Init(const FilePath& database_location, | 193 bool Init(const FilePath& database_location, |
| 186 const WeakHandle<JsEventHandler>& event_handler, | 194 const WeakHandle<JsEventHandler>& event_handler, |
| 187 const std::string& sync_server_and_path, | 195 const std::string& sync_server_and_path, |
| 188 int port, | 196 int port, |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 const NotificationInfoMap& notification_info); | 521 const NotificationInfoMap& notification_info); |
| 514 | 522 |
| 515 // JS message handlers. | 523 // JS message handlers. |
| 516 JsArgList GetNotificationState(const JsArgList& args); | 524 JsArgList GetNotificationState(const JsArgList& args); |
| 517 JsArgList GetNotificationInfo(const JsArgList& args); | 525 JsArgList GetNotificationInfo(const JsArgList& args); |
| 518 JsArgList GetRootNodeDetails(const JsArgList& args); | 526 JsArgList GetRootNodeDetails(const JsArgList& args); |
| 519 JsArgList GetNodeSummariesById(const JsArgList& args); | 527 JsArgList GetNodeSummariesById(const JsArgList& args); |
| 520 JsArgList GetNodeDetailsById(const JsArgList& args); | 528 JsArgList GetNodeDetailsById(const JsArgList& args); |
| 521 JsArgList GetChildNodeIds(const JsArgList& args); | 529 JsArgList GetChildNodeIds(const JsArgList& args); |
| 522 JsArgList FindNodesContainingString(const JsArgList& args); | 530 JsArgList FindNodesContainingString(const JsArgList& args); |
| 531 JsArgList GetClientServerTraffic(const JsArgList& args); |
| 523 | 532 |
| 524 FilePath database_path_; | 533 FilePath database_path_; |
| 525 | 534 |
| 526 const std::string name_; | 535 const std::string name_; |
| 527 | 536 |
| 528 base::ThreadChecker thread_checker_; | 537 base::ThreadChecker thread_checker_; |
| 529 | 538 |
| 530 base::WeakPtrFactory<SyncInternal> weak_ptr_factory_; | 539 base::WeakPtrFactory<SyncInternal> weak_ptr_factory_; |
| 531 | 540 |
| 532 // Thread-safe handle used by | 541 // Thread-safe handle used by |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 611 |
| 603 // These are for interacting with chrome://sync-internals. | 612 // These are for interacting with chrome://sync-internals. |
| 604 JsMessageHandlerMap js_message_handlers_; | 613 JsMessageHandlerMap js_message_handlers_; |
| 605 WeakHandle<JsEventHandler> js_event_handler_; | 614 WeakHandle<JsEventHandler> js_event_handler_; |
| 606 JsSyncManagerObserver js_sync_manager_observer_; | 615 JsSyncManagerObserver js_sync_manager_observer_; |
| 607 JsMutationEventObserver js_mutation_event_observer_; | 616 JsMutationEventObserver js_mutation_event_observer_; |
| 608 | 617 |
| 609 // This is for keeping track of client events to send to the server. | 618 // This is for keeping track of client events to send to the server. |
| 610 DebugInfoEventListener debug_info_event_listener_; | 619 DebugInfoEventListener debug_info_event_listener_; |
| 611 | 620 |
| 621 browser_sync::TrafficRecorder traffic_recorder_; |
| 622 |
| 612 Encryptor* encryptor_; | 623 Encryptor* encryptor_; |
| 613 UnrecoverableErrorHandler* unrecoverable_error_handler_; | 624 UnrecoverableErrorHandler* unrecoverable_error_handler_; |
| 614 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; | 625 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; |
| 615 | 626 |
| 616 MessageLoop* const created_on_loop_; | 627 MessageLoop* const created_on_loop_; |
| 617 | 628 |
| 618 // The number of times we've automatically (i.e. not via SetPassphrase or | 629 // The number of times we've automatically (i.e. not via SetPassphrase or |
| 619 // conflict resolver) updated the nigori's encryption keys in this chrome | 630 // conflict resolver) updated the nigori's encryption keys in this chrome |
| 620 // instantiation. | 631 // instantiation. |
| 621 int nigori_overwrite_count_; | 632 int nigori_overwrite_count_; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 965 DVLOG(1) << "Sync is bringing up SyncSessionContext."; |
| 955 std::vector<SyncEngineEventListener*> listeners; | 966 std::vector<SyncEngineEventListener*> listeners; |
| 956 listeners.push_back(&allstatus_); | 967 listeners.push_back(&allstatus_); |
| 957 listeners.push_back(this); | 968 listeners.push_back(this); |
| 958 SyncSessionContext* context = new SyncSessionContext( | 969 SyncSessionContext* context = new SyncSessionContext( |
| 959 connection_manager_.get(), | 970 connection_manager_.get(), |
| 960 directory(), | 971 directory(), |
| 961 model_safe_worker_registrar, | 972 model_safe_worker_registrar, |
| 962 extensions_activity_monitor, | 973 extensions_activity_monitor, |
| 963 listeners, | 974 listeners, |
| 964 &debug_info_event_listener_); | 975 &debug_info_event_listener_, |
| 976 &traffic_recorder_); |
| 965 context->set_account_name(credentials.email); | 977 context->set_account_name(credentials.email); |
| 966 // The SyncScheduler takes ownership of |context|. | 978 // The SyncScheduler takes ownership of |context|. |
| 967 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); | 979 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); |
| 968 } | 980 } |
| 969 | 981 |
| 970 bool signed_in = SignIn(credentials); | 982 bool signed_in = SignIn(credentials); |
| 971 | 983 |
| 972 if (signed_in) { | 984 if (signed_in) { |
| 973 if (scheduler()) { | 985 if (scheduler()) { |
| 974 scheduler()->Start( | 986 scheduler()->Start( |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 JsArgList SyncManager::SyncInternal::GetRootNodeDetails( | 2212 JsArgList SyncManager::SyncInternal::GetRootNodeDetails( |
| 2201 const JsArgList& args) { | 2213 const JsArgList& args) { |
| 2202 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2214 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2203 ReadNode root(&trans); | 2215 ReadNode root(&trans); |
| 2204 root.InitByRootLookup(); | 2216 root.InitByRootLookup(); |
| 2205 ListValue return_args; | 2217 ListValue return_args; |
| 2206 return_args.Append(root.GetDetailsAsValue()); | 2218 return_args.Append(root.GetDetailsAsValue()); |
| 2207 return JsArgList(&return_args); | 2219 return JsArgList(&return_args); |
| 2208 } | 2220 } |
| 2209 | 2221 |
| 2222 JsArgList SyncManager::SyncInternal::GetClientServerTraffic( |
| 2223 const JsArgList& args) { |
| 2224 ListValue return_args; |
| 2225 ListValue* value = traffic_recorder_.ToValue(); |
| 2226 if (value != NULL) |
| 2227 return_args.Append(value); |
| 2228 return JsArgList(&return_args); |
| 2229 } |
| 2230 |
| 2210 namespace { | 2231 namespace { |
| 2211 | 2232 |
| 2212 int64 GetId(const ListValue& ids, int i) { | 2233 int64 GetId(const ListValue& ids, int i) { |
| 2213 std::string id_str; | 2234 std::string id_str; |
| 2214 if (!ids.GetString(i, &id_str)) { | 2235 if (!ids.GetString(i, &id_str)) { |
| 2215 return kInvalidId; | 2236 return kInvalidId; |
| 2216 } | 2237 } |
| 2217 int64 id = kInvalidId; | 2238 int64 id = kInvalidId; |
| 2218 if (!base::StringToInt64(id_str, &id)) { | 2239 if (!base::StringToInt64(id_str, &id)) { |
| 2219 return kInvalidId; | 2240 return kInvalidId; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2543 share->directory->GetDownloadProgress(i.Get(), &marker); | 2564 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2544 | 2565 |
| 2545 if (marker.token().empty()) | 2566 if (marker.token().empty()) |
| 2546 result.Put(i.Get()); | 2567 result.Put(i.Get()); |
| 2547 | 2568 |
| 2548 } | 2569 } |
| 2549 return result; | 2570 return result; |
| 2550 } | 2571 } |
| 2551 | 2572 |
| 2552 } // namespace sync_api | 2573 } // namespace sync_api |
| OLD | NEW |