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> |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 JsMessageHandlerMap js_message_handlers_; | 1638 JsMessageHandlerMap js_message_handlers_; |
1639 }; | 1639 }; |
1640 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1640 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1641 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1641 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
1642 | 1642 |
1643 SyncManager::Observer::~Observer() {} | 1643 SyncManager::Observer::~Observer() {} |
1644 | 1644 |
1645 SyncManager::SyncManager(const std::string& name) | 1645 SyncManager::SyncManager(const std::string& name) |
1646 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {} | 1646 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {} |
1647 | 1647 |
1648 SyncManager::Status::Status() { | 1648 SyncManager::Status::Status() |
| 1649 : summary(INVALID), |
| 1650 authenticated(false), |
| 1651 server_up(false), |
| 1652 server_reachable(false), |
| 1653 server_broken(false), |
| 1654 notifications_enabled(false), |
| 1655 notifications_received(0), |
| 1656 notifiable_commits(0), |
| 1657 max_consecutive_errors(0), |
| 1658 unsynced_count(0), |
| 1659 conflicting_count(0), |
| 1660 syncing(false), |
| 1661 initial_sync_ended(false), |
| 1662 syncer_stuck(false), |
| 1663 updates_available(0), |
| 1664 updates_received(0), |
| 1665 tombstone_updates_received(0), |
| 1666 disk_full(false), |
| 1667 num_local_overwrites_total(0), |
| 1668 num_server_overwrites_total(0), |
| 1669 nonempty_get_updates(0), |
| 1670 empty_get_updates(0), |
| 1671 useless_sync_cycles(0), |
| 1672 useful_sync_cycles(0), |
| 1673 cryptographer_ready(false), |
| 1674 crypto_has_pending_keys(false) { |
1649 } | 1675 } |
1650 | 1676 |
1651 SyncManager::Status::~Status() { | 1677 SyncManager::Status::~Status() { |
1652 } | 1678 } |
1653 | 1679 |
1654 bool SyncManager::Init(const FilePath& database_location, | 1680 bool SyncManager::Init(const FilePath& database_location, |
1655 const std::string& sync_server_and_path, | 1681 const std::string& sync_server_and_path, |
1656 int sync_server_port, | 1682 int sync_server_port, |
1657 bool use_ssl, | 1683 bool use_ssl, |
1658 HttpPostProviderFactory* post_factory, | 1684 HttpPostProviderFactory* post_factory, |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2087 WriteNode node(&trans); | 2113 WriteNode node(&trans); |
2088 if (!node.InitByTagLookup(kNigoriTag)) { | 2114 if (!node.InitByTagLookup(kNigoriTag)) { |
2089 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " | 2115 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " |
2090 << "found."; | 2116 << "found."; |
2091 return; | 2117 return; |
2092 } | 2118 } |
2093 | 2119 |
2094 Cryptographer* cryptographer = trans.GetCryptographer(); | 2120 Cryptographer* cryptographer = trans.GetCryptographer(); |
2095 | 2121 |
2096 if (!cryptographer->is_initialized()) { | 2122 if (!cryptographer->is_initialized()) { |
2097 NOTREACHED() << "Attempting to encrypt datatypes when cryptographer not " | 2123 VLOG(1) << "Attempting to encrypt datatypes when cryptographer not " |
2098 << "initialized."; | 2124 << "initialized, prompting for passphrase."; |
| 2125 ObserverList<SyncManager::Observer> temp_obs_list; |
| 2126 CopyObservers(&temp_obs_list); |
| 2127 // TODO(zea): this isn't really decryption, but that's the only way we have |
| 2128 // to prompt the user for a passsphrase. See http://crbug.com/91379. |
| 2129 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
| 2130 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); |
2099 return; | 2131 return; |
2100 } | 2132 } |
2101 | 2133 |
2102 // Update the Nigori node set of encrypted datatypes so other machines notice. | 2134 // Update the Nigori node's set of encrypted datatypes. |
2103 // Note, we merge the current encrypted types with those requested. Once a | 2135 // Note, we merge the current encrypted types with those requested. Once a |
2104 // datatypes is marked as needing encryption, it is never unmarked. | 2136 // datatypes is marked as needing encryption, it is never unmarked. |
2105 sync_pb::NigoriSpecifics nigori; | 2137 sync_pb::NigoriSpecifics nigori; |
2106 nigori.CopyFrom(node.GetNigoriSpecifics()); | 2138 nigori.CopyFrom(node.GetNigoriSpecifics()); |
2107 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); | 2139 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); |
2108 syncable::ModelTypeSet newly_encrypted_types; | 2140 syncable::ModelTypeSet newly_encrypted_types; |
2109 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), | 2141 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), |
2110 encrypted_types.begin(), encrypted_types.end(), | 2142 encrypted_types.begin(), encrypted_types.end(), |
2111 std::inserter(newly_encrypted_types, | 2143 std::inserter(newly_encrypted_types, |
2112 newly_encrypted_types.begin())); | 2144 newly_encrypted_types.begin())); |
2113 allstatus_.SetEncryptedTypes(newly_encrypted_types); | 2145 allstatus_.SetEncryptedTypes(newly_encrypted_types); |
2114 if (newly_encrypted_types == current_encrypted_types) | 2146 if (newly_encrypted_types == current_encrypted_types) { |
2115 return; // Set of encrypted types did not change. | 2147 // Set of encrypted types has not changed, just notify and return. |
| 2148 ObserverList<SyncManager::Observer> temp_obs_list; |
| 2149 CopyObservers(&temp_obs_list); |
| 2150 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
| 2151 OnEncryptionComplete(current_encrypted_types)); |
| 2152 return; |
| 2153 } |
2116 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); | 2154 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); |
2117 node.SetNigoriSpecifics(nigori); | 2155 node.SetNigoriSpecifics(nigori); |
2118 | 2156 |
2119 cryptographer->SetEncryptedTypes(nigori); | 2157 cryptographer->SetEncryptedTypes(nigori); |
2120 | 2158 |
2121 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a | 2159 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a |
2122 // safer approach, and should not impact anything that is already encrypted | 2160 // safer approach, and should not impact anything that is already encrypted |
2123 // (redundant changes are ignored). | 2161 // (redundant changes are ignored). |
2124 ReEncryptEverything(&trans); | 2162 ReEncryptEverything(&trans); |
2125 return; | 2163 return; |
(...skipping 24 matching lines...) Expand all Loading... |
2150 to_visit.push(child_id); | 2188 to_visit.push(child_id); |
2151 while (!to_visit.empty()) { | 2189 while (!to_visit.empty()) { |
2152 child_id = to_visit.front(); | 2190 child_id = to_visit.front(); |
2153 to_visit.pop(); | 2191 to_visit.pop(); |
2154 if (child_id == kInvalidId) | 2192 if (child_id == kInvalidId) |
2155 continue; | 2193 continue; |
2156 | 2194 |
2157 WriteNode child(trans); | 2195 WriteNode child(trans); |
2158 if (!child.InitByIdLookup(child_id)) { | 2196 if (!child.InitByIdLookup(child_id)) { |
2159 NOTREACHED(); | 2197 NOTREACHED(); |
2160 return; | 2198 continue; |
2161 } | 2199 } |
2162 if (child.GetIsFolder()) { | 2200 if (child.GetIsFolder()) { |
2163 to_visit.push(child.GetFirstChildId()); | 2201 to_visit.push(child.GetFirstChildId()); |
2164 } | 2202 } |
2165 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { | 2203 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { |
2166 // Rewrite the specifics of the node with encrypted data if necessary | 2204 // Rewrite the specifics of the node with encrypted data if necessary |
2167 // (only rewrite the non-unique folders). | 2205 // (only rewrite the non-unique folders). |
2168 child.ResetFromSpecifics(); | 2206 child.ResetFromSpecifics(); |
2169 } | 2207 } |
2170 to_visit.push(child.GetSuccessorId()); | 2208 to_visit.push(child.GetSuccessorId()); |
2171 } | 2209 } |
2172 } | 2210 } |
2173 | 2211 |
2174 if (routes.count(syncable::PASSWORDS) > 0) { | 2212 if (routes.count(syncable::PASSWORDS) > 0) { |
2175 // Passwords are encrypted with their own legacy scheme. | 2213 // Passwords are encrypted with their own legacy scheme. |
2176 ReadNode passwords_root(trans); | 2214 ReadNode passwords_root(trans); |
2177 std::string passwords_tag = | 2215 std::string passwords_tag = |
2178 syncable::ModelTypeToRootTag(syncable::PASSWORDS); | 2216 syncable::ModelTypeToRootTag(syncable::PASSWORDS); |
2179 if (!passwords_root.InitByTagLookup(passwords_tag)) { | 2217 // It's possible we'll have the password routing info and not the password |
2180 LOG(WARNING) << "No passwords to reencrypt."; | 2218 // root if we attempted to SetPassphrase before passwords was enabled. |
2181 return; | 2219 if (passwords_root.InitByTagLookup(passwords_tag)) { |
2182 } | 2220 int64 child_id = passwords_root.GetFirstChildId(); |
2183 | 2221 while (child_id != kInvalidId) { |
2184 int64 child_id = passwords_root.GetFirstChildId(); | 2222 WriteNode child(trans); |
2185 while (child_id != kInvalidId) { | 2223 if (!child.InitByIdLookup(child_id)) { |
2186 WriteNode child(trans); | 2224 NOTREACHED(); |
2187 if (!child.InitByIdLookup(child_id)) { | 2225 return; |
2188 NOTREACHED(); | 2226 } |
2189 return; | 2227 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); |
| 2228 child_id = child.GetSuccessorId(); |
2190 } | 2229 } |
2191 child.SetPasswordSpecifics(child.GetPasswordSpecifics()); | |
2192 child_id = child.GetSuccessorId(); | |
2193 } | 2230 } |
2194 } | 2231 } |
2195 | 2232 |
2196 ObserverList<SyncManager::Observer> temp_obs_list; | 2233 ObserverList<SyncManager::Observer> temp_obs_list; |
2197 CopyObservers(&temp_obs_list); | 2234 CopyObservers(&temp_obs_list); |
2198 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2235 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2199 OnEncryptionComplete(encrypted_types)); | 2236 OnEncryptionComplete(encrypted_types)); |
2200 } | 2237 } |
2201 | 2238 |
2202 SyncManager::~SyncManager() { | 2239 SyncManager::~SyncManager() { |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3064 void SyncManager::TriggerOnIncomingNotificationForTest( | 3101 void SyncManager::TriggerOnIncomingNotificationForTest( |
3065 const syncable::ModelTypeBitSet& model_types) { | 3102 const syncable::ModelTypeBitSet& model_types) { |
3066 syncable::ModelTypePayloadMap model_types_with_payloads = | 3103 syncable::ModelTypePayloadMap model_types_with_payloads = |
3067 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3104 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3068 std::string()); | 3105 std::string()); |
3069 | 3106 |
3070 data_->OnIncomingNotification(model_types_with_payloads); | 3107 data_->OnIncomingNotification(model_types_with_payloads); |
3071 } | 3108 } |
3072 | 3109 |
3073 } // namespace sync_api | 3110 } // namespace sync_api |
OLD | NEW |