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

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 7795016: Merge 98758 - [Sync] Gracefully handle writing to a node when the cryptographer is not ready. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/835/src/
Patch Set: 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/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 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 cryptographer->Update(node.GetNigoriSpecifics()); 1920 cryptographer->Update(node.GetNigoriSpecifics());
1921 if (result == Cryptographer::NEEDS_PASSPHRASE) { 1921 if (result == Cryptographer::NEEDS_PASSPHRASE) {
1922 ObserverList<SyncManager::Observer> temp_obs_list; 1922 ObserverList<SyncManager::Observer> temp_obs_list;
1923 CopyObservers(&temp_obs_list); 1923 CopyObservers(&temp_obs_list);
1924 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 1924 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
1925 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); 1925 OnPassphraseRequired(sync_api::REASON_DECRYPTION));
1926 } 1926 }
1927 1927
1928 allstatus_.SetCryptographerReady(cryptographer->is_ready()); 1928 allstatus_.SetCryptographerReady(cryptographer->is_ready());
1929 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); 1929 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys());
1930 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
1930 1931
1931 return cryptographer->is_ready(); 1932 return cryptographer->is_ready();
1932 } 1933 }
1933 1934
1934 void SyncManager::SyncInternal::StartSyncingNormally() { 1935 void SyncManager::SyncInternal::StartSyncingNormally() {
1935 // Start the sync scheduler. This won't actually result in any 1936 // Start the sync scheduler. This won't actually result in any
1936 // syncing until at least the DirectoryManager broadcasts the OPENED 1937 // syncing until at least the DirectoryManager broadcasts the OPENED
1937 // event, and a valid server connection is detected. 1938 // event, and a valid server connection is detected.
1938 if (scheduler()) // NULL during certain unittests. 1939 if (scheduler()) // NULL during certain unittests.
1939 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); 1940 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 2108
2108 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require 2109 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require
2109 // messing with the Nigori node, because we can't call SetPassphrase until 2110 // messing with the Nigori node, because we can't call SetPassphrase until
2110 // download conditions are met vs Cryptographer init. It seems like it's 2111 // download conditions are met vs Cryptographer init. It seems like it's
2111 // safe to defer this work. 2112 // safe to defer this work.
2112 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics()); 2113 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics());
2113 specifics.clear_encrypted(); 2114 specifics.clear_encrypted();
2114 cryptographer->GetKeys(specifics.mutable_encrypted()); 2115 cryptographer->GetKeys(specifics.mutable_encrypted());
2115 specifics.set_using_explicit_passphrase(is_explicit); 2116 specifics.set_using_explicit_passphrase(is_explicit);
2116 node.SetNigoriSpecifics(specifics); 2117 node.SetNigoriSpecifics(specifics);
2117 ReEncryptEverything(&trans);
2118 } 2118 }
2119 2119
2120 // Does nothing if everything is already encrypted or the cryptographer has
2121 // pending keys.
2122 ReEncryptEverything(&trans);
2123
2120 VLOG(1) << "Passphrase accepted, bootstrapping encryption."; 2124 VLOG(1) << "Passphrase accepted, bootstrapping encryption.";
2121 std::string bootstrap_token; 2125 std::string bootstrap_token;
2122 cryptographer->GetBootstrapToken(&bootstrap_token); 2126 cryptographer->GetBootstrapToken(&bootstrap_token);
2123 ObserverList<SyncManager::Observer> temp_obs_list; 2127 ObserverList<SyncManager::Observer> temp_obs_list;
2124 CopyObservers(&temp_obs_list); 2128 CopyObservers(&temp_obs_list);
2125 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 2129 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
2126 OnPassphraseAccepted(bootstrap_token)); 2130 OnPassphraseAccepted(bootstrap_token));
2127 } 2131 }
2128 2132
2129 bool SyncManager::SyncInternal::IsUsingExplicitPassphrase() { 2133 bool SyncManager::SyncInternal::IsUsingExplicitPassphrase() {
(...skipping 17 matching lines...) Expand all
2147 WriteTransaction trans(FROM_HERE, GetUserShare()); 2151 WriteTransaction trans(FROM_HERE, GetUserShare());
2148 WriteNode node(&trans); 2152 WriteNode node(&trans);
2149 if (!node.InitByTagLookup(kNigoriTag)) { 2153 if (!node.InitByTagLookup(kNigoriTag)) {
2150 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " 2154 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not "
2151 << "found."; 2155 << "found.";
2152 return; 2156 return;
2153 } 2157 }
2154 2158
2155 Cryptographer* cryptographer = trans.GetCryptographer(); 2159 Cryptographer* cryptographer = trans.GetCryptographer();
2156 2160
2157 if (!cryptographer->is_initialized()) { 2161 if (!cryptographer->is_ready()) {
2158 VLOG(1) << "Attempting to encrypt datatypes when cryptographer not " 2162 VLOG(1) << "Attempting to encrypt datatypes when cryptographer not "
2159 << "initialized, prompting for passphrase."; 2163 << "initialized, prompting for passphrase.";
2160 ObserverList<SyncManager::Observer> temp_obs_list; 2164 ObserverList<SyncManager::Observer> temp_obs_list;
2161 CopyObservers(&temp_obs_list); 2165 CopyObservers(&temp_obs_list);
2162 // TODO(zea): this isn't really decryption, but that's the only way we have 2166 // TODO(zea): this isn't really decryption, but that's the only way we have
2163 // to prompt the user for a passsphrase. See http://crbug.com/91379. 2167 // to prompt the user for a passsphrase. See http://crbug.com/91379.
2164 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 2168 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
2165 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); 2169 OnPassphraseRequired(sync_api::REASON_DECRYPTION));
2166 return; 2170 return;
2167 } 2171 }
2168 2172
2169 // Update the Nigori node's set of encrypted datatypes. 2173 // Update the Nigori node's set of encrypted datatypes.
2170 // Note, we merge the current encrypted types with those requested. Once a 2174 // Note, we merge the current encrypted types with those requested. Once a
2171 // datatypes is marked as needing encryption, it is never unmarked. 2175 // datatypes is marked as needing encryption, it is never unmarked.
2172 sync_pb::NigoriSpecifics nigori; 2176 sync_pb::NigoriSpecifics nigori;
2173 nigori.CopyFrom(node.GetNigoriSpecifics()); 2177 nigori.CopyFrom(node.GetNigoriSpecifics());
2174 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); 2178 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans);
2175 syncable::ModelTypeSet newly_encrypted_types; 2179 syncable::ModelTypeSet newly_encrypted_types;
2176 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), 2180 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(),
2177 encrypted_types.begin(), encrypted_types.end(), 2181 encrypted_types.begin(), encrypted_types.end(),
2178 std::inserter(newly_encrypted_types, 2182 std::inserter(newly_encrypted_types,
2179 newly_encrypted_types.begin())); 2183 newly_encrypted_types.begin()));
2180 allstatus_.SetEncryptedTypes(newly_encrypted_types); 2184 allstatus_.SetEncryptedTypes(newly_encrypted_types);
2181 if (newly_encrypted_types == current_encrypted_types) {
2182 // Set of encrypted types has not changed, just notify and return.
2183 ObserverList<SyncManager::Observer> temp_obs_list;
2184 CopyObservers(&temp_obs_list);
2185 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
2186 OnEncryptionComplete(current_encrypted_types));
2187 return;
2188 }
2189 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); 2185 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori);
2190 node.SetNigoriSpecifics(nigori); 2186 node.SetNigoriSpecifics(nigori);
2191 2187
2192 cryptographer->SetEncryptedTypes(nigori); 2188 cryptographer->SetEncryptedTypes(nigori);
2193 2189
2194 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a 2190 // We reencrypt everything regardless of whether the set of encrypted
2195 // safer approach, and should not impact anything that is already encrypted 2191 // types changed to ensure that any stray unencrypted entries are overwritten.
2196 // (redundant changes are ignored).
2197 ReEncryptEverything(&trans); 2192 ReEncryptEverything(&trans);
2198 return; 2193 return;
2199 } 2194 }
2200 2195
2201 // TODO(zea): Add unit tests that ensure no sync changes are made when not 2196 // TODO(zea): Add unit tests that ensure no sync changes are made when not
2202 // needed. 2197 // needed.
2203 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 2198 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
2204 syncable::ModelTypeSet encrypted_types = 2199 Cryptographer* cryptographer = trans->GetCryptographer();
2205 GetEncryptedTypes(trans); 2200 if (!cryptographer || !cryptographer->is_ready())
2201 return;
2202 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
2206 ModelSafeRoutingInfo routes; 2203 ModelSafeRoutingInfo routes;
2207 registrar_->GetModelSafeRoutingInfo(&routes); 2204 registrar_->GetModelSafeRoutingInfo(&routes);
2208 std::string tag; 2205 std::string tag;
2209 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin(); 2206 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin();
2210 iter != encrypted_types.end(); ++iter) { 2207 iter != encrypted_types.end(); ++iter) {
2211 if (*iter == syncable::PASSWORDS || routes.count(*iter) == 0) 2208 if (*iter == syncable::PASSWORDS || routes.count(*iter) == 0)
2212 continue; 2209 continue;
2213 ReadNode type_root(trans); 2210 ReadNode type_root(trans);
2214 tag = syncable::ModelTypeToRootTag(*iter); 2211 tag = syncable::ModelTypeToRootTag(*iter);
2215 if (!type_root.InitByTagLookup(tag)) { 2212 if (!type_root.InitByTagLookup(tag)) {
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
3136 void SyncManager::TriggerOnIncomingNotificationForTest( 3133 void SyncManager::TriggerOnIncomingNotificationForTest(
3137 const syncable::ModelTypeBitSet& model_types) { 3134 const syncable::ModelTypeBitSet& model_types) {
3138 syncable::ModelTypePayloadMap model_types_with_payloads = 3135 syncable::ModelTypePayloadMap model_types_with_payloads =
3139 syncable::ModelTypePayloadMapFromBitSet(model_types, 3136 syncable::ModelTypePayloadMapFromBitSet(model_types,
3140 std::string()); 3137 std::string());
3141 3138
3142 data_->OnIncomingNotification(model_types_with_payloads); 3139 data_->OnIncomingNotification(model_types_with_payloads);
3143 } 3140 }
3144 3141
3145 } // namespace sync_api 3142 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/get_commit_ids_command.cc ('k') | chrome/browser/sync/engine/syncer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698