Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/app_list_syncable_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 12 #include "base/stl_util.h" | |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 13 #include "chrome/browser/apps/drive/drive_app_provider.h" | 15 #include "chrome/browser/apps/drive/drive_app_provider.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/app_list/app_list_prefs.h" | 18 #include "chrome/browser/ui/app_list/app_list_prefs.h" |
| 17 #include "chrome/browser/ui/app_list/app_list_service.h" | 19 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 18 #include "chrome/browser/ui/app_list/extension_app_item.h" | 20 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 19 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" | 21 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" |
| 20 #include "chrome/browser/ui/app_list/model_pref_updater.h" | 22 #include "chrome/browser/ui/app_list/model_pref_updater.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 } | 270 } |
| 269 | 271 |
| 270 oem_folder_name_ = | 272 oem_folder_name_ = |
| 271 l10n_util::GetStringUTF8(IDS_APP_LIST_OEM_DEFAULT_FOLDER_NAME); | 273 l10n_util::GetStringUTF8(IDS_APP_LIST_OEM_DEFAULT_FOLDER_NAME); |
| 272 } | 274 } |
| 273 | 275 |
| 274 AppListSyncableService::~AppListSyncableService() { | 276 AppListSyncableService::~AppListSyncableService() { |
| 275 // Remove observers. | 277 // Remove observers. |
| 276 model_observer_.reset(); | 278 model_observer_.reset(); |
| 277 model_pref_updater_.reset(); | 279 model_pref_updater_.reset(); |
| 278 | |
| 279 base::STLDeleteContainerPairSecondPointers(sync_items_.begin(), | |
| 280 sync_items_.end()); | |
| 281 } | 280 } |
| 282 | 281 |
| 283 void AppListSyncableService::BuildModel() { | 282 void AppListSyncableService::BuildModel() { |
| 284 // TODO(calamity): make this a DCHECK after a dev channel release. | 283 // TODO(calamity): make this a DCHECK after a dev channel release. |
| 285 CHECK(extension_system_->extension_service() && | 284 CHECK(extension_system_->extension_service() && |
| 286 extension_system_->extension_service()->is_ready()); | 285 extension_system_->extension_service()->is_ready()); |
| 287 AppListControllerDelegate* controller = NULL; | 286 AppListControllerDelegate* controller = NULL; |
| 288 AppListService* service = AppListService::Get(); | 287 AppListService* service = AppListService::Get(); |
| 289 if (service) | 288 if (service) |
| 290 controller = service->GetControllerDelegate(); | 289 controller = service->GetControllerDelegate(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 if (!sync_item) | 369 if (!sync_item) |
| 371 return; | 370 return; |
| 372 | 371 |
| 373 DCHECK_EQ(sync_item->item_type, | 372 DCHECK_EQ(sync_item->item_type, |
| 374 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP); | 373 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP); |
| 375 DeleteSyncItem(sync_item); | 374 DeleteSyncItem(sync_item); |
| 376 } | 375 } |
| 377 | 376 |
| 378 const AppListSyncableService::SyncItem* | 377 const AppListSyncableService::SyncItem* |
| 379 AppListSyncableService::GetSyncItem(const std::string& id) const { | 378 AppListSyncableService::GetSyncItem(const std::string& id) const { |
| 380 SyncItemMap::const_iterator iter = sync_items_.find(id); | 379 auto iter = sync_items_.find(id); |
| 381 if (iter != sync_items_.end()) | 380 if (iter != sync_items_.end()) |
| 382 return iter->second; | 381 return iter->second.get(); |
| 383 return NULL; | 382 return NULL; |
| 384 } | 383 } |
| 385 | 384 |
| 386 void AppListSyncableService::SetOemFolderName(const std::string& name) { | 385 void AppListSyncableService::SetOemFolderName(const std::string& name) { |
| 387 oem_folder_name_ = name; | 386 oem_folder_name_ = name; |
| 388 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); | 387 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); |
| 389 if (oem_folder) | 388 if (oem_folder) |
| 390 model_->SetItemName(oem_folder, oem_folder_name_); | 389 model_->SetItemName(oem_folder, oem_folder_name_); |
| 391 } | 390 } |
| 392 | 391 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 516 |
| 518 void AppListSyncableService::DeleteSyncItem(SyncItem* sync_item) { | 517 void AppListSyncableService::DeleteSyncItem(SyncItem* sync_item) { |
| 519 if (SyncStarted()) { | 518 if (SyncStarted()) { |
| 520 VLOG(2) << this << " -> SYNC DELETE: " << sync_item->ToString(); | 519 VLOG(2) << this << " -> SYNC DELETE: " << sync_item->ToString(); |
| 521 SyncChange sync_change(FROM_HERE, SyncChange::ACTION_DELETE, | 520 SyncChange sync_change(FROM_HERE, SyncChange::ACTION_DELETE, |
| 522 GetSyncDataFromSyncItem(sync_item)); | 521 GetSyncDataFromSyncItem(sync_item)); |
| 523 sync_processor_->ProcessSyncChanges( | 522 sync_processor_->ProcessSyncChanges( |
| 524 FROM_HERE, syncer::SyncChangeList(1, sync_change)); | 523 FROM_HERE, syncer::SyncChangeList(1, sync_change)); |
| 525 } | 524 } |
| 526 std::string item_id = sync_item->item_id; | 525 std::string item_id = sync_item->item_id; |
| 527 delete sync_item; | |
|
Nico
2016/09/22 15:56:12
(this another instance of the map<key, value> that
Avi (use Gerrit)
2016/09/22 19:17:17
Done.
| |
| 528 sync_items_.erase(item_id); | 526 sync_items_.erase(item_id); |
| 529 } | 527 } |
| 530 | 528 |
| 531 void AppListSyncableService::UpdateSyncItem(AppListItem* app_item) { | 529 void AppListSyncableService::UpdateSyncItem(AppListItem* app_item) { |
| 532 SyncItem* sync_item = FindSyncItem(app_item->id()); | 530 SyncItem* sync_item = FindSyncItem(app_item->id()); |
| 533 if (!sync_item) { | 531 if (!sync_item) { |
| 534 LOG(ERROR) << "UpdateItem: no sync item: " << app_item->id(); | 532 LOG(ERROR) << "UpdateItem: no sync item: " << app_item->id(); |
| 535 return; | 533 return; |
| 536 } | 534 } |
| 537 bool changed = UpdateSyncItemFromAppItem(app_item, sync_item); | 535 bool changed = UpdateSyncItemFromAppItem(app_item, sync_item); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 560 return; | 558 return; |
| 561 bool is_oem = AppIsOem(app_item->id()); | 559 bool is_oem = AppIsOem(app_item->id()); |
| 562 if (!is_oem && app_item->folder_id() == kOemFolderId) | 560 if (!is_oem && app_item->folder_id() == kOemFolderId) |
| 563 model_->MoveItemToFolder(app_item, ""); | 561 model_->MoveItemToFolder(app_item, ""); |
| 564 else if (is_oem && app_item->folder_id() != kOemFolderId) | 562 else if (is_oem && app_item->folder_id() != kOemFolderId) |
| 565 model_->MoveItemToFolder(app_item, kOemFolderId); | 563 model_->MoveItemToFolder(app_item, kOemFolderId); |
| 566 } | 564 } |
| 567 | 565 |
| 568 void AppListSyncableService::RemoveSyncItem(const std::string& id) { | 566 void AppListSyncableService::RemoveSyncItem(const std::string& id) { |
| 569 VLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8); | 567 VLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8); |
| 570 SyncItemMap::iterator iter = sync_items_.find(id); | 568 auto iter = sync_items_.find(id); |
| 571 if (iter == sync_items_.end()) { | 569 if (iter == sync_items_.end()) { |
| 572 DVLOG(2) << this << " : RemoveSyncItem: No Item."; | 570 DVLOG(2) << this << " : RemoveSyncItem: No Item."; |
| 573 return; | 571 return; |
| 574 } | 572 } |
| 575 | 573 |
| 576 // Check for existing RemoveDefault sync item. | 574 // Check for existing RemoveDefault sync item. |
| 577 SyncItem* sync_item = iter->second; | 575 SyncItem* sync_item = iter->second.get(); |
| 578 sync_pb::AppListSpecifics::AppListItemType type = sync_item->item_type; | 576 sync_pb::AppListSpecifics::AppListItemType type = sync_item->item_type; |
| 579 if (type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 577 if (type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 580 // RemoveDefault item exists, just return. | 578 // RemoveDefault item exists, just return. |
| 581 DVLOG(2) << this << " : RemoveDefault Item exists."; | 579 DVLOG(2) << this << " : RemoveDefault Item exists."; |
| 582 return; | 580 return; |
| 583 } | 581 } |
| 584 | 582 |
| 585 if (type == sync_pb::AppListSpecifics::TYPE_APP && | 583 if (type == sync_pb::AppListSpecifics::TYPE_APP && |
| 586 AppIsDefault(extension_system_->extension_service(), id)) { | 584 AppIsDefault(extension_system_->extension_service(), id)) { |
| 587 // This is a Default app; update the entry to a REMOVE_DEFAULT entry. This | 585 // This is a Default app; update the entry to a REMOVE_DEFAULT entry. This |
| 588 // will overwrite any existing entry for the item. | 586 // will overwrite any existing entry for the item. |
| 589 VLOG(2) << this << " -> SYNC UPDATE: REMOVE_DEFAULT: " | 587 VLOG(2) << this << " -> SYNC UPDATE: REMOVE_DEFAULT: " |
| 590 << sync_item->item_id; | 588 << sync_item->item_id; |
| 591 sync_item->item_type = sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP; | 589 sync_item->item_type = sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP; |
| 592 SendSyncChange(sync_item, SyncChange::ACTION_UPDATE); | 590 SendSyncChange(sync_item, SyncChange::ACTION_UPDATE); |
| 593 return; | 591 return; |
| 594 } | 592 } |
| 595 | 593 |
| 596 DeleteSyncItem(sync_item); | 594 DeleteSyncItem(sync_item); |
| 597 } | 595 } |
| 598 | 596 |
| 599 void AppListSyncableService::ResolveFolderPositions() { | 597 void AppListSyncableService::ResolveFolderPositions() { |
| 600 if (!app_list::switches::IsFolderUIEnabled()) | 598 if (!app_list::switches::IsFolderUIEnabled()) |
| 601 return; | 599 return; |
| 602 | 600 |
| 603 VLOG(1) << "ResolveFolderPositions."; | 601 VLOG(1) << "ResolveFolderPositions."; |
| 604 for (SyncItemMap::iterator iter = sync_items_.begin(); | 602 for (auto iter = sync_items_.begin(); iter != sync_items_.end(); ++iter) { |
|
Nico
2016/09/22 15:56:12
for-each (?)
Avi (use Gerrit)
2016/09/22 19:17:17
Done.
| |
| 605 iter != sync_items_.end(); ++iter) { | 603 SyncItem* sync_item = iter->second.get(); |
| 606 SyncItem* sync_item = iter->second; | |
| 607 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) | 604 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) |
| 608 continue; | 605 continue; |
| 609 AppListItem* app_item = model_->FindItem(sync_item->item_id); | 606 AppListItem* app_item = model_->FindItem(sync_item->item_id); |
| 610 if (!app_item) | 607 if (!app_item) |
| 611 continue; | 608 continue; |
| 612 UpdateAppItemFromSyncItem(sync_item, app_item); | 609 UpdateAppItemFromSyncItem(sync_item, app_item); |
| 613 } | 610 } |
| 614 | 611 |
| 615 // Move the OEM folder if one exists and we have not synced its position. | 612 // Move the OEM folder if one exists and we have not synced its position. |
| 616 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); | 613 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); |
| 617 if (oem_folder && !FindSyncItem(kOemFolderId)) { | 614 if (oem_folder && !FindSyncItem(kOemFolderId)) { |
| 618 model_->SetItemPosition(oem_folder, GetOemFolderPos()); | 615 model_->SetItemPosition(oem_folder, GetOemFolderPos()); |
| 619 VLOG(1) << "Creating new OEM folder sync item: " | 616 VLOG(1) << "Creating new OEM folder sync item: " |
| 620 << oem_folder->position().ToDebugString(); | 617 << oem_folder->position().ToDebugString(); |
| 621 CreateSyncItemFromAppItem(oem_folder); | 618 CreateSyncItemFromAppItem(oem_folder); |
| 622 } | 619 } |
| 623 } | 620 } |
| 624 | 621 |
| 625 void AppListSyncableService::PruneEmptySyncFolders() { | 622 void AppListSyncableService::PruneEmptySyncFolders() { |
| 626 if (!app_list::switches::IsFolderUIEnabled()) | 623 if (!app_list::switches::IsFolderUIEnabled()) |
| 627 return; | 624 return; |
| 628 | 625 |
| 629 std::set<std::string> parent_ids; | 626 std::set<std::string> parent_ids; |
| 630 for (SyncItemMap::iterator iter = sync_items_.begin(); | 627 for (auto iter = sync_items_.begin(); iter != sync_items_.end(); ++iter) { |
|
Nico
2016/09/22 15:56:11
same
Avi (use Gerrit)
2016/09/22 19:17:17
Done.
| |
| 631 iter != sync_items_.end(); ++iter) { | |
| 632 parent_ids.insert(iter->second->parent_id); | 628 parent_ids.insert(iter->second->parent_id); |
| 633 } | 629 } |
| 634 for (SyncItemMap::iterator iter = sync_items_.begin(); | 630 for (auto iter = sync_items_.begin(); iter != sync_items_.end();) { |
|
Nico
2016/09/22 15:56:11
same
Avi (use Gerrit)
2016/09/22 19:17:17
Nope.
This loop deletes items (DeleteSyncItem) so
| |
| 635 iter != sync_items_.end(); ) { | 631 SyncItem* sync_item = (iter++)->second.get(); |
| 636 SyncItem* sync_item = (iter++)->second; | |
| 637 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) | 632 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) |
| 638 continue; | 633 continue; |
| 639 if (!base::ContainsKey(parent_ids, sync_item->item_id)) | 634 if (!base::ContainsKey(parent_ids, sync_item->item_id)) |
| 640 DeleteSyncItem(sync_item); | 635 DeleteSyncItem(sync_item); |
| 641 } | 636 } |
| 642 } | 637 } |
| 643 | 638 |
| 644 // AppListSyncableService syncer::SyncableService | 639 // AppListSyncableService syncer::SyncableService |
| 645 | 640 |
| 646 syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing( | 641 syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 660 if (switches::IsFolderUIEnabled()) | 655 if (switches::IsFolderUIEnabled()) |
| 661 model_->SetFoldersEnabled(true); | 656 model_->SetFoldersEnabled(true); |
| 662 | 657 |
| 663 syncer::SyncMergeResult result = syncer::SyncMergeResult(type); | 658 syncer::SyncMergeResult result = syncer::SyncMergeResult(type); |
| 664 result.set_num_items_before_association(sync_items_.size()); | 659 result.set_num_items_before_association(sync_items_.size()); |
| 665 VLOG(1) << this << ": MergeDataAndStartSyncing: " | 660 VLOG(1) << this << ": MergeDataAndStartSyncing: " |
| 666 << initial_sync_data.size(); | 661 << initial_sync_data.size(); |
| 667 | 662 |
| 668 // Copy all sync items to |unsynced_items|. | 663 // Copy all sync items to |unsynced_items|. |
| 669 std::set<std::string> unsynced_items; | 664 std::set<std::string> unsynced_items; |
| 670 for (SyncItemMap::const_iterator iter = sync_items_.begin(); | 665 for (auto iter = sync_items_.begin(); iter != sync_items_.end(); ++iter) { |
|
Nico
2016/09/22 15:56:12
same
Avi (use Gerrit)
2016/09/22 19:17:17
Done.
| |
| 671 iter != sync_items_.end(); ++iter) { | |
| 672 unsynced_items.insert(iter->first); | 666 unsynced_items.insert(iter->first); |
| 673 } | 667 } |
| 674 | 668 |
| 675 // Create SyncItem entries for initial_sync_data. | 669 // Create SyncItem entries for initial_sync_data. |
| 676 size_t new_items = 0, updated_items = 0; | 670 size_t new_items = 0, updated_items = 0; |
| 677 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin(); | 671 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin(); |
| 678 iter != initial_sync_data.end(); ++iter) { | 672 iter != initial_sync_data.end(); ++iter) { |
| 679 const syncer::SyncData& data = *iter; | 673 const syncer::SyncData& data = *iter; |
| 680 const std::string& item_id = data.GetSpecifics().app_list().item_id(); | 674 const std::string& item_id = data.GetSpecifics().app_list().item_id(); |
| 681 const sync_pb::AppListSpecifics& specifics = data.GetSpecifics().app_list(); | 675 const sync_pb::AppListSpecifics& specifics = data.GetSpecifics().app_list(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 sync_error_handler_.reset(); | 731 sync_error_handler_.reset(); |
| 738 model_->SetFoldersEnabled(false); | 732 model_->SetFoldersEnabled(false); |
| 739 } | 733 } |
| 740 | 734 |
| 741 syncer::SyncDataList AppListSyncableService::GetAllSyncData( | 735 syncer::SyncDataList AppListSyncableService::GetAllSyncData( |
| 742 syncer::ModelType type) const { | 736 syncer::ModelType type) const { |
| 743 DCHECK_EQ(syncer::APP_LIST, type); | 737 DCHECK_EQ(syncer::APP_LIST, type); |
| 744 | 738 |
| 745 VLOG(1) << this << ": GetAllSyncData: " << sync_items_.size(); | 739 VLOG(1) << this << ": GetAllSyncData: " << sync_items_.size(); |
| 746 syncer::SyncDataList list; | 740 syncer::SyncDataList list; |
| 747 for (SyncItemMap::const_iterator iter = sync_items_.begin(); | 741 for (auto iter = sync_items_.begin(); iter != sync_items_.end(); ++iter) { |
| 748 iter != sync_items_.end(); ++iter) { | |
| 749 VLOG(2) << this << " -> SYNC: " << iter->second->ToString(); | 742 VLOG(2) << this << " -> SYNC: " << iter->second->ToString(); |
| 750 list.push_back(GetSyncDataFromSyncItem(iter->second)); | 743 list.push_back(GetSyncDataFromSyncItem(iter->second.get())); |
| 751 } | 744 } |
| 752 return list; | 745 return list; |
| 753 } | 746 } |
| 754 | 747 |
| 755 syncer::SyncError AppListSyncableService::ProcessSyncChanges( | 748 syncer::SyncError AppListSyncableService::ProcessSyncChanges( |
| 756 const tracked_objects::Location& from_here, | 749 const tracked_objects::Location& from_here, |
| 757 const syncer::SyncChangeList& change_list) { | 750 const syncer::SyncChangeList& change_list) { |
| 758 if (!sync_processor_.get()) { | 751 if (!sync_processor_.get()) { |
| 759 return syncer::SyncError(FROM_HERE, | 752 return syncer::SyncError(FROM_HERE, |
| 760 syncer::SyncError::DATATYPE_ERROR, | 753 syncer::SyncError::DATATYPE_ERROR, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP && | 806 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP && |
| 814 specifics.item_type() != | 807 specifics.item_type() != |
| 815 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 808 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 816 LOG(ERROR) << "Synced item type: " << specifics.item_type() | 809 LOG(ERROR) << "Synced item type: " << specifics.item_type() |
| 817 << " != existing sync item type: " << sync_item->item_type | 810 << " != existing sync item type: " << sync_item->item_type |
| 818 << " Deleting item from model!"; | 811 << " Deleting item from model!"; |
| 819 model_->DeleteItem(item_id); | 812 model_->DeleteItem(item_id); |
| 820 } | 813 } |
| 821 VLOG(2) << this << " - ProcessSyncItem: Delete existing entry: " | 814 VLOG(2) << this << " - ProcessSyncItem: Delete existing entry: " |
| 822 << sync_item->ToString(); | 815 << sync_item->ToString(); |
| 823 delete sync_item; | |
| 824 sync_items_.erase(item_id); | 816 sync_items_.erase(item_id); |
| 825 } | 817 } |
| 826 | 818 |
| 827 sync_item = CreateSyncItem(item_id, specifics.item_type()); | 819 sync_item = CreateSyncItem(item_id, specifics.item_type()); |
| 828 UpdateSyncItemFromSync(specifics, sync_item); | 820 UpdateSyncItemFromSync(specifics, sync_item); |
| 829 ProcessNewSyncItem(sync_item); | 821 ProcessNewSyncItem(sync_item); |
| 830 VLOG(2) << this << " <- SYNC ADD: " << sync_item->ToString(); | 822 VLOG(2) << this << " <- SYNC ADD: " << sync_item->ToString(); |
| 831 return true; | 823 return true; |
| 832 } | 824 } |
| 833 | 825 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 else | 934 else |
| 943 VLOG(2) << this << " -> SYNC UPDATE: " << sync_item->ToString(); | 935 VLOG(2) << this << " -> SYNC UPDATE: " << sync_item->ToString(); |
| 944 SyncChange sync_change(FROM_HERE, sync_change_type, | 936 SyncChange sync_change(FROM_HERE, sync_change_type, |
| 945 GetSyncDataFromSyncItem(sync_item)); | 937 GetSyncDataFromSyncItem(sync_item)); |
| 946 sync_processor_->ProcessSyncChanges( | 938 sync_processor_->ProcessSyncChanges( |
| 947 FROM_HERE, syncer::SyncChangeList(1, sync_change)); | 939 FROM_HERE, syncer::SyncChangeList(1, sync_change)); |
| 948 } | 940 } |
| 949 | 941 |
| 950 AppListSyncableService::SyncItem* | 942 AppListSyncableService::SyncItem* |
| 951 AppListSyncableService::FindSyncItem(const std::string& item_id) { | 943 AppListSyncableService::FindSyncItem(const std::string& item_id) { |
| 952 SyncItemMap::iterator iter = sync_items_.find(item_id); | 944 auto iter = sync_items_.find(item_id); |
| 953 if (iter == sync_items_.end()) | 945 if (iter == sync_items_.end()) |
| 954 return NULL; | 946 return NULL; |
| 955 return iter->second; | 947 return iter->second.get(); |
| 956 } | 948 } |
| 957 | 949 |
| 958 AppListSyncableService::SyncItem* | 950 AppListSyncableService::SyncItem* |
| 959 AppListSyncableService::CreateSyncItem( | 951 AppListSyncableService::CreateSyncItem( |
| 960 const std::string& item_id, | 952 const std::string& item_id, |
| 961 sync_pb::AppListSpecifics::AppListItemType item_type) { | 953 sync_pb::AppListSpecifics::AppListItemType item_type) { |
| 962 DCHECK(!base::ContainsKey(sync_items_, item_id)); | 954 DCHECK(!base::ContainsKey(sync_items_, item_id)); |
| 963 SyncItem* sync_item = new SyncItem(item_id, item_type); | 955 sync_items_[item_id] = base::MakeUnique<SyncItem>(item_id, item_type); |
| 964 sync_items_[item_id] = sync_item; | 956 return sync_items_[item_id].get(); |
| 965 return sync_item; | |
| 966 } | 957 } |
| 967 | 958 |
| 968 void AppListSyncableService::DeleteSyncItemSpecifics( | 959 void AppListSyncableService::DeleteSyncItemSpecifics( |
| 969 const sync_pb::AppListSpecifics& specifics) { | 960 const sync_pb::AppListSpecifics& specifics) { |
| 970 const std::string& item_id = specifics.item_id(); | 961 const std::string& item_id = specifics.item_id(); |
| 971 if (item_id.empty()) { | 962 if (item_id.empty()) { |
| 972 LOG(ERROR) << "Delete AppList item with empty ID"; | 963 LOG(ERROR) << "Delete AppList item with empty ID"; |
| 973 return; | 964 return; |
| 974 } | 965 } |
| 975 VLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8); | 966 VLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8); |
| 976 SyncItemMap::iterator iter = sync_items_.find(item_id); | 967 auto iter = sync_items_.find(item_id); |
| 977 if (iter == sync_items_.end()) | 968 if (iter == sync_items_.end()) |
| 978 return; | 969 return; |
| 979 sync_pb::AppListSpecifics::AppListItemType item_type = | 970 sync_pb::AppListSpecifics::AppListItemType item_type = |
| 980 iter->second->item_type; | 971 iter->second->item_type; |
| 981 VLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString(); | 972 VLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString(); |
| 982 delete iter->second; | |
| 983 sync_items_.erase(iter); | 973 sync_items_.erase(iter); |
| 984 // Only delete apps from the model. Folders will be deleted when all | 974 // Only delete apps from the model. Folders will be deleted when all |
| 985 // children have been deleted. | 975 // children have been deleted. |
| 986 if (item_type == sync_pb::AppListSpecifics::TYPE_APP) { | 976 if (item_type == sync_pb::AppListSpecifics::TYPE_APP) { |
| 987 model_->DeleteItem(item_id); | 977 model_->DeleteItem(item_id); |
| 988 } else if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 978 } else if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 989 if (IsDriveAppSyncId(item_id) && drive_app_provider_) { | 979 if (IsDriveAppSyncId(item_id) && drive_app_provider_) { |
| 990 drive_app_provider_->RemoveUninstalledDriveAppFromSync( | 980 drive_app_provider_->RemoveUninstalledDriveAppFromSync( |
| 991 GetDriveAppIdFromSyncId(item_id)); | 981 GetDriveAppIdFromSyncId(item_id)); |
| 992 } | 982 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1013 } | 1003 } |
| 1014 model_->SetItemName(oem_folder, oem_folder_name_); | 1004 model_->SetItemName(oem_folder, oem_folder_name_); |
| 1015 return oem_folder->id(); | 1005 return oem_folder->id(); |
| 1016 } | 1006 } |
| 1017 | 1007 |
| 1018 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { | 1008 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { |
| 1019 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_; | 1009 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_; |
| 1020 if (!first_app_list_sync_) { | 1010 if (!first_app_list_sync_) { |
| 1021 VLOG(1) << "Sync items exist, placing OEM folder at end."; | 1011 VLOG(1) << "Sync items exist, placing OEM folder at end."; |
| 1022 syncer::StringOrdinal last; | 1012 syncer::StringOrdinal last; |
| 1023 for (SyncItemMap::iterator iter = sync_items_.begin(); | 1013 for (auto iter = sync_items_.begin(); iter != sync_items_.end(); ++iter) { |
|
Nico
2016/09/22 15:56:11
same (?)
Avi (use Gerrit)
2016/09/22 19:17:17
Done.
| |
| 1024 iter != sync_items_.end(); ++iter) { | 1014 SyncItem* sync_item = iter->second.get(); |
| 1025 SyncItem* sync_item = iter->second; | |
| 1026 if (sync_item->item_ordinal.IsValid() && | 1015 if (sync_item->item_ordinal.IsValid() && |
| 1027 (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) { | 1016 (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) { |
| 1028 last = sync_item->item_ordinal; | 1017 last = sync_item->item_ordinal; |
| 1029 } | 1018 } |
| 1030 } | 1019 } |
| 1031 if (last.IsValid()) | 1020 if (last.IsValid()) |
| 1032 return last.CreateAfter(); | 1021 return last.CreateAfter(); |
| 1033 } | 1022 } |
| 1034 | 1023 |
| 1035 // Place the OEM folder just after the web store, which should always be | 1024 // Place the OEM folder just after the web store, which should always be |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 res += " { " + item_name + " }"; | 1070 res += " { " + item_name + " }"; |
| 1082 res += " [" + item_ordinal.ToDebugString() + "]"; | 1071 res += " [" + item_ordinal.ToDebugString() + "]"; |
| 1083 if (!parent_id.empty()) | 1072 if (!parent_id.empty()) |
| 1084 res += " <" + parent_id.substr(0, 8) + ">"; | 1073 res += " <" + parent_id.substr(0, 8) + ">"; |
| 1085 res += " [" + item_pin_ordinal.ToDebugString() + "]"; | 1074 res += " [" + item_pin_ordinal.ToDebugString() + "]"; |
| 1086 } | 1075 } |
| 1087 return res; | 1076 return res; |
| 1088 } | 1077 } |
| 1089 | 1078 |
| 1090 } // namespace app_list | 1079 } // namespace app_list |
| OLD | NEW |