| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/sync_bundle.h" | 5 #include "chrome/browser/extensions/sync_bundle.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "chrome/browser/extensions/extension_sync_data.h" | 8 #include "chrome/browser/extensions/extension_sync_data.h" |
| 9 #include "chrome/browser/extensions/extension_sync_service.h" | 9 #include "chrome/browser/extensions/extension_sync_service.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool SyncBundle::IsSyncing() const { | 42 bool SyncBundle::IsSyncing() const { |
| 43 return sync_processor_ != nullptr; | 43 return sync_processor_ != nullptr; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool SyncBundle::HasExtensionId(const std::string& id) const { | 46 bool SyncBundle::HasExtensionId(const std::string& id) const { |
| 47 return synced_extensions_.find(id) != synced_extensions_.end(); | 47 return synced_extensions_.find(id) != synced_extensions_.end(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SyncBundle::ShouldIncludeInLocalSyncDataList( | |
| 51 const Extension& extension) const { | |
| 52 // If there is pending data for this extension, then this version is out of | |
| 53 // date. We'll sync back the version we got from sync. | |
| 54 return IsSyncing() && !HasPendingExtensionId(extension.id()); | |
| 55 } | |
| 56 | |
| 57 void SyncBundle::PushSyncDataList( | 50 void SyncBundle::PushSyncDataList( |
| 58 const syncer::SyncDataList& sync_data_list) { | 51 const syncer::SyncDataList& sync_data_list) { |
| 59 syncer::SyncChangeList sync_change_list; | 52 syncer::SyncChangeList sync_change_list; |
| 60 for (const syncer::SyncData& sync_data : sync_data_list) { | 53 for (const syncer::SyncData& sync_data : sync_data_list) { |
| 61 const syncer::SyncDataLocal sync_data_local(sync_data); | 54 const syncer::SyncDataLocal sync_data_local(sync_data); |
| 62 const std::string& extension_id = sync_data_local.GetTag(); | 55 const std::string& extension_id = sync_data_local.GetTag(); |
| 63 | 56 |
| 64 sync_change_list.push_back(CreateSyncChange(extension_id, sync_data)); | 57 sync_change_list.push_back(CreateSyncChange(extension_id, sync_data)); |
| 65 | 58 |
| 66 AddSyncedExtension(extension_id); | 59 AddSyncedExtension(extension_id); |
| 67 } | 60 } |
| 68 | 61 |
| 69 PushSyncChanges(sync_change_list); | 62 PushSyncChanges(sync_change_list); |
| 70 } | 63 } |
| 71 | 64 |
| 72 void SyncBundle::PushSyncDeletion(const std::string& extension_id, | 65 void SyncBundle::PushSyncDeletion(const std::string& extension_id, |
| 73 const syncer::SyncData& sync_data) { | 66 const syncer::SyncData& sync_data) { |
| 74 RemoveSyncedExtension(extension_id); | 67 RemoveSyncedExtension(extension_id); |
| 75 PushSyncChanges(syncer::SyncChangeList(1, | 68 PushSyncChanges(syncer::SyncChangeList(1, |
| 76 syncer::SyncChange(FROM_HERE, | 69 syncer::SyncChange(FROM_HERE, |
| 77 syncer::SyncChange::ACTION_DELETE, | 70 syncer::SyncChange::ACTION_DELETE, |
| 78 sync_data))); | 71 sync_data))); |
| 79 } | 72 } |
| 80 | 73 |
| 81 void SyncBundle::PushSyncChangeIfNeeded(const Extension& extension) { | 74 void SyncBundle::PushSyncChange(const std::string& extension_id, |
| 75 const syncer::SyncData& sync_data) { |
| 82 syncer::SyncChangeList sync_change_list( | 76 syncer::SyncChangeList sync_change_list( |
| 83 1, | 77 1, |
| 84 CreateSyncChange(extension.id(), | 78 CreateSyncChange(extension_id, sync_data)); |
| 85 sync_service_->CreateSyncData(extension).GetSyncData())); | |
| 86 PushSyncChanges(sync_change_list); | 79 PushSyncChanges(sync_change_list); |
| 87 MarkPendingExtensionSynced(extension.id()); | 80 MarkPendingExtensionSynced(extension_id); |
| 88 } | 81 } |
| 89 | 82 |
| 90 void SyncBundle::ApplySyncChange(const syncer::SyncChange& sync_change) { | 83 void SyncBundle::ApplySyncChange(const syncer::SyncChange& sync_change) { |
| 91 scoped_ptr<ExtensionSyncData> extension_sync_data( | 84 scoped_ptr<ExtensionSyncData> extension_sync_data( |
| 92 ExtensionSyncData::CreateFromSyncChange(sync_change)); | 85 ExtensionSyncData::CreateFromSyncChange(sync_change)); |
| 93 if (!extension_sync_data.get()) | 86 if (!extension_sync_data.get()) |
| 94 return; // TODO(treib,kalman): Warning message? | 87 return; // TODO(treib,kalman): Warning message? |
| 95 | 88 |
| 96 if (extension_sync_data->uninstalled()) | 89 if (extension_sync_data->uninstalled()) |
| 97 RemoveSyncedExtension(extension_sync_data->id()); | 90 RemoveSyncedExtension(extension_sync_data->id()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 void SyncBundle::RemoveSyncedExtension(const std::string& id) { | 133 void SyncBundle::RemoveSyncedExtension(const std::string& id) { |
| 141 synced_extensions_.erase(id); | 134 synced_extensions_.erase(id); |
| 142 } | 135 } |
| 143 | 136 |
| 144 void SyncBundle::MarkPendingExtensionSynced(const std::string& id) { | 137 void SyncBundle::MarkPendingExtensionSynced(const std::string& id) { |
| 145 pending_sync_data_.erase(id); | 138 pending_sync_data_.erase(id); |
| 146 AddSyncedExtension(id); | 139 AddSyncedExtension(id); |
| 147 } | 140 } |
| 148 | 141 |
| 149 } // namespace extensions | 142 } // namespace extensions |
| OLD | NEW |