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

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

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup pass #2 Created 9 years 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 syncable::BaseTransaction* trans) OVERRIDE; 255 syncable::BaseTransaction* trans) OVERRIDE;
256 256
257 // Listens for notifications from the ServerConnectionManager 257 // Listens for notifications from the ServerConnectionManager
258 void HandleServerConnectionEvent(const ServerConnectionEvent& event); 258 void HandleServerConnectionEvent(const ServerConnectionEvent& event);
259 259
260 // Open the directory named with username_for_share 260 // Open the directory named with username_for_share
261 bool OpenDirectory(); 261 bool OpenDirectory();
262 262
263 // Cryptographer::Observer implementation. 263 // Cryptographer::Observer implementation.
264 virtual void OnEncryptedTypesChanged( 264 virtual void OnEncryptedTypesChanged(
265 const syncable::ModelTypeSet& encrypted_types, 265 syncable::ModelEnumSet encrypted_types,
266 bool encrypt_everything) OVERRIDE; 266 bool encrypt_everything) OVERRIDE;
267 267
268 // SyncNotifierObserver implementation. 268 // SyncNotifierObserver implementation.
269 virtual void OnNotificationStateChange( 269 virtual void OnNotificationStateChange(
270 bool notifications_enabled) OVERRIDE; 270 bool notifications_enabled) OVERRIDE;
271 271
272 virtual void OnIncomingNotification( 272 virtual void OnIncomingNotification(
273 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; 273 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE;
274 274
275 virtual void StoreState(const std::string& cookie) OVERRIDE; 275 virtual void StoreState(const std::string& cookie) OVERRIDE;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ChangeReorderBuffer* buffer, 314 ChangeReorderBuffer* buffer,
315 Cryptographer* cryptographer, 315 Cryptographer* cryptographer,
316 const syncable::EntryKernel& original, 316 const syncable::EntryKernel& original,
317 bool existed_before, 317 bool existed_before,
318 bool exists_now); 318 bool exists_now);
319 319
320 // Called only by our NetworkChangeNotifier. 320 // Called only by our NetworkChangeNotifier.
321 virtual void OnIPAddressChanged() OVERRIDE; 321 virtual void OnIPAddressChanged() OVERRIDE;
322 322
323 bool InitialSyncEndedForAllEnabledTypes() { 323 bool InitialSyncEndedForAllEnabledTypes() {
324 syncable::ModelTypeSet types; 324 syncable::ModelEnumSet types;
325 ModelSafeRoutingInfo enabled_types; 325 ModelSafeRoutingInfo enabled_types;
326 registrar_->GetModelSafeRoutingInfo(&enabled_types); 326 registrar_->GetModelSafeRoutingInfo(&enabled_types);
327 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); 327 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
328 i != enabled_types.end(); ++i) { 328 i != enabled_types.end(); ++i) {
329 types.insert(i->first); 329 types.Put(i->first);
330 } 330 }
331 331
332 return InitialSyncEndedForTypes(types, &share_); 332 return InitialSyncEndedForTypes(types, &share_);
333 } 333 }
334 334
335 // SyncEngineEventListener implementation. 335 // SyncEngineEventListener implementation.
336 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; 336 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE;
337 337
338 // ServerConnectionEventListener implementation. 338 // ServerConnectionEventListener implementation.
339 virtual void OnServerConnectionEvent( 339 virtual void OnServerConnectionEvent(
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 // types changed to ensure that any stray unencrypted entries are overwritten. 1128 // types changed to ensure that any stray unencrypted entries are overwritten.
1129 ReEncryptEverything(&trans); 1129 ReEncryptEverything(&trans);
1130 } 1130 }
1131 1131
1132 // TODO(zea): Add unit tests that ensure no sync changes are made when not 1132 // TODO(zea): Add unit tests that ensure no sync changes are made when not
1133 // needed. 1133 // needed.
1134 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 1134 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
1135 Cryptographer* cryptographer = trans->GetCryptographer(); 1135 Cryptographer* cryptographer = trans->GetCryptographer();
1136 if (!cryptographer || !cryptographer->is_ready()) 1136 if (!cryptographer || !cryptographer->is_ready())
1137 return; 1137 return;
1138 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); 1138 syncable::ModelEnumSet encrypted_types = GetEncryptedTypes(trans);
1139 ModelSafeRoutingInfo routes; 1139 ModelSafeRoutingInfo routes;
1140 registrar_->GetModelSafeRoutingInfo(&routes); 1140 registrar_->GetModelSafeRoutingInfo(&routes);
1141 std::string tag; 1141 std::string tag;
1142 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin(); 1142 for (syncable::ModelEnumSet::Iterator iter = encrypted_types.First();
1143 iter != encrypted_types.end(); ++iter) { 1143 iter.Good(); iter.Inc()) {
1144 if (*iter == syncable::PASSWORDS || 1144 if (iter.Get() == syncable::PASSWORDS ||
1145 *iter == syncable::NIGORI || 1145 iter.Get() == syncable::NIGORI ||
1146 routes.count(*iter) == 0) 1146 routes.count(iter.Get()) == 0)
1147 continue; 1147 continue;
1148 ReadNode type_root(trans); 1148 ReadNode type_root(trans);
1149 tag = syncable::ModelTypeToRootTag(*iter); 1149 tag = syncable::ModelTypeToRootTag(iter.Get());
1150 if (!type_root.InitByTagLookup(tag)) { 1150 if (!type_root.InitByTagLookup(tag)) {
1151 // This can happen when we enable a datatype for the first time on restart 1151 // This can happen when we enable a datatype for the first time on restart
1152 // (for example when we upgrade) and therefore haven't done the initial 1152 // (for example when we upgrade) and therefore haven't done the initial
1153 // download for that type at the time we RefreshEncryption. There's 1153 // download for that type at the time we RefreshEncryption. There's
1154 // nothing we can do for now, so just move on to the next type. 1154 // nothing we can do for now, so just move on to the next type.
1155 continue; 1155 continue;
1156 } 1156 }
1157 1157
1158 // Iterate through all children of this datatype. 1158 // Iterate through all children of this datatype.
1159 std::queue<int64> to_visit; 1159 std::queue<int64> to_visit;
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 if ((*it)->ContainsString(lowercase_query)) { 1845 if ((*it)->ContainsString(lowercase_query)) {
1846 result->Append(new StringValue(base::Int64ToString( 1846 result->Append(new StringValue(base::Int64ToString(
1847 (*it)->ref(syncable::META_HANDLE)))); 1847 (*it)->ref(syncable::META_HANDLE))));
1848 } 1848 }
1849 } 1849 }
1850 1850
1851 return JsArgList(&return_args); 1851 return JsArgList(&return_args);
1852 } 1852 }
1853 1853
1854 void SyncManager::SyncInternal::OnEncryptedTypesChanged( 1854 void SyncManager::SyncInternal::OnEncryptedTypesChanged(
1855 const syncable::ModelTypeSet& encrypted_types, 1855 syncable::ModelEnumSet encrypted_types,
1856 bool encrypt_everything) { 1856 bool encrypt_everything) {
1857 // NOTE: We're in a transaction. 1857 // NOTE: We're in a transaction.
1858 FOR_EACH_OBSERVER( 1858 FOR_EACH_OBSERVER(
1859 SyncManager::Observer, observers_, 1859 SyncManager::Observer, observers_,
1860 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); 1860 OnEncryptedTypesChanged(encrypted_types, encrypt_everything));
1861 } 1861 }
1862 1862
1863 void SyncManager::SyncInternal::OnNotificationStateChange( 1863 void SyncManager::SyncInternal::OnNotificationStateChange(
1864 bool notifications_enabled) { 1864 bool notifications_enabled) {
1865 DVLOG(1) << "P2P: Notifications enabled = " 1865 DVLOG(1) << "P2P: Notifications enabled = "
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 UserShare* SyncManager::GetUserShare() const { 1974 UserShare* SyncManager::GetUserShare() const {
1975 return data_->GetUserShare(); 1975 return data_->GetUserShare();
1976 } 1976 }
1977 1977
1978 void SyncManager::RefreshEncryption() { 1978 void SyncManager::RefreshEncryption() {
1979 DCHECK(thread_checker_.CalledOnValidThread()); 1979 DCHECK(thread_checker_.CalledOnValidThread());
1980 if (data_->UpdateCryptographerAndNigori()) 1980 if (data_->UpdateCryptographerAndNigori())
1981 data_->RefreshEncryption(); 1981 data_->RefreshEncryption();
1982 } 1982 }
1983 1983
1984 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { 1984 syncable::ModelEnumSet SyncManager::GetEncryptedDataTypesForTest() const {
1985 ReadTransaction trans(FROM_HERE, GetUserShare()); 1985 ReadTransaction trans(FROM_HERE, GetUserShare());
1986 return GetEncryptedTypes(&trans); 1986 return GetEncryptedTypes(&trans);
1987 } 1987 }
1988 1988
1989 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelTypeSet* to_add) 1989 bool SyncManager::ReceivedExperimentalTypes(syncable::ModelEnumSet* to_add)
1990 const { 1990 const {
1991 ReadTransaction trans(FROM_HERE, GetUserShare()); 1991 ReadTransaction trans(FROM_HERE, GetUserShare());
1992 ReadNode node(&trans); 1992 ReadNode node(&trans);
1993 if (!node.InitByTagLookup(kNigoriTag)) { 1993 if (!node.InitByTagLookup(kNigoriTag)) {
1994 DVLOG(1) << "Couldn't find Nigori node."; 1994 DVLOG(1) << "Couldn't find Nigori node.";
1995 return false; 1995 return false;
1996 } 1996 }
1997 if (node.GetNigoriSpecifics().sync_tabs()) { 1997 if (node.GetNigoriSpecifics().sync_tabs()) {
1998 to_add->insert(syncable::SESSIONS); 1998 to_add->Put(syncable::SESSIONS);
1999 return true; 1999 return true;
2000 } 2000 }
2001 return false; 2001 return false;
2002 } 2002 }
2003 2003
2004 bool SyncManager::HasUnsyncedItems() const { 2004 bool SyncManager::HasUnsyncedItems() const {
2005 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); 2005 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare());
2006 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); 2006 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0);
2007 } 2007 }
2008 2008
(...skipping 25 matching lines...) Expand all
2034 return "REASON_DECRYPTION"; 2034 return "REASON_DECRYPTION";
2035 case REASON_SET_PASSPHRASE_FAILED: 2035 case REASON_SET_PASSPHRASE_FAILED:
2036 return "REASON_SET_PASSPHRASE_FAILED"; 2036 return "REASON_SET_PASSPHRASE_FAILED";
2037 default: 2037 default:
2038 NOTREACHED(); 2038 NOTREACHED();
2039 return "INVALID_REASON"; 2039 return "INVALID_REASON";
2040 } 2040 }
2041 } 2041 }
2042 2042
2043 // Helper function to determine if initial sync had ended for types. 2043 // Helper function to determine if initial sync had ended for types.
2044 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, 2044 bool InitialSyncEndedForTypes(syncable::ModelEnumSet types,
2045 sync_api::UserShare* share) { 2045 sync_api::UserShare* share) {
2046 syncable::ScopedDirLookup lookup(share->dir_manager.get(), 2046 syncable::ScopedDirLookup lookup(share->dir_manager.get(),
2047 share->name); 2047 share->name);
2048 if (!lookup.good()) { 2048 if (!lookup.good()) {
2049 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; 2049 DCHECK(false) << "ScopedDirLookup failed when checking initial sync";
2050 return false; 2050 return false;
2051 } 2051 }
2052 2052
2053 for (syncable::ModelTypeSet::const_iterator i = types.begin(); 2053 for (syncable::ModelEnumSet::Iterator i = types.First();
2054 i != types.end(); ++i) { 2054 i.Good(); i.Inc()) {
2055 if (!lookup->initial_sync_ended_for_type(*i)) 2055 if (!lookup->initial_sync_ended_for_type(i.Get()))
2056 return false; 2056 return false;
2057 } 2057 }
2058 return true; 2058 return true;
2059 } 2059 }
2060 2060
2061 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( 2061 syncable::ModelEnumSet GetTypesWithEmptyProgressMarkerToken(
2062 const syncable::ModelTypeSet types, 2062 syncable::ModelEnumSet types,
2063 sync_api::UserShare* share) { 2063 sync_api::UserShare* share) {
2064 syncable::ScopedDirLookup lookup(share->dir_manager.get(), 2064 syncable::ScopedDirLookup lookup(share->dir_manager.get(),
2065 share->name); 2065 share->name);
2066 if (!lookup.good()) { 2066 if (!lookup.good()) {
2067 NOTREACHED() << "ScopedDirLookup failed for " 2067 NOTREACHED() << "ScopedDirLookup failed for "
2068 << "GetTypesWithEmptyProgressMarkerToken"; 2068 << "GetTypesWithEmptyProgressMarkerToken";
2069 return syncable::ModelTypeSet(); 2069 return syncable::ModelEnumSet();
2070 } 2070 }
2071 2071
2072 syncable::ModelTypeSet result; 2072 syncable::ModelEnumSet result;
2073 for (syncable::ModelTypeSet::const_iterator i = types.begin(); 2073 for (syncable::ModelEnumSet::Iterator i = types.First();
2074 i != types.end(); ++i) { 2074 i.Good(); i.Inc()) {
2075 sync_pb::DataTypeProgressMarker marker; 2075 sync_pb::DataTypeProgressMarker marker;
2076 lookup->GetDownloadProgress(*i, &marker); 2076 lookup->GetDownloadProgress(i.Get(), &marker);
2077 2077
2078 if (marker.token().empty()) 2078 if (marker.token().empty())
2079 result.insert(*i); 2079 result.Put(i.Get());
2080 2080
2081 } 2081 }
2082 return result; 2082 return result;
2083 } 2083 }
2084 2084
2085 } // namespace sync_api 2085 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/sync_manager.h ('k') | chrome/browser/sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698