Commit f0f76b02 authored by vasilii's avatar vasilii Committed by Commit bot

Remove ScopedVector from PasswordSyncableService.

BUG=555132

Review-Url: https://codereview.chromium.org/2403433002
Cr-Commit-Position: refs/heads/master@{#423835}
parent 64afe822
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include "components/password_manager/core/browser/password_syncable_service.h" #include "components/password_manager/core/browser/password_syncable_service.h"
#include <algorithm>
#include <iterator>
#include <utility> #include <utility>
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/location.h" #include "base/location.h"
#include "base/memory/scoped_vector.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
...@@ -83,9 +85,9 @@ syncer::SyncChange::SyncChangeType GetSyncChangeType( ...@@ -83,9 +85,9 @@ syncer::SyncChange::SyncChangeType GetSyncChangeType(
void AppendPasswordFromSpecifics( void AppendPasswordFromSpecifics(
const sync_pb::PasswordSpecificsData& specifics, const sync_pb::PasswordSpecificsData& specifics,
base::Time sync_time, base::Time sync_time,
ScopedVector<autofill::PasswordForm>* entries) { std::vector<std::unique_ptr<autofill::PasswordForm>>* entries) {
entries->push_back( entries->push_back(base::MakeUnique<autofill::PasswordForm>(
new autofill::PasswordForm(PasswordFromSpecifics(specifics))); PasswordFromSpecifics(specifics)));
entries->back()->date_synced = sync_time; entries->back()->date_synced = sync_time;
} }
...@@ -105,7 +107,7 @@ bool IsEmptyPasswordSpecificsData( ...@@ -105,7 +107,7 @@ bool IsEmptyPasswordSpecificsData(
} // namespace } // namespace
struct PasswordSyncableService::SyncEntries { struct PasswordSyncableService::SyncEntries {
ScopedVector<autofill::PasswordForm>* EntriesForChangeType( std::vector<std::unique_ptr<autofill::PasswordForm>>* EntriesForChangeType(
syncer::SyncChange::SyncChangeType type) { syncer::SyncChange::SyncChangeType type) {
switch (type) { switch (type) {
case syncer::SyncChange::ACTION_ADD: case syncer::SyncChange::ACTION_ADD:
...@@ -122,15 +124,15 @@ struct PasswordSyncableService::SyncEntries { ...@@ -122,15 +124,15 @@ struct PasswordSyncableService::SyncEntries {
} }
// List that contains the entries that are known only to sync. // List that contains the entries that are known only to sync.
ScopedVector<autofill::PasswordForm> new_entries; std::vector<std::unique_ptr<autofill::PasswordForm>> new_entries;
// List that contains the entries that are known to both sync and the local // List that contains the entries that are known to both sync and the local
// database but have updates in sync. They need to be updated in the local // database but have updates in sync. They need to be updated in the local
// database. // database.
ScopedVector<autofill::PasswordForm> updated_entries; std::vector<std::unique_ptr<autofill::PasswordForm>> updated_entries;
// The list of entries to be deleted from the local database. // The list of entries to be deleted from the local database.
ScopedVector<autofill::PasswordForm> deleted_entries; std::vector<std::unique_ptr<autofill::PasswordForm>> deleted_entries;
}; };
PasswordSyncableService::PasswordSyncableService( PasswordSyncableService::PasswordSyncableService(
...@@ -154,7 +156,7 @@ syncer::SyncMergeResult PasswordSyncableService::MergeDataAndStartSyncing( ...@@ -154,7 +156,7 @@ syncer::SyncMergeResult PasswordSyncableService::MergeDataAndStartSyncing(
// We add all the db entries as |new_local_entries| initially. During model // We add all the db entries as |new_local_entries| initially. During model
// association entries that match a sync entry will be removed and this list // association entries that match a sync entry will be removed and this list
// will only contain entries that are not in sync. // will only contain entries that are not in sync.
ScopedVector<autofill::PasswordForm> password_entries; std::vector<std::unique_ptr<autofill::PasswordForm>> password_entries;
PasswordEntryMap new_local_entries; PasswordEntryMap new_local_entries;
if (!ReadFromPasswordStore(&password_entries, &new_local_entries)) { if (!ReadFromPasswordStore(&password_entries, &new_local_entries)) {
merge_result.set_error(sync_error_factory->CreateAndUploadError( merge_result.set_error(sync_error_factory->CreateAndUploadError(
...@@ -193,7 +195,7 @@ syncer::SyncMergeResult PasswordSyncableService::MergeDataAndStartSyncing( ...@@ -193,7 +195,7 @@ syncer::SyncMergeResult PasswordSyncableService::MergeDataAndStartSyncing(
// cleaned up. This should happen in M43 and can be verified using crash // cleaned up. This should happen in M43 and can be verified using crash
// reports. // reports.
sync_entries.deleted_entries.push_back( sync_entries.deleted_entries.push_back(
new autofill::PasswordForm(*it->second)); base::MakeUnique<autofill::PasswordForm>(*it->second));
} else { } else {
updated_db_entries.push_back( updated_db_entries.push_back(
syncer::SyncChange(FROM_HERE, syncer::SyncChange(FROM_HERE,
...@@ -238,14 +240,16 @@ syncer::SyncDataList PasswordSyncableService::GetAllSyncData( ...@@ -238,14 +240,16 @@ syncer::SyncDataList PasswordSyncableService::GetAllSyncData(
syncer::ModelType type) const { syncer::ModelType type) const {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_EQ(syncer::PASSWORDS, type); DCHECK_EQ(syncer::PASSWORDS, type);
ScopedVector<autofill::PasswordForm> password_entries; std::vector<std::unique_ptr<autofill::PasswordForm>> password_entries;
ReadFromPasswordStore(&password_entries, nullptr); ReadFromPasswordStore(&password_entries, nullptr);
syncer::SyncDataList sync_data; syncer::SyncDataList sync_data;
for (PasswordForms::iterator it = password_entries.begin(); sync_data.reserve(password_entries.size());
it != password_entries.end(); ++it) { std::transform(password_entries.begin(), password_entries.end(),
sync_data.push_back(SyncDataFromPassword(**it)); std::back_inserter(sync_data),
} [](const std::unique_ptr<autofill::PasswordForm>& form) {
return SyncDataFromPassword(*form);
});
return sync_data; return sync_data;
} }
...@@ -260,7 +264,7 @@ syncer::SyncError PasswordSyncableService::ProcessSyncChanges( ...@@ -260,7 +264,7 @@ syncer::SyncError PasswordSyncableService::ProcessSyncChanges(
for (syncer::SyncChangeList::const_iterator it = change_list.begin(); for (syncer::SyncChangeList::const_iterator it = change_list.begin();
it != change_list.end(); ++it) { it != change_list.end(); ++it) {
const sync_pb::EntitySpecifics& specifics = it->sync_data().GetSpecifics(); const sync_pb::EntitySpecifics& specifics = it->sync_data().GetSpecifics();
ScopedVector<autofill::PasswordForm>* entries = std::vector<std::unique_ptr<autofill::PasswordForm>>* entries =
sync_entries.EntriesForChangeType(it->change_type()); sync_entries.EntriesForChangeType(it->change_type());
if (!entries) { if (!entries) {
return sync_error_factory_->CreateAndUploadError( return sync_error_factory_->CreateAndUploadError(
...@@ -310,7 +314,7 @@ void PasswordSyncableService::InjectStartSyncFlare( ...@@ -310,7 +314,7 @@ void PasswordSyncableService::InjectStartSyncFlare(
} }
bool PasswordSyncableService::ReadFromPasswordStore( bool PasswordSyncableService::ReadFromPasswordStore(
ScopedVector<autofill::PasswordForm>* password_entries, std::vector<std::unique_ptr<autofill::PasswordForm>>* password_entries,
PasswordEntryMap* passwords_entry_map) const { PasswordEntryMap* passwords_entry_map) const {
DCHECK(password_entries); DCHECK(password_entries);
std::vector<std::unique_ptr<autofill::PasswordForm>> autofillable_entries; std::vector<std::unique_ptr<autofill::PasswordForm>> autofillable_entries;
...@@ -324,24 +328,19 @@ bool PasswordSyncableService::ReadFromPasswordStore( ...@@ -324,24 +328,19 @@ bool PasswordSyncableService::ReadFromPasswordStore(
syncer::MODEL_TYPE_COUNT); syncer::MODEL_TYPE_COUNT);
return false; return false;
} }
password_entries->clear();
password_entries->resize(autofillable_entries.size() + password_entries->resize(autofillable_entries.size() +
blacklist_entries.size()); blacklist_entries.size());
auto next = password_entries->begin(); std::move(autofillable_entries.begin(), autofillable_entries.end(),
for (auto& autofillable : autofillable_entries) { password_entries->begin());
*next++ = autofillable.release(); std::move(blacklist_entries.begin(), blacklist_entries.end(),
} password_entries->begin() + autofillable_entries.size());
for (auto& blacklisted : blacklist_entries) {
*next++ = blacklisted.release();
}
if (!passwords_entry_map) if (!passwords_entry_map)
return true; return true;
PasswordEntryMap& entry_map = *passwords_entry_map; PasswordEntryMap& entry_map = *passwords_entry_map;
for (PasswordForms::iterator it = password_entries->begin(); for (const auto& form : *password_entries) {
it != password_entries->end(); ++it) { autofill::PasswordForm* password_form = form.get();
autofill::PasswordForm* password_form = *it;
entry_map[MakePasswordSyncTag(*password_form)] = password_form; entry_map[MakePasswordSyncTag(*password_form)] = password_form;
} }
...@@ -350,12 +349,12 @@ bool PasswordSyncableService::ReadFromPasswordStore( ...@@ -350,12 +349,12 @@ bool PasswordSyncableService::ReadFromPasswordStore(
void PasswordSyncableService::WriteToPasswordStore(const SyncEntries& entries) { void PasswordSyncableService::WriteToPasswordStore(const SyncEntries& entries) {
PasswordStoreChangeList changes; PasswordStoreChangeList changes;
WriteEntriesToDatabase(&PasswordStoreSync::AddLoginSync, WriteEntriesToDatabase(&PasswordStoreSync::AddLoginSync, entries.new_entries,
entries.new_entries.get(), &changes); &changes);
WriteEntriesToDatabase(&PasswordStoreSync::UpdateLoginSync, WriteEntriesToDatabase(&PasswordStoreSync::UpdateLoginSync,
entries.updated_entries.get(), &changes); entries.updated_entries, &changes);
WriteEntriesToDatabase(&PasswordStoreSync::RemoveLoginSync, WriteEntriesToDatabase(&PasswordStoreSync::RemoveLoginSync,
entries.deleted_entries.get(), &changes); entries.deleted_entries, &changes);
// We have to notify password store observers of the change by hand since // We have to notify password store observers of the change by hand since
// we use internal password store interfaces to make changes synchronously. // we use internal password store interfaces to make changes synchronously.
...@@ -431,11 +430,10 @@ void PasswordSyncableService::CreateOrUpdateEntry( ...@@ -431,11 +430,10 @@ void PasswordSyncableService::CreateOrUpdateEntry(
void PasswordSyncableService::WriteEntriesToDatabase( void PasswordSyncableService::WriteEntriesToDatabase(
DatabaseOperation operation, DatabaseOperation operation,
const PasswordForms& entries, const std::vector<std::unique_ptr<autofill::PasswordForm>>& entries,
PasswordStoreChangeList* all_changes) { PasswordStoreChangeList* all_changes) {
for (PasswordForms::const_iterator it = entries.begin(); it != entries.end(); for (const std::unique_ptr<autofill::PasswordForm>& form : entries) {
++it) { PasswordStoreChangeList new_changes = (password_store_->*operation)(*form);
PasswordStoreChangeList new_changes = (password_store_->*operation)(**it);
all_changes->insert(all_changes->end(), all_changes->insert(all_changes->end(),
new_changes.begin(), new_changes.begin(),
new_changes.end()); new_changes.end());
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
#include "components/sync/protocol/password_specifics.pb.h" #include "components/sync/protocol/password_specifics.pb.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
template <typename T>
class ScopedVector;
namespace autofill { namespace autofill {
struct PasswordForm; struct PasswordForm;
} }
...@@ -65,7 +62,6 @@ class PasswordSyncableService : public syncer::SyncableService, ...@@ -65,7 +62,6 @@ class PasswordSyncableService : public syncer::SyncableService,
const syncer::SyncableService::StartSyncFlare& flare); const syncer::SyncableService::StartSyncFlare& flare);
private: private:
typedef std::vector<autofill::PasswordForm*> PasswordForms;
// Map from password sync tag to password form. // Map from password sync tag to password form.
typedef std::map<std::string, autofill::PasswordForm*> PasswordEntryMap; typedef std::map<std::string, autofill::PasswordForm*> PasswordEntryMap;
...@@ -79,7 +75,7 @@ class PasswordSyncableService : public syncer::SyncableService, ...@@ -79,7 +75,7 @@ class PasswordSyncableService : public syncer::SyncableService,
// Retrieves the entries from password db and fills both |password_entries| // Retrieves the entries from password db and fills both |password_entries|
// and |passwords_entry_map|. |passwords_entry_map| can be NULL. // and |passwords_entry_map|. |passwords_entry_map| can be NULL.
bool ReadFromPasswordStore( bool ReadFromPasswordStore(
ScopedVector<autofill::PasswordForm>* password_entries, std::vector<std::unique_ptr<autofill::PasswordForm>>* password_entries,
PasswordEntryMap* passwords_entry_map) const; PasswordEntryMap* passwords_entry_map) const;
// Uses the |PasswordStore| APIs to change entries. // Uses the |PasswordStore| APIs to change entries.
...@@ -96,9 +92,10 @@ class PasswordSyncableService : public syncer::SyncableService, ...@@ -96,9 +92,10 @@ class PasswordSyncableService : public syncer::SyncableService,
// Calls |operation| for each element in |entries| and appends the changes to // Calls |operation| for each element in |entries| and appends the changes to
// |all_changes|. // |all_changes|.
void WriteEntriesToDatabase(DatabaseOperation operation, void WriteEntriesToDatabase(
const PasswordForms& entries, DatabaseOperation operation,
PasswordStoreChangeList* all_changes); const std::vector<std::unique_ptr<autofill::PasswordForm>>& entries,
PasswordStoreChangeList* all_changes);
// The factory that creates sync errors. |SyncError| has rich data // The factory that creates sync errors. |SyncError| has rich data
// suitable for debugging. // suitable for debugging.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment