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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <bitset> | 8 #include <bitset> |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 #include <queue> | 12 #include <queue> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/base64.h" | 16 #include "base/base64.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/callback.h" | 18 #include "base/callback.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/compiler_specific.h" |
20 #include "base/json/json_writer.h" | 21 #include "base/json/json_writer.h" |
21 #include "base/logging.h" | 22 #include "base/logging.h" |
22 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
23 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
24 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
25 #include "base/sha1.h" | 26 #include "base/sha1.h" |
26 #include "base/string_number_conversions.h" | 27 #include "base/string_number_conversions.h" |
27 #include "base/string_util.h" | 28 #include "base/string_util.h" |
28 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
29 #include "base/task.h" | 30 #include "base/task.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 473 |
473 if (unencrypted->has_encrypted()) { | 474 if (unencrypted->has_encrypted()) { |
474 // This specifics is already encrypted, our work is done. | 475 // This specifics is already encrypted, our work is done. |
475 LOG(WARNING) << "Attempted to encrypt an already encrypted entity" | 476 LOG(WARNING) << "Attempted to encrypt an already encrypted entity" |
476 << " specifics of type " << syncable::ModelTypeToString(type) | 477 << " specifics of type " << syncable::ModelTypeToString(type) |
477 << ". Dropping."; | 478 << ". Dropping."; |
478 return; | 479 return; |
479 } | 480 } |
480 sync_pb::EntitySpecifics encrypted; | 481 sync_pb::EntitySpecifics encrypted; |
481 syncable::AddDefaultExtensionValue(type, &encrypted); | 482 syncable::AddDefaultExtensionValue(type, &encrypted); |
482 VLOG(2) << "Encrypted specifics of type " << syncable::ModelTypeToString(type) | 483 if (VLOG_IS_ON(2)) { |
483 << " with content: " << unencrypted->SerializeAsString() << "\n"; | 484 std::string unencrypted_base64; |
| 485 if (!base::Base64Encode(unencrypted->SerializeAsString(), |
| 486 &unencrypted_base64)) { |
| 487 NOTREACHED(); |
| 488 } |
| 489 VLOG(2) << "Encrypted specifics of type " |
| 490 << syncable::ModelTypeToString(type) |
| 491 << " with content: " << unencrypted_base64 << "\n"; |
| 492 } |
484 if (!GetTransaction()->GetCryptographer()->Encrypt( | 493 if (!GetTransaction()->GetCryptographer()->Encrypt( |
485 *unencrypted, | 494 *unencrypted, |
486 encrypted.mutable_encrypted())) { | 495 encrypted.mutable_encrypted())) { |
487 LOG(ERROR) << "Could not encrypt data for node of type " << | 496 LOG(ERROR) << "Could not encrypt data for node of type " << |
488 syncable::ModelTypeToString(type); | 497 syncable::ModelTypeToString(type); |
489 NOTREACHED(); | 498 NOTREACHED(); |
490 } | 499 } |
491 unencrypted->CopyFrom(encrypted); | 500 unencrypted->CopyFrom(encrypted); |
492 } | 501 } |
493 | 502 |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 : public net::NetworkChangeNotifier::IPAddressObserver, | 1197 : public net::NetworkChangeNotifier::IPAddressObserver, |
1189 public sync_notifier::SyncNotifierObserver, | 1198 public sync_notifier::SyncNotifierObserver, |
1190 public browser_sync::JsBackend, | 1199 public browser_sync::JsBackend, |
1191 public browser_sync::JsEventRouter, | 1200 public browser_sync::JsEventRouter, |
1192 public SyncEngineEventListener, | 1201 public SyncEngineEventListener, |
1193 public ServerConnectionEventListener, | 1202 public ServerConnectionEventListener, |
1194 public syncable::DirectoryChangeListener { | 1203 public syncable::DirectoryChangeListener { |
1195 static const int kDefaultNudgeDelayMilliseconds; | 1204 static const int kDefaultNudgeDelayMilliseconds; |
1196 static const int kPreferencesNudgeDelayMilliseconds; | 1205 static const int kPreferencesNudgeDelayMilliseconds; |
1197 public: | 1206 public: |
1198 explicit SyncInternal(SyncManager* sync_manager) | 1207 SyncInternal(const std::string& name, SyncManager* sync_manager) |
1199 : core_message_loop_(NULL), | 1208 : name_(name), |
| 1209 core_message_loop_(NULL), |
1200 parent_router_(NULL), | 1210 parent_router_(NULL), |
1201 sync_manager_(sync_manager), | 1211 sync_manager_(sync_manager), |
1202 registrar_(NULL), | 1212 registrar_(NULL), |
1203 initialized_(false), | 1213 initialized_(false), |
1204 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 1214 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
1205 js_directory_change_listener_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 1215 js_directory_change_listener_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
1206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1207 // Pre-fill |notification_info_map_|. | 1217 // Pre-fill |notification_info_map_|. |
1208 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 1218 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
1209 i < syncable::MODEL_TYPE_COUNT; ++i) { | 1219 i < syncable::MODEL_TYPE_COUNT; ++i) { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 | 1600 |
1591 browser_sync::JsArgList GetNodeDetailsById( | 1601 browser_sync::JsArgList GetNodeDetailsById( |
1592 const browser_sync::JsArgList& args); | 1602 const browser_sync::JsArgList& args); |
1593 | 1603 |
1594 browser_sync::JsArgList GetChildNodeIds( | 1604 browser_sync::JsArgList GetChildNodeIds( |
1595 const browser_sync::JsArgList& args); | 1605 const browser_sync::JsArgList& args); |
1596 | 1606 |
1597 browser_sync::JsArgList FindNodesContainingString( | 1607 browser_sync::JsArgList FindNodesContainingString( |
1598 const browser_sync::JsArgList& args); | 1608 const browser_sync::JsArgList& args); |
1599 | 1609 |
| 1610 const std::string name_; |
| 1611 |
1600 // We couple the DirectoryManager and username together in a UserShare member | 1612 // We couple the DirectoryManager and username together in a UserShare member |
1601 // so we can return a handle to share_ to clients of the API for use when | 1613 // so we can return a handle to share_ to clients of the API for use when |
1602 // constructing any transaction type. | 1614 // constructing any transaction type. |
1603 UserShare share_; | 1615 UserShare share_; |
1604 | 1616 |
1605 MessageLoop* core_message_loop_; | 1617 MessageLoop* core_message_loop_; |
1606 | 1618 |
1607 ObserverList<SyncManager::Observer> observers_; | 1619 ObserverList<SyncManager::Observer> observers_; |
1608 | 1620 |
1609 browser_sync::JsEventRouter* parent_router_; | 1621 browser_sync::JsEventRouter* parent_router_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 | 1672 |
1661 browser_sync::JsDirectoryChangeListener js_directory_change_listener_; | 1673 browser_sync::JsDirectoryChangeListener js_directory_change_listener_; |
1662 | 1674 |
1663 JsMessageHandlerMap js_message_handlers_; | 1675 JsMessageHandlerMap js_message_handlers_; |
1664 }; | 1676 }; |
1665 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1677 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1666 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1678 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
1667 | 1679 |
1668 SyncManager::Observer::~Observer() {} | 1680 SyncManager::Observer::~Observer() {} |
1669 | 1681 |
1670 SyncManager::SyncManager() { | 1682 SyncManager::SyncManager(const std::string& name) |
1671 data_ = new SyncInternal(this); | 1683 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {} |
1672 } | |
1673 | 1684 |
1674 bool SyncManager::Init(const FilePath& database_location, | 1685 bool SyncManager::Init(const FilePath& database_location, |
1675 const char* sync_server_and_path, | 1686 const char* sync_server_and_path, |
1676 int sync_server_port, | 1687 int sync_server_port, |
1677 bool use_ssl, | 1688 bool use_ssl, |
1678 HttpPostProviderFactory* post_factory, | 1689 HttpPostProviderFactory* post_factory, |
1679 ModelSafeWorkerRegistrar* registrar, | 1690 ModelSafeWorkerRegistrar* registrar, |
1680 const char* user_agent, | 1691 const char* user_agent, |
1681 const SyncCredentials& credentials, | 1692 const SyncCredentials& credentials, |
1682 sync_notifier::SyncNotifier* sync_notifier, | 1693 sync_notifier::SyncNotifier* sync_notifier, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1830 std::vector<SyncEngineEventListener*> listeners; | 1841 std::vector<SyncEngineEventListener*> listeners; |
1831 listeners.push_back(&allstatus_); | 1842 listeners.push_back(&allstatus_); |
1832 listeners.push_back(this); | 1843 listeners.push_back(this); |
1833 SyncSessionContext* context = new SyncSessionContext( | 1844 SyncSessionContext* context = new SyncSessionContext( |
1834 connection_manager_.get(), | 1845 connection_manager_.get(), |
1835 dir_manager(), | 1846 dir_manager(), |
1836 model_safe_worker_registrar, | 1847 model_safe_worker_registrar, |
1837 listeners); | 1848 listeners); |
1838 context->set_account_name(credentials.email); | 1849 context->set_account_name(credentials.email); |
1839 // The SyncerThread takes ownership of |context|. | 1850 // The SyncerThread takes ownership of |context|. |
1840 syncer_thread_.reset(new SyncerThread(context, new Syncer())); | 1851 syncer_thread_.reset( |
| 1852 new SyncerThread(name_, context, new Syncer())); |
1841 } | 1853 } |
1842 | 1854 |
1843 bool signed_in = SignIn(credentials); | 1855 bool signed_in = SignIn(credentials); |
1844 | 1856 |
1845 if (signed_in && syncer_thread()) { | 1857 if (signed_in && syncer_thread()) { |
1846 syncer_thread()->Start( | 1858 syncer_thread()->Start( |
1847 browser_sync::SyncerThread::CONFIGURATION_MODE, NULL); | 1859 browser_sync::SyncerThread::CONFIGURATION_MODE, NULL); |
1848 } | 1860 } |
1849 | 1861 |
1850 // Do this once the directory is opened. | 1862 // Do this once the directory is opened. |
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3028 void SyncManager::TriggerOnIncomingNotificationForTest( | 3040 void SyncManager::TriggerOnIncomingNotificationForTest( |
3029 const syncable::ModelTypeBitSet& model_types) { | 3041 const syncable::ModelTypeBitSet& model_types) { |
3030 syncable::ModelTypePayloadMap model_types_with_payloads = | 3042 syncable::ModelTypePayloadMap model_types_with_payloads = |
3031 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3043 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3032 std::string()); | 3044 std::string()); |
3033 | 3045 |
3034 data_->OnIncomingNotification(model_types_with_payloads); | 3046 data_->OnIncomingNotification(model_types_with_payloads); |
3035 } | 3047 } |
3036 | 3048 |
3037 } // namespace sync_api | 3049 } // namespace sync_api |
OLD | NEW |