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