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

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

Issue 10454105: sync: Refactor per-datatype throttling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 6 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
« no previous file with comments | « sync/internal_api/sync_manager.h ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "sync/internal_api/sync_manager.h" 5 #include "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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
21 #include "sync/engine/all_status.h"
21 #include "sync/engine/net/server_connection_manager.h" 22 #include "sync/engine/net/server_connection_manager.h"
22 #include "sync/engine/nigori_util.h" 23 #include "sync/engine/nigori_util.h"
23 #include "sync/engine/sync_scheduler.h" 24 #include "sync/engine/sync_scheduler.h"
24 #include "sync/engine/syncer_types.h" 25 #include "sync/engine/syncer_types.h"
25 #include "sync/internal_api/all_status.h" 26 #include "sync/engine/throttled_data_type_tracker.h"
26 #include "sync/internal_api/base_node.h" 27 #include "sync/internal_api/base_node.h"
27 #include "sync/internal_api/change_reorder_buffer.h" 28 #include "sync/internal_api/change_reorder_buffer.h"
28 #include "sync/internal_api/configure_reason.h" 29 #include "sync/internal_api/configure_reason.h"
29 #include "sync/internal_api/debug_info_event_listener.h" 30 #include "sync/internal_api/debug_info_event_listener.h"
30 #include "sync/internal_api/js_mutation_event_observer.h" 31 #include "sync/internal_api/js_mutation_event_observer.h"
31 #include "sync/internal_api/js_sync_manager_observer.h" 32 #include "sync/internal_api/js_sync_manager_observer.h"
32 #include "sync/internal_api/public/engine/polling_constants.h" 33 #include "sync/internal_api/public/engine/polling_constants.h"
33 #include "sync/internal_api/public/syncable/model_type.h" 34 #include "sync/internal_api/public/syncable/model_type.h"
34 #include "sync/internal_api/public/syncable/model_type_payload_map.h" 35 #include "sync/internal_api/public/syncable/model_type_payload_map.h"
35 #include "sync/internal_api/read_node.h" 36 #include "sync/internal_api/read_node.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 public ServerConnectionEventListener, 138 public ServerConnectionEventListener,
138 public syncable::DirectoryChangeDelegate { 139 public syncable::DirectoryChangeDelegate {
139 public: 140 public:
140 explicit SyncInternal(const std::string& name) 141 explicit SyncInternal(const std::string& name)
141 : name_(name), 142 : name_(name),
142 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 143 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
143 change_delegate_(NULL), 144 change_delegate_(NULL),
144 initialized_(false), 145 initialized_(false),
145 testing_mode_(NON_TEST), 146 testing_mode_(NON_TEST),
146 observing_ip_address_changes_(false), 147 observing_ip_address_changes_(false),
148 throttled_data_type_tracker_(&allstatus_),
147 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), 149 traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord),
148 encryptor_(NULL), 150 encryptor_(NULL),
149 unrecoverable_error_handler_(NULL), 151 unrecoverable_error_handler_(NULL),
150 report_unrecoverable_error_function_(NULL), 152 report_unrecoverable_error_function_(NULL),
151 created_on_loop_(MessageLoop::current()), 153 created_on_loop_(MessageLoop::current()),
152 nigori_overwrite_count_(0) { 154 nigori_overwrite_count_(0) {
153 // Pre-fill |notification_info_map_|. 155 // Pre-fill |notification_info_map_|.
154 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 156 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
155 i < syncable::MODEL_TYPE_COUNT; ++i) { 157 i < syncable::MODEL_TYPE_COUNT; ++i) {
156 notification_info_map_.insert( 158 notification_info_map_.insert(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 DCHECK(initialized_); 341 DCHECK(initialized_);
340 return &share_; 342 return &share_;
341 } 343 }
342 344
343 // Return the currently active (validated) username for use with syncable 345 // Return the currently active (validated) username for use with syncable
344 // types. 346 // types.
345 const std::string& username_for_share() const { 347 const std::string& username_for_share() const {
346 return share_.name; 348 return share_.name;
347 } 349 }
348 350
349 Status GetStatus(); 351 SyncStatus GetStatus();
350 352
351 void RequestNudge(const tracked_objects::Location& nudge_location); 353 void RequestNudge(const tracked_objects::Location& nudge_location);
352 354
353 void RequestNudgeForDataTypes( 355 void RequestNudgeForDataTypes(
354 const tracked_objects::Location& nudge_location, 356 const tracked_objects::Location& nudge_location,
355 ModelTypeSet type); 357 ModelTypeSet type);
356 358
357 TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type); 359 TimeDelta GetNudgeDelayTimeDelta(const ModelType& model_type);
358 360
359 void NotifyCryptographerState(Cryptographer* cryptographer); 361 void NotifyCryptographerState(Cryptographer* cryptographer);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // Map used to store the notification info to be displayed in 597 // Map used to store the notification info to be displayed in
596 // about:sync page. 598 // about:sync page.
597 NotificationInfoMap notification_info_map_; 599 NotificationInfoMap notification_info_map_;
598 600
599 // These are for interacting with chrome://sync-internals. 601 // These are for interacting with chrome://sync-internals.
600 JsMessageHandlerMap js_message_handlers_; 602 JsMessageHandlerMap js_message_handlers_;
601 WeakHandle<JsEventHandler> js_event_handler_; 603 WeakHandle<JsEventHandler> js_event_handler_;
602 JsSyncManagerObserver js_sync_manager_observer_; 604 JsSyncManagerObserver js_sync_manager_observer_;
603 JsMutationEventObserver js_mutation_event_observer_; 605 JsMutationEventObserver js_mutation_event_observer_;
604 606
607 browser_sync::ThrottledDataTypeTracker throttled_data_type_tracker_;
608
605 // This is for keeping track of client events to send to the server. 609 // This is for keeping track of client events to send to the server.
606 DebugInfoEventListener debug_info_event_listener_; 610 DebugInfoEventListener debug_info_event_listener_;
607 611
608 browser_sync::TrafficRecorder traffic_recorder_; 612 browser_sync::TrafficRecorder traffic_recorder_;
609 613
610 Encryptor* encryptor_; 614 Encryptor* encryptor_;
611 UnrecoverableErrorHandler* unrecoverable_error_handler_; 615 UnrecoverableErrorHandler* unrecoverable_error_handler_;
612 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; 616 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
613 617
614 MessageLoop* const created_on_loop_; 618 MessageLoop* const created_on_loop_;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 699
696 SyncManager::ChangeDelegate::~ChangeDelegate() {} 700 SyncManager::ChangeDelegate::~ChangeDelegate() {}
697 701
698 SyncManager::ChangeObserver::~ChangeObserver() {} 702 SyncManager::ChangeObserver::~ChangeObserver() {}
699 703
700 SyncManager::Observer::~Observer() {} 704 SyncManager::Observer::~Observer() {}
701 705
702 SyncManager::SyncManager(const std::string& name) 706 SyncManager::SyncManager(const std::string& name)
703 : data_(new SyncInternal(name)) {} 707 : data_(new SyncInternal(name)) {}
704 708
705 SyncManager::Status::Status()
706 : notifications_enabled(false),
707 notifications_received(0),
708 encryption_conflicts(0),
709 hierarchy_conflicts(0),
710 simple_conflicts(0),
711 server_conflicts(0),
712 committed_count(0),
713 syncing(false),
714 initial_sync_ended(false),
715 updates_available(0),
716 updates_received(0),
717 reflected_updates_received(0),
718 tombstone_updates_received(0),
719 num_commits_total(0),
720 num_local_overwrites_total(0),
721 num_server_overwrites_total(0),
722 nonempty_get_updates(0),
723 empty_get_updates(0),
724 sync_cycles_with_commits(0),
725 sync_cycles_without_commits(0),
726 useless_sync_cycles(0),
727 useful_sync_cycles(0),
728 cryptographer_ready(false),
729 crypto_has_pending_keys(false) {
730 }
731
732 SyncManager::Status::~Status() {
733 }
734
735 bool SyncManager::Init( 709 bool SyncManager::Init(
736 const FilePath& database_location, 710 const FilePath& database_location,
737 const WeakHandle<JsEventHandler>& event_handler, 711 const WeakHandle<JsEventHandler>& event_handler,
738 const std::string& sync_server_and_path, 712 const std::string& sync_server_and_path,
739 int sync_server_port, 713 int sync_server_port,
740 bool use_ssl, 714 bool use_ssl,
741 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 715 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
742 HttpPostProviderFactory* post_factory, 716 HttpPostProviderFactory* post_factory,
743 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info, 717 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info,
744 const std::vector<browser_sync::ModelSafeWorker*>& workers, 718 const std::vector<browser_sync::ModelSafeWorker*>& workers,
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 DVLOG(1) << "Sync is bringing up SyncSessionContext."; 922 DVLOG(1) << "Sync is bringing up SyncSessionContext.";
949 std::vector<SyncEngineEventListener*> listeners; 923 std::vector<SyncEngineEventListener*> listeners;
950 listeners.push_back(&allstatus_); 924 listeners.push_back(&allstatus_);
951 listeners.push_back(this); 925 listeners.push_back(this);
952 session_context_.reset(new SyncSessionContext( 926 session_context_.reset(new SyncSessionContext(
953 connection_manager_.get(), 927 connection_manager_.get(),
954 directory(), 928 directory(),
955 model_safe_routing_info, 929 model_safe_routing_info,
956 workers, 930 workers,
957 extensions_activity_monitor, 931 extensions_activity_monitor,
932 &throttled_data_type_tracker_,
958 listeners, 933 listeners,
959 &debug_info_event_listener_, 934 &debug_info_event_listener_,
960 &traffic_recorder_)); 935 &traffic_recorder_));
961 session_context()->set_account_name(credentials.email); 936 session_context()->set_account_name(credentials.email);
962 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); 937 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer()));
963 } 938 }
964 939
965 bool signed_in = SignIn(credentials); 940 bool signed_in = SignIn(credentials);
966 941
967 if (signed_in) { 942 if (signed_in) {
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 VisiblePropertiesDiffer(it->second, crypto)) { 1927 VisiblePropertiesDiffer(it->second, crypto)) {
1953 change_buffers_[type].PushUpdatedItem( 1928 change_buffers_[type].PushUpdatedItem(
1954 handle, VisiblePositionsDiffer(it->second)); 1929 handle, VisiblePositionsDiffer(it->second));
1955 } 1930 }
1956 1931
1957 SetExtraChangeRecordData(handle, type, &change_buffers_[type], crypto, 1932 SetExtraChangeRecordData(handle, type, &change_buffers_[type], crypto,
1958 it->second.original, existed_before, exists_now); 1933 it->second.original, existed_before, exists_now);
1959 } 1934 }
1960 } 1935 }
1961 1936
1962 SyncManager::Status SyncManager::SyncInternal::GetStatus() { 1937 SyncStatus SyncManager::SyncInternal::GetStatus() {
1963 return allstatus_.status(); 1938 return allstatus_.status();
1964 } 1939 }
1965 1940
1966 void SyncManager::SyncInternal::RequestNudge( 1941 void SyncManager::SyncInternal::RequestNudge(
1967 const tracked_objects::Location& location) { 1942 const tracked_objects::Location& location) {
1968 if (scheduler()) { 1943 if (scheduler()) {
1969 scheduler()->ScheduleNudge( 1944 scheduler()->ScheduleNudge(
1970 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL, 1945 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL,
1971 ModelTypeSet(), location); 1946 ModelTypeSet(), location);
1972 } 1947 }
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 void SyncManager::SyncInternal::AddObserver( 2346 void SyncManager::SyncInternal::AddObserver(
2372 SyncManager::Observer* observer) { 2347 SyncManager::Observer* observer) {
2373 observers_.AddObserver(observer); 2348 observers_.AddObserver(observer);
2374 } 2349 }
2375 2350
2376 void SyncManager::SyncInternal::RemoveObserver( 2351 void SyncManager::SyncInternal::RemoveObserver(
2377 SyncManager::Observer* observer) { 2352 SyncManager::Observer* observer) {
2378 observers_.RemoveObserver(observer); 2353 observers_.RemoveObserver(observer);
2379 } 2354 }
2380 2355
2381 SyncManager::Status SyncManager::GetDetailedStatus() const { 2356 SyncStatus SyncManager::GetDetailedStatus() const {
2382 return data_->GetStatus(); 2357 return data_->GetStatus();
2383 } 2358 }
2384 2359
2385 void SyncManager::SaveChanges() { 2360 void SyncManager::SaveChanges() {
2386 DCHECK(thread_checker_.CalledOnValidThread()); 2361 DCHECK(thread_checker_.CalledOnValidThread());
2387 data_->SaveChanges(); 2362 data_->SaveChanges();
2388 } 2363 }
2389 2364
2390 void SyncManager::SyncInternal::SaveChanges() { 2365 void SyncManager::SyncInternal::SaveChanges() {
2391 directory()->SaveChanges(); 2366 directory()->SaveChanges();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 share->directory->GetDownloadProgress(i.Get(), &marker); 2477 share->directory->GetDownloadProgress(i.Get(), &marker);
2503 2478
2504 if (marker.token().empty()) 2479 if (marker.token().empty())
2505 result.Put(i.Get()); 2480 result.Put(i.Get());
2506 2481
2507 } 2482 }
2508 return result; 2483 return result;
2509 } 2484 }
2510 2485
2511 } // namespace sync_api 2486 } // namespace sync_api
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager.h ('k') | sync/sessions/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698