| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 364 |
| 366 void AppListSyncableService::UntrackUninstalledDriveApp( | 365 void AppListSyncableService::UntrackUninstalledDriveApp( |
| 367 const std::string& drive_app_id) { | 366 const std::string& drive_app_id) { |
| 368 const std::string sync_id = GetDriveAppSyncId(drive_app_id); | 367 const std::string sync_id = GetDriveAppSyncId(drive_app_id); |
| 369 SyncItem* sync_item = FindSyncItem(sync_id); | 368 SyncItem* sync_item = FindSyncItem(sync_id); |
| 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(drive_app_id); |
| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 AppIsDefault(extension_system_->extension_service(), item->id())) { | 503 AppIsDefault(extension_system_->extension_service(), item->id())) { |
| 505 VLOG(2) << this << ": HandleDefaultApp: Uninstall: " | 504 VLOG(2) << this << ": HandleDefaultApp: Uninstall: " |
| 506 << sync_item->ToString(); | 505 << sync_item->ToString(); |
| 507 UninstallExtension(extension_system_->extension_service(), item->id()); | 506 UninstallExtension(extension_system_->extension_service(), item->id()); |
| 508 return true; | 507 return true; |
| 509 } | 508 } |
| 510 | 509 |
| 511 // Otherwise, we are adding the app as a non-default app (i.e. an app that | 510 // Otherwise, we are adding the app as a non-default app (i.e. an app that |
| 512 // was installed by Default and removed is getting installed explicitly by | 511 // was installed by Default and removed is getting installed explicitly by |
| 513 // the user), so delete the REMOVE_DEFAULT_APP. | 512 // the user), so delete the REMOVE_DEFAULT_APP. |
| 514 DeleteSyncItem(sync_item); | 513 DeleteSyncItem(sync_item->item_id); |
| 515 return false; | 514 return false; |
| 516 } | 515 } |
| 517 | 516 |
| 518 void AppListSyncableService::DeleteSyncItem(SyncItem* sync_item) { | 517 void AppListSyncableService::DeleteSyncItem(const std::string& item_id) { |
| 518 SyncItem* sync_item = FindSyncItem(item_id); |
| 519 if (!sync_item) { |
| 520 LOG(ERROR) << "DeleteSyncItem: no sync item: " << item_id; |
| 521 return; |
| 522 } |
| 519 if (SyncStarted()) { | 523 if (SyncStarted()) { |
| 520 VLOG(2) << this << " -> SYNC DELETE: " << sync_item->ToString(); | 524 VLOG(2) << this << " -> SYNC DELETE: " << sync_item->ToString(); |
| 521 SyncChange sync_change(FROM_HERE, SyncChange::ACTION_DELETE, | 525 SyncChange sync_change(FROM_HERE, SyncChange::ACTION_DELETE, |
| 522 GetSyncDataFromSyncItem(sync_item)); | 526 GetSyncDataFromSyncItem(sync_item)); |
| 523 sync_processor_->ProcessSyncChanges( | 527 sync_processor_->ProcessSyncChanges( |
| 524 FROM_HERE, syncer::SyncChangeList(1, sync_change)); | 528 FROM_HERE, syncer::SyncChangeList(1, sync_change)); |
| 525 } | 529 } |
| 526 std::string item_id = sync_item->item_id; | |
| 527 delete sync_item; | |
| 528 sync_items_.erase(item_id); | 530 sync_items_.erase(item_id); |
| 529 } | 531 } |
| 530 | 532 |
| 531 void AppListSyncableService::UpdateSyncItem(AppListItem* app_item) { | 533 void AppListSyncableService::UpdateSyncItem(AppListItem* app_item) { |
| 532 SyncItem* sync_item = FindSyncItem(app_item->id()); | 534 SyncItem* sync_item = FindSyncItem(app_item->id()); |
| 533 if (!sync_item) { | 535 if (!sync_item) { |
| 534 LOG(ERROR) << "UpdateItem: no sync item: " << app_item->id(); | 536 LOG(ERROR) << "UpdateItem: no sync item: " << app_item->id(); |
| 535 return; | 537 return; |
| 536 } | 538 } |
| 537 bool changed = UpdateSyncItemFromAppItem(app_item, sync_item); | 539 bool changed = UpdateSyncItemFromAppItem(app_item, sync_item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 560 return; | 562 return; |
| 561 bool is_oem = AppIsOem(app_item->id()); | 563 bool is_oem = AppIsOem(app_item->id()); |
| 562 if (!is_oem && app_item->folder_id() == kOemFolderId) | 564 if (!is_oem && app_item->folder_id() == kOemFolderId) |
| 563 model_->MoveItemToFolder(app_item, ""); | 565 model_->MoveItemToFolder(app_item, ""); |
| 564 else if (is_oem && app_item->folder_id() != kOemFolderId) | 566 else if (is_oem && app_item->folder_id() != kOemFolderId) |
| 565 model_->MoveItemToFolder(app_item, kOemFolderId); | 567 model_->MoveItemToFolder(app_item, kOemFolderId); |
| 566 } | 568 } |
| 567 | 569 |
| 568 void AppListSyncableService::RemoveSyncItem(const std::string& id) { | 570 void AppListSyncableService::RemoveSyncItem(const std::string& id) { |
| 569 VLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8); | 571 VLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8); |
| 570 SyncItemMap::iterator iter = sync_items_.find(id); | 572 auto iter = sync_items_.find(id); |
| 571 if (iter == sync_items_.end()) { | 573 if (iter == sync_items_.end()) { |
| 572 DVLOG(2) << this << " : RemoveSyncItem: No Item."; | 574 DVLOG(2) << this << " : RemoveSyncItem: No Item."; |
| 573 return; | 575 return; |
| 574 } | 576 } |
| 575 | 577 |
| 576 // Check for existing RemoveDefault sync item. | 578 // Check for existing RemoveDefault sync item. |
| 577 SyncItem* sync_item = iter->second; | 579 SyncItem* sync_item = iter->second.get(); |
| 578 sync_pb::AppListSpecifics::AppListItemType type = sync_item->item_type; | 580 sync_pb::AppListSpecifics::AppListItemType type = sync_item->item_type; |
| 579 if (type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 581 if (type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 580 // RemoveDefault item exists, just return. | 582 // RemoveDefault item exists, just return. |
| 581 DVLOG(2) << this << " : RemoveDefault Item exists."; | 583 DVLOG(2) << this << " : RemoveDefault Item exists."; |
| 582 return; | 584 return; |
| 583 } | 585 } |
| 584 | 586 |
| 585 if (type == sync_pb::AppListSpecifics::TYPE_APP && | 587 if (type == sync_pb::AppListSpecifics::TYPE_APP && |
| 586 AppIsDefault(extension_system_->extension_service(), id)) { | 588 AppIsDefault(extension_system_->extension_service(), id)) { |
| 587 // This is a Default app; update the entry to a REMOVE_DEFAULT entry. This | 589 // This is a Default app; update the entry to a REMOVE_DEFAULT entry. This |
| 588 // will overwrite any existing entry for the item. | 590 // will overwrite any existing entry for the item. |
| 589 VLOG(2) << this << " -> SYNC UPDATE: REMOVE_DEFAULT: " | 591 VLOG(2) << this << " -> SYNC UPDATE: REMOVE_DEFAULT: " |
| 590 << sync_item->item_id; | 592 << sync_item->item_id; |
| 591 sync_item->item_type = sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP; | 593 sync_item->item_type = sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP; |
| 592 SendSyncChange(sync_item, SyncChange::ACTION_UPDATE); | 594 SendSyncChange(sync_item, SyncChange::ACTION_UPDATE); |
| 593 return; | 595 return; |
| 594 } | 596 } |
| 595 | 597 |
| 596 DeleteSyncItem(sync_item); | 598 DeleteSyncItem(iter->first); |
| 597 } | 599 } |
| 598 | 600 |
| 599 void AppListSyncableService::ResolveFolderPositions() { | 601 void AppListSyncableService::ResolveFolderPositions() { |
| 600 if (!app_list::switches::IsFolderUIEnabled()) | 602 if (!app_list::switches::IsFolderUIEnabled()) |
| 601 return; | 603 return; |
| 602 | 604 |
| 603 VLOG(1) << "ResolveFolderPositions."; | 605 VLOG(1) << "ResolveFolderPositions."; |
| 604 for (SyncItemMap::iterator iter = sync_items_.begin(); | 606 for (const auto& sync_pair : sync_items_) { |
| 605 iter != sync_items_.end(); ++iter) { | 607 SyncItem* sync_item = sync_pair.second.get(); |
| 606 SyncItem* sync_item = iter->second; | |
| 607 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) | 608 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) |
| 608 continue; | 609 continue; |
| 609 AppListItem* app_item = model_->FindItem(sync_item->item_id); | 610 AppListItem* app_item = model_->FindItem(sync_item->item_id); |
| 610 if (!app_item) | 611 if (!app_item) |
| 611 continue; | 612 continue; |
| 612 UpdateAppItemFromSyncItem(sync_item, app_item); | 613 UpdateAppItemFromSyncItem(sync_item, app_item); |
| 613 } | 614 } |
| 614 | 615 |
| 615 // Move the OEM folder if one exists and we have not synced its position. | 616 // Move the OEM folder if one exists and we have not synced its position. |
| 616 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); | 617 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); |
| 617 if (oem_folder && !FindSyncItem(kOemFolderId)) { | 618 if (oem_folder && !FindSyncItem(kOemFolderId)) { |
| 618 model_->SetItemPosition(oem_folder, GetOemFolderPos()); | 619 model_->SetItemPosition(oem_folder, GetOemFolderPos()); |
| 619 VLOG(1) << "Creating new OEM folder sync item: " | 620 VLOG(1) << "Creating new OEM folder sync item: " |
| 620 << oem_folder->position().ToDebugString(); | 621 << oem_folder->position().ToDebugString(); |
| 621 CreateSyncItemFromAppItem(oem_folder); | 622 CreateSyncItemFromAppItem(oem_folder); |
| 622 } | 623 } |
| 623 } | 624 } |
| 624 | 625 |
| 625 void AppListSyncableService::PruneEmptySyncFolders() { | 626 void AppListSyncableService::PruneEmptySyncFolders() { |
| 626 if (!app_list::switches::IsFolderUIEnabled()) | 627 if (!app_list::switches::IsFolderUIEnabled()) |
| 627 return; | 628 return; |
| 628 | 629 |
| 629 std::set<std::string> parent_ids; | 630 std::set<std::string> parent_ids; |
| 630 for (SyncItemMap::iterator iter = sync_items_.begin(); | 631 for (const auto& sync_pair : sync_items_) |
| 631 iter != sync_items_.end(); ++iter) { | 632 parent_ids.insert(sync_pair.second->parent_id); |
| 632 parent_ids.insert(iter->second->parent_id); | 633 |
| 633 } | 634 for (auto iter = sync_items_.begin(); iter != sync_items_.end();) { |
| 634 for (SyncItemMap::iterator iter = sync_items_.begin(); | 635 SyncItem* sync_item = (iter++)->second.get(); |
| 635 iter != sync_items_.end(); ) { | |
| 636 SyncItem* sync_item = (iter++)->second; | |
| 637 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) | 636 if (sync_item->item_type != sync_pb::AppListSpecifics::TYPE_FOLDER) |
| 638 continue; | 637 continue; |
| 639 if (!base::ContainsKey(parent_ids, sync_item->item_id)) | 638 if (!base::ContainsKey(parent_ids, sync_item->item_id)) |
| 640 DeleteSyncItem(sync_item); | 639 DeleteSyncItem(sync_item->item_id); |
| 641 } | 640 } |
| 642 } | 641 } |
| 643 | 642 |
| 644 // AppListSyncableService syncer::SyncableService | 643 // AppListSyncableService syncer::SyncableService |
| 645 | 644 |
| 646 syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing( | 645 syncer::SyncMergeResult AppListSyncableService::MergeDataAndStartSyncing( |
| 647 syncer::ModelType type, | 646 syncer::ModelType type, |
| 648 const syncer::SyncDataList& initial_sync_data, | 647 const syncer::SyncDataList& initial_sync_data, |
| 649 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, | 648 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 650 std::unique_ptr<syncer::SyncErrorFactory> error_handler) { | 649 std::unique_ptr<syncer::SyncErrorFactory> error_handler) { |
| 651 DCHECK(!sync_processor_.get()); | 650 DCHECK(!sync_processor_.get()); |
| 652 DCHECK(sync_processor.get()); | 651 DCHECK(sync_processor.get()); |
| 653 DCHECK(error_handler.get()); | 652 DCHECK(error_handler.get()); |
| 654 | 653 |
| 655 // Ensure the model is built. | 654 // Ensure the model is built. |
| 656 GetModel(); | 655 GetModel(); |
| 657 | 656 |
| 658 sync_processor_ = std::move(sync_processor); | 657 sync_processor_ = std::move(sync_processor); |
| 659 sync_error_handler_ = std::move(error_handler); | 658 sync_error_handler_ = std::move(error_handler); |
| 660 if (switches::IsFolderUIEnabled()) | 659 if (switches::IsFolderUIEnabled()) |
| 661 model_->SetFoldersEnabled(true); | 660 model_->SetFoldersEnabled(true); |
| 662 | 661 |
| 663 syncer::SyncMergeResult result = syncer::SyncMergeResult(type); | 662 syncer::SyncMergeResult result = syncer::SyncMergeResult(type); |
| 664 result.set_num_items_before_association(sync_items_.size()); | 663 result.set_num_items_before_association(sync_items_.size()); |
| 665 VLOG(1) << this << ": MergeDataAndStartSyncing: " | 664 VLOG(1) << this << ": MergeDataAndStartSyncing: " |
| 666 << initial_sync_data.size(); | 665 << initial_sync_data.size(); |
| 667 | 666 |
| 668 // Copy all sync items to |unsynced_items|. | 667 // Copy all sync items to |unsynced_items|. |
| 669 std::set<std::string> unsynced_items; | 668 std::set<std::string> unsynced_items; |
| 670 for (SyncItemMap::const_iterator iter = sync_items_.begin(); | 669 for (const auto& sync_pair : sync_items_) { |
| 671 iter != sync_items_.end(); ++iter) { | 670 unsynced_items.insert(sync_pair.first); |
| 672 unsynced_items.insert(iter->first); | |
| 673 } | 671 } |
| 674 | 672 |
| 675 // Create SyncItem entries for initial_sync_data. | 673 // Create SyncItem entries for initial_sync_data. |
| 676 size_t new_items = 0, updated_items = 0; | 674 size_t new_items = 0, updated_items = 0; |
| 677 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin(); | 675 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin(); |
| 678 iter != initial_sync_data.end(); ++iter) { | 676 iter != initial_sync_data.end(); ++iter) { |
| 679 const syncer::SyncData& data = *iter; | 677 const syncer::SyncData& data = *iter; |
| 680 const std::string& item_id = data.GetSpecifics().app_list().item_id(); | 678 const std::string& item_id = data.GetSpecifics().app_list().item_id(); |
| 681 const sync_pb::AppListSpecifics& specifics = data.GetSpecifics().app_list(); | 679 const sync_pb::AppListSpecifics& specifics = data.GetSpecifics().app_list(); |
| 682 DVLOG(2) << this << " Initial Sync Item: " << item_id | 680 DVLOG(2) << this << " Initial Sync Item: " << item_id |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 sync_error_handler_.reset(); | 735 sync_error_handler_.reset(); |
| 738 model_->SetFoldersEnabled(false); | 736 model_->SetFoldersEnabled(false); |
| 739 } | 737 } |
| 740 | 738 |
| 741 syncer::SyncDataList AppListSyncableService::GetAllSyncData( | 739 syncer::SyncDataList AppListSyncableService::GetAllSyncData( |
| 742 syncer::ModelType type) const { | 740 syncer::ModelType type) const { |
| 743 DCHECK_EQ(syncer::APP_LIST, type); | 741 DCHECK_EQ(syncer::APP_LIST, type); |
| 744 | 742 |
| 745 VLOG(1) << this << ": GetAllSyncData: " << sync_items_.size(); | 743 VLOG(1) << this << ": GetAllSyncData: " << sync_items_.size(); |
| 746 syncer::SyncDataList list; | 744 syncer::SyncDataList list; |
| 747 for (SyncItemMap::const_iterator iter = sync_items_.begin(); | 745 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(); | 746 VLOG(2) << this << " -> SYNC: " << iter->second->ToString(); |
| 750 list.push_back(GetSyncDataFromSyncItem(iter->second)); | 747 list.push_back(GetSyncDataFromSyncItem(iter->second.get())); |
| 751 } | 748 } |
| 752 return list; | 749 return list; |
| 753 } | 750 } |
| 754 | 751 |
| 755 syncer::SyncError AppListSyncableService::ProcessSyncChanges( | 752 syncer::SyncError AppListSyncableService::ProcessSyncChanges( |
| 756 const tracked_objects::Location& from_here, | 753 const tracked_objects::Location& from_here, |
| 757 const syncer::SyncChangeList& change_list) { | 754 const syncer::SyncChangeList& change_list) { |
| 758 if (!sync_processor_.get()) { | 755 if (!sync_processor_.get()) { |
| 759 return syncer::SyncError(FROM_HERE, | 756 return syncer::SyncError(FROM_HERE, |
| 760 syncer::SyncError::DATATYPE_ERROR, | 757 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 && | 810 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP && |
| 814 specifics.item_type() != | 811 specifics.item_type() != |
| 815 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 812 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 816 LOG(ERROR) << "Synced item type: " << specifics.item_type() | 813 LOG(ERROR) << "Synced item type: " << specifics.item_type() |
| 817 << " != existing sync item type: " << sync_item->item_type | 814 << " != existing sync item type: " << sync_item->item_type |
| 818 << " Deleting item from model!"; | 815 << " Deleting item from model!"; |
| 819 model_->DeleteItem(item_id); | 816 model_->DeleteItem(item_id); |
| 820 } | 817 } |
| 821 VLOG(2) << this << " - ProcessSyncItem: Delete existing entry: " | 818 VLOG(2) << this << " - ProcessSyncItem: Delete existing entry: " |
| 822 << sync_item->ToString(); | 819 << sync_item->ToString(); |
| 823 delete sync_item; | |
| 824 sync_items_.erase(item_id); | 820 sync_items_.erase(item_id); |
| 825 } | 821 } |
| 826 | 822 |
| 827 sync_item = CreateSyncItem(item_id, specifics.item_type()); | 823 sync_item = CreateSyncItem(item_id, specifics.item_type()); |
| 828 UpdateSyncItemFromSync(specifics, sync_item); | 824 UpdateSyncItemFromSync(specifics, sync_item); |
| 829 ProcessNewSyncItem(sync_item); | 825 ProcessNewSyncItem(sync_item); |
| 830 VLOG(2) << this << " <- SYNC ADD: " << sync_item->ToString(); | 826 VLOG(2) << this << " <- SYNC ADD: " << sync_item->ToString(); |
| 831 return true; | 827 return true; |
| 832 } | 828 } |
| 833 | 829 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 else | 938 else |
| 943 VLOG(2) << this << " -> SYNC UPDATE: " << sync_item->ToString(); | 939 VLOG(2) << this << " -> SYNC UPDATE: " << sync_item->ToString(); |
| 944 SyncChange sync_change(FROM_HERE, sync_change_type, | 940 SyncChange sync_change(FROM_HERE, sync_change_type, |
| 945 GetSyncDataFromSyncItem(sync_item)); | 941 GetSyncDataFromSyncItem(sync_item)); |
| 946 sync_processor_->ProcessSyncChanges( | 942 sync_processor_->ProcessSyncChanges( |
| 947 FROM_HERE, syncer::SyncChangeList(1, sync_change)); | 943 FROM_HERE, syncer::SyncChangeList(1, sync_change)); |
| 948 } | 944 } |
| 949 | 945 |
| 950 AppListSyncableService::SyncItem* | 946 AppListSyncableService::SyncItem* |
| 951 AppListSyncableService::FindSyncItem(const std::string& item_id) { | 947 AppListSyncableService::FindSyncItem(const std::string& item_id) { |
| 952 SyncItemMap::iterator iter = sync_items_.find(item_id); | 948 auto iter = sync_items_.find(item_id); |
| 953 if (iter == sync_items_.end()) | 949 if (iter == sync_items_.end()) |
| 954 return NULL; | 950 return NULL; |
| 955 return iter->second; | 951 return iter->second.get(); |
| 956 } | 952 } |
| 957 | 953 |
| 958 AppListSyncableService::SyncItem* | 954 AppListSyncableService::SyncItem* |
| 959 AppListSyncableService::CreateSyncItem( | 955 AppListSyncableService::CreateSyncItem( |
| 960 const std::string& item_id, | 956 const std::string& item_id, |
| 961 sync_pb::AppListSpecifics::AppListItemType item_type) { | 957 sync_pb::AppListSpecifics::AppListItemType item_type) { |
| 962 DCHECK(!base::ContainsKey(sync_items_, item_id)); | 958 DCHECK(!base::ContainsKey(sync_items_, item_id)); |
| 963 SyncItem* sync_item = new SyncItem(item_id, item_type); | 959 sync_items_[item_id] = base::MakeUnique<SyncItem>(item_id, item_type); |
| 964 sync_items_[item_id] = sync_item; | 960 return sync_items_[item_id].get(); |
| 965 return sync_item; | |
| 966 } | 961 } |
| 967 | 962 |
| 968 void AppListSyncableService::DeleteSyncItemSpecifics( | 963 void AppListSyncableService::DeleteSyncItemSpecifics( |
| 969 const sync_pb::AppListSpecifics& specifics) { | 964 const sync_pb::AppListSpecifics& specifics) { |
| 970 const std::string& item_id = specifics.item_id(); | 965 const std::string& item_id = specifics.item_id(); |
| 971 if (item_id.empty()) { | 966 if (item_id.empty()) { |
| 972 LOG(ERROR) << "Delete AppList item with empty ID"; | 967 LOG(ERROR) << "Delete AppList item with empty ID"; |
| 973 return; | 968 return; |
| 974 } | 969 } |
| 975 VLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8); | 970 VLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8); |
| 976 SyncItemMap::iterator iter = sync_items_.find(item_id); | 971 auto iter = sync_items_.find(item_id); |
| 977 if (iter == sync_items_.end()) | 972 if (iter == sync_items_.end()) |
| 978 return; | 973 return; |
| 979 sync_pb::AppListSpecifics::AppListItemType item_type = | 974 sync_pb::AppListSpecifics::AppListItemType item_type = |
| 980 iter->second->item_type; | 975 iter->second->item_type; |
| 981 VLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString(); | 976 VLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString(); |
| 982 delete iter->second; | |
| 983 sync_items_.erase(iter); | 977 sync_items_.erase(iter); |
| 984 // Only delete apps from the model. Folders will be deleted when all | 978 // Only delete apps from the model. Folders will be deleted when all |
| 985 // children have been deleted. | 979 // children have been deleted. |
| 986 if (item_type == sync_pb::AppListSpecifics::TYPE_APP) { | 980 if (item_type == sync_pb::AppListSpecifics::TYPE_APP) { |
| 987 model_->DeleteItem(item_id); | 981 model_->DeleteItem(item_id); |
| 988 } else if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 982 } else if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 989 if (IsDriveAppSyncId(item_id) && drive_app_provider_) { | 983 if (IsDriveAppSyncId(item_id) && drive_app_provider_) { |
| 990 drive_app_provider_->RemoveUninstalledDriveAppFromSync( | 984 drive_app_provider_->RemoveUninstalledDriveAppFromSync( |
| 991 GetDriveAppIdFromSyncId(item_id)); | 985 GetDriveAppIdFromSyncId(item_id)); |
| 992 } | 986 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1013 } | 1007 } |
| 1014 model_->SetItemName(oem_folder, oem_folder_name_); | 1008 model_->SetItemName(oem_folder, oem_folder_name_); |
| 1015 return oem_folder->id(); | 1009 return oem_folder->id(); |
| 1016 } | 1010 } |
| 1017 | 1011 |
| 1018 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { | 1012 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { |
| 1019 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_; | 1013 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_; |
| 1020 if (!first_app_list_sync_) { | 1014 if (!first_app_list_sync_) { |
| 1021 VLOG(1) << "Sync items exist, placing OEM folder at end."; | 1015 VLOG(1) << "Sync items exist, placing OEM folder at end."; |
| 1022 syncer::StringOrdinal last; | 1016 syncer::StringOrdinal last; |
| 1023 for (SyncItemMap::iterator iter = sync_items_.begin(); | 1017 for (const auto& sync_pair : sync_items_) { |
| 1024 iter != sync_items_.end(); ++iter) { | 1018 SyncItem* sync_item = sync_pair.second.get(); |
| 1025 SyncItem* sync_item = iter->second; | |
| 1026 if (sync_item->item_ordinal.IsValid() && | 1019 if (sync_item->item_ordinal.IsValid() && |
| 1027 (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) { | 1020 (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) { |
| 1028 last = sync_item->item_ordinal; | 1021 last = sync_item->item_ordinal; |
| 1029 } | 1022 } |
| 1030 } | 1023 } |
| 1031 if (last.IsValid()) | 1024 if (last.IsValid()) |
| 1032 return last.CreateAfter(); | 1025 return last.CreateAfter(); |
| 1033 } | 1026 } |
| 1034 | 1027 |
| 1035 // Place the OEM folder just after the web store, which should always be | 1028 // 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 + " }"; | 1074 res += " { " + item_name + " }"; |
| 1082 res += " [" + item_ordinal.ToDebugString() + "]"; | 1075 res += " [" + item_ordinal.ToDebugString() + "]"; |
| 1083 if (!parent_id.empty()) | 1076 if (!parent_id.empty()) |
| 1084 res += " <" + parent_id.substr(0, 8) + ">"; | 1077 res += " <" + parent_id.substr(0, 8) + ">"; |
| 1085 res += " [" + item_pin_ordinal.ToDebugString() + "]"; | 1078 res += " [" + item_pin_ordinal.ToDebugString() + "]"; |
| 1086 } | 1079 } |
| 1087 return res; | 1080 return res; |
| 1088 } | 1081 } |
| 1089 | 1082 |
| 1090 } // namespace app_list | 1083 } // namespace app_list |
| OLD | NEW |