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

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

Issue 7982049: [Sync] Move some code into new class JsMutationEventObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps Created 9 years, 3 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) 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"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/sync/internal_api/read_node.h" 27 #include "chrome/browser/sync/internal_api/read_node.h"
28 #include "chrome/browser/sync/internal_api/read_transaction.h" 28 #include "chrome/browser/sync/internal_api/read_transaction.h"
29 #include "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h" 29 #include "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h"
30 #include "chrome/browser/sync/internal_api/user_share.h" 30 #include "chrome/browser/sync/internal_api/user_share.h"
31 #include "chrome/browser/sync/internal_api/write_node.h" 31 #include "chrome/browser/sync/internal_api/write_node.h"
32 #include "chrome/browser/sync/internal_api/write_transaction.h" 32 #include "chrome/browser/sync/internal_api/write_transaction.h"
33 #include "chrome/browser/sync/js/js_arg_list.h" 33 #include "chrome/browser/sync/js/js_arg_list.h"
34 #include "chrome/browser/sync/js/js_backend.h" 34 #include "chrome/browser/sync/js/js_backend.h"
35 #include "chrome/browser/sync/js/js_event_details.h" 35 #include "chrome/browser/sync/js/js_event_details.h"
36 #include "chrome/browser/sync/js/js_event_handler.h" 36 #include "chrome/browser/sync/js/js_event_handler.h"
37 #include "chrome/browser/sync/js/js_mutation_event_observer.h"
37 #include "chrome/browser/sync/js/js_reply_handler.h" 38 #include "chrome/browser/sync/js/js_reply_handler.h"
38 #include "chrome/browser/sync/js/js_sync_manager_observer.h" 39 #include "chrome/browser/sync/js/js_sync_manager_observer.h"
39 #include "chrome/browser/sync/js/js_transaction_observer.h"
40 #include "chrome/browser/sync/notifier/sync_notifier.h" 40 #include "chrome/browser/sync/notifier/sync_notifier.h"
41 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" 41 #include "chrome/browser/sync/notifier/sync_notifier_observer.h"
42 #include "chrome/browser/sync/protocol/proto_value_conversions.h" 42 #include "chrome/browser/sync/protocol/proto_value_conversions.h"
43 #include "chrome/browser/sync/protocol/sync.pb.h" 43 #include "chrome/browser/sync/protocol/sync.pb.h"
44 #include "chrome/browser/sync/syncable/directory_change_delegate.h" 44 #include "chrome/browser/sync/syncable/directory_change_delegate.h"
45 #include "chrome/browser/sync/syncable/directory_manager.h" 45 #include "chrome/browser/sync/syncable/directory_manager.h"
46 #include "chrome/browser/sync/syncable/model_type.h" 46 #include "chrome/browser/sync/syncable/model_type.h"
47 #include "chrome/browser/sync/syncable/model_type_payload_map.h" 47 #include "chrome/browser/sync/syncable/model_type_payload_map.h"
48 #include "chrome/browser/sync/syncable/syncable.h" 48 #include "chrome/browser/sync/syncable/syncable.h"
49 #include "chrome/browser/sync/util/cryptographer.h" 49 #include "chrome/browser/sync/util/cryptographer.h"
50 #include "chrome/common/chrome_switches.h" 50 #include "chrome/common/chrome_switches.h"
51 #include "net/base/network_change_notifier.h" 51 #include "net/base/network_change_notifier.h"
52 52
53 using std::string; 53 using std::string;
54 54
55 using base::TimeDelta; 55 using base::TimeDelta;
56 using browser_sync::AllStatus; 56 using browser_sync::AllStatus;
57 using browser_sync::Cryptographer; 57 using browser_sync::Cryptographer;
58 using browser_sync::JsArgList; 58 using browser_sync::JsArgList;
59 using browser_sync::JsBackend; 59 using browser_sync::JsBackend;
60 using browser_sync::JsEventDetails; 60 using browser_sync::JsEventDetails;
61 using browser_sync::JsEventHandler; 61 using browser_sync::JsEventHandler;
62 using browser_sync::JsEventHandler; 62 using browser_sync::JsEventHandler;
63 using browser_sync::JsReplyHandler; 63 using browser_sync::JsReplyHandler;
64 using browser_sync::JsMutationEventObserver;
64 using browser_sync::JsSyncManagerObserver; 65 using browser_sync::JsSyncManagerObserver;
65 using browser_sync::JsTransactionObserver;
66 using browser_sync::ModelSafeWorkerRegistrar; 66 using browser_sync::ModelSafeWorkerRegistrar;
67 using browser_sync::kNigoriTag; 67 using browser_sync::kNigoriTag;
68 using browser_sync::KeyParams; 68 using browser_sync::KeyParams;
69 using browser_sync::ModelSafeRoutingInfo; 69 using browser_sync::ModelSafeRoutingInfo;
70 using browser_sync::ServerConnectionEvent; 70 using browser_sync::ServerConnectionEvent;
71 using browser_sync::ServerConnectionEventListener; 71 using browser_sync::ServerConnectionEventListener;
72 using browser_sync::SyncEngineEvent; 72 using browser_sync::SyncEngineEvent;
73 using browser_sync::SyncEngineEventListener; 73 using browser_sync::SyncEngineEventListener;
74 using browser_sync::SyncScheduler; 74 using browser_sync::SyncScheduler;
75 using browser_sync::Syncer; 75 using browser_sync::Syncer;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 bool observing_ip_address_changes_; 542 bool observing_ip_address_changes_;
543 543
544 // Map used to store the notification info to be displayed in 544 // Map used to store the notification info to be displayed in
545 // about:sync page. 545 // about:sync page.
546 NotificationInfoMap notification_info_map_; 546 NotificationInfoMap notification_info_map_;
547 547
548 // These are for interacting with chrome://sync-internals. 548 // These are for interacting with chrome://sync-internals.
549 JsMessageHandlerMap js_message_handlers_; 549 JsMessageHandlerMap js_message_handlers_;
550 WeakHandle<JsEventHandler> js_event_handler_; 550 WeakHandle<JsEventHandler> js_event_handler_;
551 JsSyncManagerObserver js_sync_manager_observer_; 551 JsSyncManagerObserver js_sync_manager_observer_;
552 JsTransactionObserver js_transaction_observer_; 552 JsMutationEventObserver js_mutation_event_observer_;
553 }; 553 };
554 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; 554 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200;
555 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; 555 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000;
556 556
557 SyncManager::ChangeDelegate::~ChangeDelegate() {} 557 SyncManager::ChangeDelegate::~ChangeDelegate() {}
558 558
559 SyncManager::ChangeObserver::~ChangeObserver() {} 559 SyncManager::ChangeObserver::~ChangeObserver() {}
560 560
561 SyncManager::Observer::~Observer() {} 561 SyncManager::Observer::~Observer() {}
562 562
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 VLOG(1) << "Starting SyncInternal initialization."; 749 VLOG(1) << "Starting SyncInternal initialization.";
750 750
751 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); 751 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
752 752
753 registrar_ = model_safe_worker_registrar; 753 registrar_ = model_safe_worker_registrar;
754 change_delegate_ = change_delegate; 754 change_delegate_ = change_delegate;
755 setup_for_test_mode_ = setup_for_test_mode; 755 setup_for_test_mode_ = setup_for_test_mode;
756 756
757 sync_notifier_.reset(sync_notifier); 757 sync_notifier_.reset(sync_notifier);
758 758
759 AddChangeObserver(&js_sync_manager_observer_);
760 AddObserver(&js_sync_manager_observer_); 759 AddObserver(&js_sync_manager_observer_);
761 SetJsEventHandler(event_handler); 760 SetJsEventHandler(event_handler);
762 761
763 share_.dir_manager.reset(new DirectoryManager(database_location)); 762 share_.dir_manager.reset(new DirectoryManager(database_location));
764 763
765 connection_manager_.reset(new SyncAPIServerConnectionManager( 764 connection_manager_.reset(new SyncAPIServerConnectionManager(
766 sync_server_and_path, port, use_ssl, user_agent, post_factory)); 765 sync_server_and_path, port, use_ssl, user_agent, post_factory));
767 766
768 net::NetworkChangeNotifier::AddIPAddressObserver(this); 767 net::NetworkChangeNotifier::AddIPAddressObserver(this);
769 observing_ip_address_changes_ = true; 768 observing_ip_address_changes_ = true;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } 889 }
891 890
892 // Database has to be initialized for the guid to be available. 891 // Database has to be initialized for the guid to be available.
893 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); 892 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share());
894 if (!lookup.good()) { 893 if (!lookup.good()) {
895 NOTREACHED(); 894 NOTREACHED();
896 return false; 895 return false;
897 } 896 }
898 897
899 connection_manager()->set_client_id(lookup->cache_guid()); 898 connection_manager()->set_client_id(lookup->cache_guid());
900 lookup->AddTransactionObserver(&js_transaction_observer_); 899 lookup->AddTransactionObserver(&js_mutation_event_observer_);
900 AddChangeObserver(&js_mutation_event_observer_);
901 return true; 901 return true;
902 } 902 }
903 903
904 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { 904 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) {
905 DCHECK(thread_checker_.CalledOnValidThread()); 905 DCHECK(thread_checker_.CalledOnValidThread());
906 DCHECK(share_.name.empty()); 906 DCHECK(share_.name.empty());
907 share_.name = credentials.email; 907 share_.name = credentials.email;
908 908
909 VLOG(1) << "Signing in user: " << username_for_share(); 909 VLOG(1) << "Signing in user: " << username_for_share();
910 if (!OpenDirectory()) 910 if (!OpenDirectory())
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 DCHECK(thread_checker_.CalledOnValidThread()); 1255 DCHECK(thread_checker_.CalledOnValidThread());
1256 1256
1257 // Prevent any in-flight method calls from running. Also 1257 // Prevent any in-flight method calls from running. Also
1258 // invalidates |weak_handle_this_|. 1258 // invalidates |weak_handle_this_|.
1259 weak_ptr_factory_.InvalidateWeakPtrs(); 1259 weak_ptr_factory_.InvalidateWeakPtrs();
1260 1260
1261 // Automatically stops the scheduler. 1261 // Automatically stops the scheduler.
1262 scheduler_.reset(); 1262 scheduler_.reset();
1263 1263
1264 SetJsEventHandler(WeakHandle<JsEventHandler>()); 1264 SetJsEventHandler(WeakHandle<JsEventHandler>());
1265 RemoveChangeObserver(&js_sync_manager_observer_);
1266 RemoveObserver(&js_sync_manager_observer_); 1265 RemoveObserver(&js_sync_manager_observer_);
1267 1266
1268 if (sync_notifier_.get()) { 1267 if (sync_notifier_.get()) {
1269 sync_notifier_->RemoveObserver(this); 1268 sync_notifier_->RemoveObserver(this);
1270 } 1269 }
1271 sync_notifier_.reset(); 1270 sync_notifier_.reset();
1272 1271
1273 if (connection_manager_.get()) { 1272 if (connection_manager_.get()) {
1274 connection_manager_->RemoveListener(this); 1273 connection_manager_->RemoveListener(this);
1275 } 1274 }
1276 connection_manager_.reset(); 1275 connection_manager_.reset();
1277 1276
1278 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 1277 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
1279 observing_ip_address_changes_ = false; 1278 observing_ip_address_changes_ = false;
1280 1279
1281 if (dir_manager()) { 1280 if (dir_manager()) {
1282 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); 1281 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share());
1283 if (lookup.good()) { 1282 if (lookup.good()) {
1284 lookup->RemoveTransactionObserver(&js_transaction_observer_); 1283 lookup->RemoveTransactionObserver(&js_mutation_event_observer_);
1284 RemoveChangeObserver(&js_mutation_event_observer_);
1285 } else { 1285 } else {
1286 NOTREACHED(); 1286 NOTREACHED();
1287 } 1287 }
1288 dir_manager()->FinalSaveChangesForAll(); 1288 dir_manager()->FinalSaveChangesForAll();
1289 dir_manager()->Close(username_for_share()); 1289 dir_manager()->Close(username_for_share());
1290 } 1290 }
1291 1291
1292 // Reset the DirectoryManager and UserSettings so they relinquish sqlite 1292 // Reset the DirectoryManager and UserSettings so they relinquish sqlite
1293 // handles to backing files. 1293 // handles to backing files.
1294 share_.dir_manager.reset(); 1294 share_.dir_manager.reset();
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 event.snapshot->errors.sync_protocol_error)); 1673 event.snapshot->errors.sync_protocol_error));
1674 return; 1674 return;
1675 } 1675 }
1676 1676
1677 } 1677 }
1678 1678
1679 void SyncManager::SyncInternal::SetJsEventHandler( 1679 void SyncManager::SyncInternal::SetJsEventHandler(
1680 const WeakHandle<JsEventHandler>& event_handler) { 1680 const WeakHandle<JsEventHandler>& event_handler) {
1681 js_event_handler_ = event_handler; 1681 js_event_handler_ = event_handler;
1682 js_sync_manager_observer_.SetJsEventHandler(js_event_handler_); 1682 js_sync_manager_observer_.SetJsEventHandler(js_event_handler_);
1683 js_transaction_observer_.SetJsEventHandler(js_event_handler_); 1683 js_mutation_event_observer_.SetJsEventHandler(js_event_handler_);
1684 } 1684 }
1685 1685
1686 void SyncManager::SyncInternal::ProcessJsMessage( 1686 void SyncManager::SyncInternal::ProcessJsMessage(
1687 const std::string& name, const JsArgList& args, 1687 const std::string& name, const JsArgList& args,
1688 const WeakHandle<JsReplyHandler>& reply_handler) { 1688 const WeakHandle<JsReplyHandler>& reply_handler) {
1689 if (!initialized_) { 1689 if (!initialized_) {
1690 NOTREACHED(); 1690 NOTREACHED();
1691 return; 1691 return;
1692 } 1692 }
1693 1693
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 2062
2063 for (syncable::ModelTypeSet::const_iterator i = types.begin(); 2063 for (syncable::ModelTypeSet::const_iterator i = types.begin();
2064 i != types.end(); ++i) { 2064 i != types.end(); ++i) {
2065 if (!lookup->initial_sync_ended_for_type(*i)) 2065 if (!lookup->initial_sync_ended_for_type(*i))
2066 return false; 2066 return false;
2067 } 2067 }
2068 return true; 2068 return true;
2069 } 2069 }
2070 2070
2071 } // namespace sync_api 2071 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/resources/sync_internals/chrome_sync.js ('k') | chrome/browser/sync/js/js_mutation_event_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698