Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/browser/ui/app_list/app_list_syncable_service.cc

Issue 373923002: Only count non-default apps against first time sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/apps/drive/drive_app_provider.h" 8 #include "chrome/browser/apps/drive/drive_app_provider.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 13 matching lines...) Expand all
24 #include "sync/api/sync_merge_result.h" 24 #include "sync/api/sync_merge_result.h"
25 #include "sync/protocol/sync.pb.h" 25 #include "sync/protocol/sync.pb.h"
26 #include "ui/app_list/app_list_folder_item.h" 26 #include "ui/app_list/app_list_folder_item.h"
27 #include "ui/app_list/app_list_item.h" 27 #include "ui/app_list/app_list_item.h"
28 #include "ui/app_list/app_list_model.h" 28 #include "ui/app_list/app_list_model.h"
29 #include "ui/app_list/app_list_model_observer.h" 29 #include "ui/app_list/app_list_model_observer.h"
30 #include "ui/app_list/app_list_switches.h" 30 #include "ui/app_list/app_list_switches.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 32
33 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
34 #include "chrome/browser/chromeos/file_manager/app_id.h"
34 #include "chrome/browser/chromeos/genius_app/app_id.h" 35 #include "chrome/browser/chromeos/genius_app/app_id.h"
35 #endif 36 #endif
36 37
37 using syncer::SyncChange; 38 using syncer::SyncChange;
38 39
39 namespace app_list { 40 namespace app_list {
40 41
41 namespace { 42 namespace {
42 43
43 const char kOemFolderId[] = "ddb1da55-d478-4243-8642-56d3041f0263"; 44 const char kOemFolderId[] = "ddb1da55-d478-4243-8642-56d3041f0263";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 bool AppIsDefault(ExtensionService* service, const std::string& id) { 102 bool AppIsDefault(ExtensionService* service, const std::string& id) {
102 return service && extensions::ExtensionPrefs::Get(service->profile()) 103 return service && extensions::ExtensionPrefs::Get(service->profile())
103 ->WasInstalledByDefault(id); 104 ->WasInstalledByDefault(id);
104 } 105 }
105 106
106 bool IsUnRemovableDefaultApp(const std::string& id) { 107 bool IsUnRemovableDefaultApp(const std::string& id) {
107 if (id == extension_misc::kChromeAppId || 108 if (id == extension_misc::kChromeAppId ||
108 id == extension_misc::kWebStoreAppId) 109 id == extension_misc::kWebStoreAppId)
109 return true; 110 return true;
110 #if defined(OS_CHROMEOS) 111 #if defined(OS_CHROMEOS)
111 if (id == genius_app::kGeniusAppId) 112 if (id == file_manager::kFileManagerAppId || id == genius_app::kGeniusAppId)
112 return true; 113 return true;
113 #endif 114 #endif
114 return false; 115 return false;
115 } 116 }
116 117
117 void UninstallExtension(ExtensionService* service, const std::string& id) { 118 void UninstallExtension(ExtensionService* service, const std::string& id) {
118 if (service && service->GetInstalledExtension(id)) 119 if (service && service->GetInstalledExtension(id))
119 service->UninstallExtension(id, false, NULL); 120 service->UninstallExtension(id, false, NULL);
120 } 121 }
121 122
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 }; 203 };
203 204
204 // AppListSyncableService 205 // AppListSyncableService
205 206
206 AppListSyncableService::AppListSyncableService( 207 AppListSyncableService::AppListSyncableService(
207 Profile* profile, 208 Profile* profile,
208 extensions::ExtensionSystem* extension_system) 209 extensions::ExtensionSystem* extension_system)
209 : profile_(profile), 210 : profile_(profile),
210 extension_system_(extension_system), 211 extension_system_(extension_system),
211 model_(new AppListModel), 212 model_(new AppListModel),
212 first_app_list_sync_(false) { 213 first_app_list_sync_(true) {
213 if (!extension_system) { 214 if (!extension_system) {
214 LOG(ERROR) << "AppListSyncableService created with no ExtensionSystem"; 215 LOG(ERROR) << "AppListSyncableService created with no ExtensionSystem";
215 return; 216 return;
216 } 217 }
217 218
218 oem_folder_name_ = 219 oem_folder_name_ =
219 l10n_util::GetStringUTF8(IDS_APP_LIST_OEM_DEFAULT_FOLDER_NAME); 220 l10n_util::GetStringUTF8(IDS_APP_LIST_OEM_DEFAULT_FOLDER_NAME);
220 221
221 // Note: model_observer_ is constructed after the initial sync changes are 222 // Note: model_observer_ is constructed after the initial sync changes are
222 // received in MergeDataAndStartSyncing(). Changes to the model before that 223 // received in MergeDataAndStartSyncing(). Changes to the model before that
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 VLOG(1) << this << ": MergeDataAndStartSyncing: " 531 VLOG(1) << this << ": MergeDataAndStartSyncing: "
531 << initial_sync_data.size(); 532 << initial_sync_data.size();
532 533
533 // Copy all sync items to |unsynced_items|. 534 // Copy all sync items to |unsynced_items|.
534 std::set<std::string> unsynced_items; 535 std::set<std::string> unsynced_items;
535 for (SyncItemMap::const_iterator iter = sync_items_.begin(); 536 for (SyncItemMap::const_iterator iter = sync_items_.begin();
536 iter != sync_items_.end(); ++iter) { 537 iter != sync_items_.end(); ++iter) {
537 unsynced_items.insert(iter->first); 538 unsynced_items.insert(iter->first);
538 } 539 }
539 540
540 first_app_list_sync_ = initial_sync_data.empty();
541
542 // Create SyncItem entries for initial_sync_data. 541 // Create SyncItem entries for initial_sync_data.
543 size_t new_items = 0, updated_items = 0; 542 size_t new_items = 0, updated_items = 0;
544 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin(); 543 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin();
545 iter != initial_sync_data.end(); ++iter) { 544 iter != initial_sync_data.end(); ++iter) {
546 const syncer::SyncData& data = *iter; 545 const syncer::SyncData& data = *iter;
547 const std::string& item_id = data.GetSpecifics().app_list().item_id(); 546 const std::string& item_id = data.GetSpecifics().app_list().item_id();
547 const sync_pb::AppListSpecifics& specifics = data.GetSpecifics().app_list();
548 DVLOG(2) << this << " Initial Sync Item: " << item_id 548 DVLOG(2) << this << " Initial Sync Item: " << item_id
549 << " Type: " << data.GetSpecifics().app_list().item_type(); 549 << " Type: " << specifics.item_type();
550 DCHECK_EQ(syncer::APP_LIST, data.GetDataType()); 550 DCHECK_EQ(syncer::APP_LIST, data.GetDataType());
551 if (ProcessSyncItemSpecifics(data.GetSpecifics().app_list())) 551 if (ProcessSyncItemSpecifics(specifics))
552 ++new_items; 552 ++new_items;
553 else 553 else
554 ++updated_items; 554 ++updated_items;
555 if (specifics.item_type() != sync_pb::AppListSpecifics::TYPE_FOLDER &&
556 !IsUnRemovableDefaultApp(item_id) &&
557 !AppIsDefault(extension_system_->extension_service(), item_id)) {
558 VLOG(2) << "Syncing non-default item: " << item_id;
559 first_app_list_sync_ = false;
560 }
555 unsynced_items.erase(item_id); 561 unsynced_items.erase(item_id);
556 } 562 }
557 563
558 result.set_num_items_after_association(sync_items_.size()); 564 result.set_num_items_after_association(sync_items_.size());
559 result.set_num_items_added(new_items); 565 result.set_num_items_added(new_items);
560 result.set_num_items_deleted(0); 566 result.set_num_items_deleted(0);
561 result.set_num_items_modified(updated_items); 567 result.set_num_items_modified(updated_items);
562 568
563 // Send unsynced items. Does not affect |result|. 569 // Send unsynced items. Does not affect |result|.
564 syncer::SyncChangeList change_list; 570 syncer::SyncChangeList change_list;
565 for (std::set<std::string>::iterator iter = unsynced_items.begin(); 571 for (std::set<std::string>::iterator iter = unsynced_items.begin();
566 iter != unsynced_items.end(); ++iter) { 572 iter != unsynced_items.end(); ++iter) {
567 SyncItem* sync_item = FindSyncItem(*iter); 573 SyncItem* sync_item = FindSyncItem(*iter);
574 // Sync can cause an item to change folders, causing an unsynced folder
575 // item to be removed.
576 if (!sync_item)
577 continue;
568 VLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString(); 578 VLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString();
569 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD, 579 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD,
570 GetSyncDataFromSyncItem(sync_item))); 580 GetSyncDataFromSyncItem(sync_item)));
571 } 581 }
572 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); 582 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
573 583
574 // Adding items may have created folders without setting their positions 584 // Adding items may have created folders without setting their positions
575 // since we haven't started observing the item list yet. Resolve those. 585 // since we haven't started observing the item list yet. Resolve those.
576 ResolveFolderPositions(); 586 ResolveFolderPositions();
577 587
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 DVLOG(1) << "Creating new OEM folder sync item: " 853 DVLOG(1) << "Creating new OEM folder sync item: "
844 << oem_folder->position().ToDebugString(); 854 << oem_folder->position().ToDebugString();
845 CreateSyncItemFromAppItem(oem_folder); 855 CreateSyncItemFromAppItem(oem_folder);
846 } 856 }
847 } 857 }
848 model_->SetItemName(oem_folder, oem_folder_name_); 858 model_->SetItemName(oem_folder, oem_folder_name_);
849 return oem_folder->id(); 859 return oem_folder->id();
850 } 860 }
851 861
852 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { 862 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() {
863 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_;
853 if (!first_app_list_sync_) { 864 if (!first_app_list_sync_) {
854 DVLOG(1) << "Sync items exist, placing OEM folder at end."; 865 DVLOG(1) << "Sync items exist, placing OEM folder at end.";
855 syncer::StringOrdinal last; 866 syncer::StringOrdinal last;
856 for (SyncItemMap::iterator iter = sync_items_.begin(); 867 for (SyncItemMap::iterator iter = sync_items_.begin();
857 iter != sync_items_.end(); ++iter) { 868 iter != sync_items_.end(); ++iter) {
858 SyncItem* sync_item = iter->second; 869 SyncItem* sync_item = iter->second;
859 if (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last)) 870 if (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))
860 last = sync_item->item_ordinal; 871 last = sync_item->item_ordinal;
861 } 872 }
862 return last.CreateAfter(); 873 return last.CreateAfter();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 } else { 915 } else {
905 res += " { " + item_name + " }"; 916 res += " { " + item_name + " }";
906 res += " [" + item_ordinal.ToDebugString() + "]"; 917 res += " [" + item_ordinal.ToDebugString() + "]";
907 if (!parent_id.empty()) 918 if (!parent_id.empty())
908 res += " <" + parent_id.substr(0, 8) + ">"; 919 res += " <" + parent_id.substr(0, 8) + ">";
909 } 920 }
910 return res; 921 return res;
911 } 922 }
912 923
913 } // namespace app_list 924 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698