Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

Issue 9826035: [Sync] Display the client server traffic log in about:sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For submitting. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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),
149 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord),
145 encryptor_(NULL), 150 encryptor_(NULL),
146 unrecoverable_error_handler_(NULL), 151 unrecoverable_error_handler_(NULL),
147 report_unrecoverable_error_function_(NULL), 152 report_unrecoverable_error_function_(NULL),
148 created_on_loop_(MessageLoop::current()), 153 created_on_loop_(MessageLoop::current()),
149 nigori_overwrite_count_(0) { 154 nigori_overwrite_count_(0) {
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()));
(...skipping 14 matching lines...) Expand all
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 const NotificationInfoMap& notification_info); 523 const NotificationInfoMap& notification_info);
516 524
517 // JS message handlers. 525 // JS message handlers.
518 JsArgList GetNotificationState(const JsArgList& args); 526 JsArgList GetNotificationState(const JsArgList& args);
519 JsArgList GetNotificationInfo(const JsArgList& args); 527 JsArgList GetNotificationInfo(const JsArgList& args);
520 JsArgList GetRootNodeDetails(const JsArgList& args); 528 JsArgList GetRootNodeDetails(const JsArgList& args);
521 JsArgList GetNodeSummariesById(const JsArgList& args); 529 JsArgList GetNodeSummariesById(const JsArgList& args);
522 JsArgList GetNodeDetailsById(const JsArgList& args); 530 JsArgList GetNodeDetailsById(const JsArgList& args);
523 JsArgList GetChildNodeIds(const JsArgList& args); 531 JsArgList GetChildNodeIds(const JsArgList& args);
524 JsArgList FindNodesContainingString(const JsArgList& args); 532 JsArgList FindNodesContainingString(const JsArgList& args);
533 JsArgList GetClientServerTraffic(const JsArgList& args);
525 534
526 FilePath database_path_; 535 FilePath database_path_;
527 536
528 const std::string name_; 537 const std::string name_;
529 538
530 base::ThreadChecker thread_checker_; 539 base::ThreadChecker thread_checker_;
531 540
532 base::WeakPtrFactory<SyncInternal> weak_ptr_factory_; 541 base::WeakPtrFactory<SyncInternal> weak_ptr_factory_;
533 542
534 // Thread-safe handle used by 543 // Thread-safe handle used by
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 613
605 // These are for interacting with chrome://sync-internals. 614 // These are for interacting with chrome://sync-internals.
606 JsMessageHandlerMap js_message_handlers_; 615 JsMessageHandlerMap js_message_handlers_;
607 WeakHandle<JsEventHandler> js_event_handler_; 616 WeakHandle<JsEventHandler> js_event_handler_;
608 JsSyncManagerObserver js_sync_manager_observer_; 617 JsSyncManagerObserver js_sync_manager_observer_;
609 JsMutationEventObserver js_mutation_event_observer_; 618 JsMutationEventObserver js_mutation_event_observer_;
610 619
611 // This is for keeping track of client events to send to the server. 620 // This is for keeping track of client events to send to the server.
612 DebugInfoEventListener debug_info_event_listener_; 621 DebugInfoEventListener debug_info_event_listener_;
613 622
623 browser_sync::TrafficRecorder traffic_recorder_;
624
614 Encryptor* encryptor_; 625 Encryptor* encryptor_;
615 UnrecoverableErrorHandler* unrecoverable_error_handler_; 626 UnrecoverableErrorHandler* unrecoverable_error_handler_;
616 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; 627 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
617 628
618 MessageLoop* const created_on_loop_; 629 MessageLoop* const created_on_loop_;
619 630
620 // The number of times we've automatically (i.e. not via SetPassphrase or 631 // The number of times we've automatically (i.e. not via SetPassphrase or
621 // conflict resolver) updated the nigori's encryption keys in this chrome 632 // conflict resolver) updated the nigori's encryption keys in this chrome
622 // instantiation. 633 // instantiation.
623 int nigori_overwrite_count_; 634 int nigori_overwrite_count_;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 DVLOG(1) << "Sync is bringing up SyncSessionContext."; 967 DVLOG(1) << "Sync is bringing up SyncSessionContext.";
957 std::vector<SyncEngineEventListener*> listeners; 968 std::vector<SyncEngineEventListener*> listeners;
958 listeners.push_back(&allstatus_); 969 listeners.push_back(&allstatus_);
959 listeners.push_back(this); 970 listeners.push_back(this);
960 SyncSessionContext* context = new SyncSessionContext( 971 SyncSessionContext* context = new SyncSessionContext(
961 connection_manager_.get(), 972 connection_manager_.get(),
962 directory(), 973 directory(),
963 model_safe_worker_registrar, 974 model_safe_worker_registrar,
964 extensions_activity_monitor, 975 extensions_activity_monitor,
965 listeners, 976 listeners,
966 &debug_info_event_listener_); 977 &debug_info_event_listener_,
978 &traffic_recorder_);
967 context->set_account_name(credentials.email); 979 context->set_account_name(credentials.email);
968 // The SyncScheduler takes ownership of |context|. 980 // The SyncScheduler takes ownership of |context|.
969 scheduler_.reset(new SyncScheduler(name_, context, new Syncer())); 981 scheduler_.reset(new SyncScheduler(name_, context, new Syncer()));
970 } 982 }
971 983
972 bool signed_in = SignIn(credentials); 984 bool signed_in = SignIn(credentials);
973 985
974 if (signed_in) { 986 if (signed_in) {
975 if (scheduler()) { 987 if (scheduler()) {
976 scheduler()->Start( 988 scheduler()->Start(
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 JsArgList SyncManager::SyncInternal::GetRootNodeDetails( 2222 JsArgList SyncManager::SyncInternal::GetRootNodeDetails(
2211 const JsArgList& args) { 2223 const JsArgList& args) {
2212 ReadTransaction trans(FROM_HERE, GetUserShare()); 2224 ReadTransaction trans(FROM_HERE, GetUserShare());
2213 ReadNode root(&trans); 2225 ReadNode root(&trans);
2214 root.InitByRootLookup(); 2226 root.InitByRootLookup();
2215 ListValue return_args; 2227 ListValue return_args;
2216 return_args.Append(root.GetDetailsAsValue()); 2228 return_args.Append(root.GetDetailsAsValue());
2217 return JsArgList(&return_args); 2229 return JsArgList(&return_args);
2218 } 2230 }
2219 2231
2232 JsArgList SyncManager::SyncInternal::GetClientServerTraffic(
2233 const JsArgList& args) {
2234 ListValue return_args;
2235 ListValue* value = traffic_recorder_.ToValue();
2236 if (value != NULL)
2237 return_args.Append(value);
2238 return JsArgList(&return_args);
2239 }
2240
2220 namespace { 2241 namespace {
2221 2242
2222 int64 GetId(const ListValue& ids, int i) { 2243 int64 GetId(const ListValue& ids, int i) {
2223 std::string id_str; 2244 std::string id_str;
2224 if (!ids.GetString(i, &id_str)) { 2245 if (!ids.GetString(i, &id_str)) {
2225 return kInvalidId; 2246 return kInvalidId;
2226 } 2247 }
2227 int64 id = kInvalidId; 2248 int64 id = kInvalidId;
2228 if (!base::StringToInt64(id_str, &id)) { 2249 if (!base::StringToInt64(id_str, &id)) {
2229 return kInvalidId; 2250 return kInvalidId;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 share->directory->GetDownloadProgress(i.Get(), &marker); 2574 share->directory->GetDownloadProgress(i.Get(), &marker);
2554 2575
2555 if (marker.token().empty()) 2576 if (marker.token().empty())
2556 result.Put(i.Get()); 2577 result.Put(i.Get());
2557 2578
2558 } 2579 }
2559 return result; 2580 return result;
2560 } 2581 }
2561 2582
2562 } // namespace sync_api 2583 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/resources/sync_internals_resources.grd ('k') | chrome/browser/ui/webui/sync_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698