| Index: chrome/browser/ui/app_list/app_list_syncable_service.cc
|
| diff --git a/chrome/browser/ui/app_list/app_list_syncable_service.cc b/chrome/browser/ui/app_list/app_list_syncable_service.cc
|
| index aabaeb7b7b865440a51ebfe32d9e52f876505011..eda8d4a322d8070d1275acfca99f7f40d59a968b 100644
|
| --- a/chrome/browser/ui/app_list/app_list_syncable_service.cc
|
| +++ b/chrome/browser/ui/app_list/app_list_syncable_service.cc
|
| @@ -8,6 +8,8 @@
|
|
|
| #include "base/command_line.h"
|
| #include "base/macros.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/stl_util.h"
|
| #include "base/strings/string_util.h"
|
| #include "build/build_config.h"
|
| #include "chrome/browser/apps/drive/drive_app_provider.h"
|
| @@ -275,9 +277,6 @@ AppListSyncableService::~AppListSyncableService() {
|
| // Remove observers.
|
| model_observer_.reset();
|
| model_pref_updater_.reset();
|
| -
|
| - base::STLDeleteContainerPairSecondPointers(sync_items_.begin(),
|
| - sync_items_.end());
|
| }
|
|
|
| void AppListSyncableService::BuildModel() {
|
| @@ -372,14 +371,14 @@ void AppListSyncableService::UntrackUninstalledDriveApp(
|
|
|
| DCHECK_EQ(sync_item->item_type,
|
| sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP);
|
| - DeleteSyncItem(sync_item);
|
| + DeleteSyncItem(drive_app_id);
|
| }
|
|
|
| const AppListSyncableService::SyncItem*
|
| AppListSyncableService::GetSyncItem(const std::string& id) const {
|
| - SyncItemMap::const_iterator iter = sync_items_.find(id);
|
| + auto iter = sync_items_.find(id);
|
| if (iter != sync_items_.end())
|
| - return iter->second;
|
| + return iter->second.get();
|
| return NULL;
|
| }
|
|
|
| @@ -511,11 +510,16 @@ bool AppListSyncableService::RemoveDefaultApp(AppListItem* item,
|
| // Otherwise, we are adding the app as a non-default app (i.e. an app that
|
| // was installed by Default and removed is getting installed explicitly by
|
| // the user), so delete the REMOVE_DEFAULT_APP.
|
| - DeleteSyncItem(sync_item);
|
| + DeleteSyncItem(sync_item->item_id);
|
| return false;
|
| }
|
|
|
| -void AppListSyncableService::DeleteSyncItem(SyncItem* sync_item) {
|
| +void AppListSyncableService::DeleteSyncItem(const std::string& item_id) {
|
| + SyncItem* sync_item = FindSyncItem(item_id);
|
| + if (!sync_item) {
|
| + LOG(ERROR) << "DeleteSyncItem: no sync item: " << item_id;
|
| + return;
|
| + }
|
| if (SyncStarted()) {
|
| VLOG(2) << this << " -> SYNC DELETE: " << sync_item->ToString();
|
| SyncChange sync_change(FROM_HERE, SyncChange::ACTION_DELETE,
|
| @@ -523,8 +527,6 @@ void AppListSyncableService::DeleteSyncItem(SyncItem* sync_item) {
|
| sync_processor_->ProcessSyncChanges(
|
| FROM_HERE, syncer::SyncChangeList(1, sync_change));
|
| }
|
| - std::string item_id = sync_item->item_id;
|
| - delete sync_item;
|
| sync_items_.erase(item_id);
|
| }
|
|
|
| @@ -567,14 +569,14 @@ void AppListSyncableService::UpdateItem(AppListItem* app_item) {
|
|
|
| void AppListSyncableService::RemoveSyncItem(const std::string& id) {
|
| VLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8);
|
| - SyncItemMap::iterator iter = sync_items_.find(id);
|
| + auto iter = sync_items_.find(id);
|
| if (iter == sync_items_.end()) {
|
| DVLOG(2) << this << " : RemoveSyncItem: No Item.";
|
| return;
|
| }
|
|
|
| // Check for existing RemoveDefault sync item.
|
| - SyncItem* sync_item = iter->second;
|
| + SyncItem* sync_item = iter->second.get();
|
| sync_pb::AppListSpecifics::AppListItemType type = sync_item->item_type;
|
| if (type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) {
|
| // RemoveDefault item exists, just return.
|
| @@ -593,7 +595,7 @@ void AppListSyncableService::RemoveSyncItem(const std::string& id) {
|
| return;
|
| }
|
|
|
| - DeleteSyncItem(sync_item);
|
| + DeleteSyncItem(iter->first);
|
| }
|
|
|
| void AppListSyncableService::ResolveFolderPositions() {
|
| @@ -601,9 +603,8 @@ void AppListSyncableService::ResolveFolderPositions() {
|
| return;
|
|
|
| VLOG(1) << "ResolveFolderPositions.";
|
| - for (SyncItemMap::iterator iter = sync_items_.begin();
|
| - iter != sync_items_.end(); ++iter) {
|
| - SyncItem* sync_item = iter->second;
|
| + for (const auto& sync_pair : sync_items_) {
|
| + SyncItem* sync_item = sync_pair.second.get();
|
| if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER)
|
| continue;
|
| AppListItem* app_item = model_->FindItem(sync_item->item_id);
|
| @@ -627,17 +628,15 @@ void AppListSyncableService::PruneEmptySyncFolders() {
|
| return;
|
|
|
| std::set<std::string> parent_ids;
|
| - for (SyncItemMap::iterator iter = sync_items_.begin();
|
| - iter != sync_items_.end(); ++iter) {
|
| - parent_ids.insert(iter->second->parent_id);
|
| - }
|
| - for (SyncItemMap::iterator iter = sync_items_.begin();
|
| - iter != sync_items_.end(); ) {
|
| - SyncItem* sync_item = (iter++)->second;
|
| + for (const auto& sync_pair : sync_items_)
|
| + parent_ids.insert(sync_pair.second->parent_id);
|
| +
|
| + for (auto iter = sync_items_.begin(); iter != sync_items_.end();) {
|
| + SyncItem* sync_item = (iter++)->second.get();
|
| if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER)
|
| continue;
|
| if (!base::ContainsKey(parent_ids, sync_item->item_id))
|
| - DeleteSyncItem(sync_item);
|
| + DeleteSyncItem(sync_item->item_id);
|
| }
|
| }
|
|
|
| @@ -667,9 +666,8 @@ syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing(
|
|
|
| // Copy all sync items to |unsynced_items|.
|
| std::set<std::string> unsynced_items;
|
| - for (SyncItemMap::const_iterator iter = sync_items_.begin();
|
| - iter != sync_items_.end(); ++iter) {
|
| - unsynced_items.insert(iter->first);
|
| + for (const auto& sync_pair : sync_items_) {
|
| + unsynced_items.insert(sync_pair.first);
|
| }
|
|
|
| // Create SyncItem entries for initial_sync_data.
|
| @@ -744,10 +742,9 @@ syncer::SyncDataList AppListSyncableService::GetAllSyncData(
|
|
|
| VLOG(1) << this << ": GetAllSyncData: " << sync_items_.size();
|
| syncer::SyncDataList list;
|
| - for (SyncItemMap::const_iterator iter = sync_items_.begin();
|
| - iter != sync_items_.end(); ++iter) {
|
| + for (auto iter = sync_items_.begin(); iter != sync_items_.end(); ++iter) {
|
| VLOG(2) << this << " -> SYNC: " << iter->second->ToString();
|
| - list.push_back(GetSyncDataFromSyncItem(iter->second));
|
| + list.push_back(GetSyncDataFromSyncItem(iter->second.get()));
|
| }
|
| return list;
|
| }
|
| @@ -820,7 +817,6 @@ bool AppListSyncableService::ProcessSyncItemSpecifics(
|
| }
|
| VLOG(2) << this << " - ProcessSyncItem: Delete existing entry: "
|
| << sync_item->ToString();
|
| - delete sync_item;
|
| sync_items_.erase(item_id);
|
| }
|
|
|
| @@ -949,10 +945,10 @@ void AppListSyncableService::SendSyncChange(
|
|
|
| AppListSyncableService::SyncItem*
|
| AppListSyncableService::FindSyncItem(const std::string& item_id) {
|
| - SyncItemMap::iterator iter = sync_items_.find(item_id);
|
| + auto iter = sync_items_.find(item_id);
|
| if (iter == sync_items_.end())
|
| return NULL;
|
| - return iter->second;
|
| + return iter->second.get();
|
| }
|
|
|
| AppListSyncableService::SyncItem*
|
| @@ -960,9 +956,8 @@ AppListSyncableService::CreateSyncItem(
|
| const std::string& item_id,
|
| sync_pb::AppListSpecifics::AppListItemType item_type) {
|
| DCHECK(!base::ContainsKey(sync_items_, item_id));
|
| - SyncItem* sync_item = new SyncItem(item_id, item_type);
|
| - sync_items_[item_id] = sync_item;
|
| - return sync_item;
|
| + sync_items_[item_id] = base::MakeUnique<SyncItem>(item_id, item_type);
|
| + return sync_items_[item_id].get();
|
| }
|
|
|
| void AppListSyncableService::DeleteSyncItemSpecifics(
|
| @@ -973,13 +968,12 @@ void AppListSyncableService::DeleteSyncItemSpecifics(
|
| return;
|
| }
|
| VLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8);
|
| - SyncItemMap::iterator iter = sync_items_.find(item_id);
|
| + auto iter = sync_items_.find(item_id);
|
| if (iter == sync_items_.end())
|
| return;
|
| sync_pb::AppListSpecifics::AppListItemType item_type =
|
| iter->second->item_type;
|
| VLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString();
|
| - delete iter->second;
|
| sync_items_.erase(iter);
|
| // Only delete apps from the model. Folders will be deleted when all
|
| // children have been deleted.
|
| @@ -1020,9 +1014,8 @@ syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() {
|
| if (!first_app_list_sync_) {
|
| VLOG(1) << "Sync items exist, placing OEM folder at end.";
|
| syncer::StringOrdinal last;
|
| - for (SyncItemMap::iterator iter = sync_items_.begin();
|
| - iter != sync_items_.end(); ++iter) {
|
| - SyncItem* sync_item = iter->second;
|
| + for (const auto& sync_pair : sync_items_) {
|
| + SyncItem* sync_item = sync_pair.second.get();
|
| if (sync_item->item_ordinal.IsValid() &&
|
| (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) {
|
| last = sync_item->item_ordinal;
|
|
|