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

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

Issue 148403007: Protect AppListItemList Add/Remove and fix sync bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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
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/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/app_list/app_list_service.h" 12 #include "chrome/browser/ui/app_list/app_list_service.h"
13 #include "chrome/browser/ui/app_list/extension_app_item.h" 13 #include "chrome/browser/ui/app_list/extension_app_item.h"
14 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" 14 #include "chrome/browser/ui/app_list/extension_app_model_builder.h"
15 #include "chrome/browser/ui/host_desktop.h" 15 #include "chrome/browser/ui/host_desktop.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
18 #include "extensions/browser/extension_prefs.h" 18 #include "extensions/browser/extension_prefs.h"
19 #include "sync/api/sync_change_processor.h" 19 #include "sync/api/sync_change_processor.h"
20 #include "sync/api/sync_data.h" 20 #include "sync/api/sync_data.h"
21 #include "sync/api/sync_merge_result.h" 21 #include "sync/api/sync_merge_result.h"
22 #include "sync/protocol/sync.pb.h" 22 #include "sync/protocol/sync.pb.h"
23 #include "ui/app_list/app_list_folder_item.h" 23 #include "ui/app_list/app_list_folder_item.h"
24 #include "ui/app_list/app_list_item.h" 24 #include "ui/app_list/app_list_item.h"
25 #include "ui/app_list/app_list_model.h" 25 #include "ui/app_list/app_list_model.h"
26 #include "ui/app_list/app_list_model_observer.h"
27 #include "ui/app_list/app_list_switches.h"
26 28
27 using syncer::SyncChange; 29 using syncer::SyncChange;
28 30
29 namespace app_list { 31 namespace app_list {
30 32
31 namespace { 33 namespace {
32 34
33 bool SyncAppListEnabled() { 35 bool SyncAppListEnabled() {
34 return CommandLine::ForCurrentProcess()->HasSwitch( 36 return CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kEnableSyncAppList); 37 ::switches::kEnableSyncAppList);
36 } 38 }
37 39
38 void UpdateSyncItemFromSync(const sync_pb::AppListSpecifics& specifics, 40 void UpdateSyncItemFromSync(const sync_pb::AppListSpecifics& specifics,
39 AppListSyncableService::SyncItem* item) { 41 AppListSyncableService::SyncItem* item) {
40 DCHECK_EQ(item->item_id, specifics.item_id()); 42 DCHECK_EQ(item->item_id, specifics.item_id());
41 item->item_type = specifics.item_type(); 43 item->item_type = specifics.item_type();
42 item->item_name = specifics.item_name(); 44 item->item_name = specifics.item_name();
43 item->parent_id = specifics.parent_id(); 45 item->parent_id = specifics.parent_id();
44 if (!specifics.page_ordinal().empty()) 46 if (!specifics.page_ordinal().empty())
45 item->page_ordinal = syncer::StringOrdinal(specifics.page_ordinal()); 47 item->page_ordinal = syncer::StringOrdinal(specifics.page_ordinal());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 AppListSyncableService::SyncItem::SyncItem( 118 AppListSyncableService::SyncItem::SyncItem(
117 const std::string& id, 119 const std::string& id,
118 sync_pb::AppListSpecifics::AppListItemType type) 120 sync_pb::AppListSpecifics::AppListItemType type)
119 : item_id(id), 121 : item_id(id),
120 item_type(type) { 122 item_type(type) {
121 } 123 }
122 124
123 AppListSyncableService::SyncItem::~SyncItem() { 125 AppListSyncableService::SyncItem::~SyncItem() {
124 } 126 }
125 127
126 // AppListSyncableService::ItemListObserver 128 // AppListSyncableService::ModelObserver
127 129
128 class AppListSyncableService::ItemListObserver 130 class AppListSyncableService::ModelObserver : public AppListModelObserver {
129 : public AppListItemListObserver {
130 public: 131 public:
131 explicit ItemListObserver(AppListSyncableService* owner) : owner_(owner) { 132 explicit ModelObserver(AppListSyncableService* owner)
132 owner_->model()->item_list()->AddObserver(this); 133 : owner_(owner) {
134 DVLOG(2) << owner_ << ": ModelObserver Added";
135 owner_->model()->AddObserver(this);
133 } 136 }
134 137
135 virtual ~ItemListObserver() { 138 virtual ~ModelObserver() {
136 owner_->model()->item_list()->RemoveObserver(this); 139 owner_->model()->RemoveObserver(this);
140 DVLOG(2) << owner_ << ": ModelObserver Removed";
137 } 141 }
138 142
139 private: 143 private:
140 // AppListItemListObserver 144 // AppListModelObserver
141 virtual void OnListItemAdded(size_t index, AppListItem* item) OVERRIDE { 145 virtual void OnAppListItemAdded(AppListItem* item) OVERRIDE {
146 DVLOG(2) << owner_ << " OnAppListItemAdded: " << item->ToDebugString();
142 owner_->AddOrUpdateFromSyncItem(item); 147 owner_->AddOrUpdateFromSyncItem(item);
143 } 148 }
144 149
145 virtual void OnListItemRemoved(size_t index, AppListItem* item) OVERRIDE { 150 virtual void OnAppListItemWillBeDeleted(AppListItem* item) OVERRIDE {
151 DVLOG(2) << owner_ << " OnAppListItemDeleted: " << item->ToDebugString();
146 owner_->RemoveSyncItem(item->id()); 152 owner_->RemoveSyncItem(item->id());
147 } 153 }
148 154
149 virtual void OnListItemMoved(size_t from_index, 155 virtual void OnAppListItemUpdated(AppListItem* item) OVERRIDE {
150 size_t to_index, 156 DVLOG(2) << owner_ << " OnAppListItemUpdated: " << item->ToDebugString();
151 AppListItem* item) OVERRIDE {
152 owner_->UpdateSyncItem(item); 157 owner_->UpdateSyncItem(item);
153 } 158 }
154 159
155 AppListSyncableService* owner_; 160 AppListSyncableService* owner_;
156 161
157 DISALLOW_COPY_AND_ASSIGN(ItemListObserver); 162 DISALLOW_COPY_AND_ASSIGN(ModelObserver);
158 }; 163 };
159 164
160 // AppListSyncableService 165 // AppListSyncableService
161 166
162 AppListSyncableService::AppListSyncableService( 167 AppListSyncableService::AppListSyncableService(
163 Profile* profile, 168 Profile* profile,
164 extensions::ExtensionSystem* extension_system) 169 extensions::ExtensionSystem* extension_system)
165 : profile_(profile), 170 : profile_(profile),
166 extension_system_(extension_system), 171 extension_system_(extension_system),
167 model_(new AppListModel) { 172 model_(new AppListModel) {
168 if (!extension_system || !extension_system->extension_service()) { 173 if (!extension_system || !extension_system->extension_service()) {
169 LOG(WARNING) << "AppListSyncableService created with no ExtensionService"; 174 LOG(WARNING) << "AppListSyncableService created with no ExtensionService";
170 return; 175 return;
171 } 176 }
172 177
173 if (SyncAppListEnabled()) 178 // Note: model_observer_ is constructed after the initial sync changes are
174 item_list_observer_.reset(new ItemListObserver(this)); 179 // received in MergeDataAndStartSyncing(). Changes to the model before that
175 180 // will be synced after the initial sync occurs.
176 if (extension_system->extension_service()->is_ready()) { 181 if (extension_system->extension_service()->is_ready()) {
177 BuildModel(); 182 BuildModel();
178 return; 183 return;
179 } 184 }
180 185
181 // The extensions for this profile have not yet all been loaded. 186 // The extensions for this profile have not yet all been loaded.
182 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 187 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
183 content::Source<Profile>(profile)); 188 content::Source<Profile>(profile));
184 } 189 }
185 190
186 AppListSyncableService::~AppListSyncableService() { 191 AppListSyncableService::~AppListSyncableService() {
187 // Remove observers. 192 // Remove observers.
188 item_list_observer_.reset(); 193 model_observer_.reset();
189 194
190 STLDeleteContainerPairSecondPointers(sync_items_.begin(), sync_items_.end()); 195 STLDeleteContainerPairSecondPointers(sync_items_.begin(), sync_items_.end());
191 } 196 }
192 197
193 void AppListSyncableService::BuildModel() { 198 void AppListSyncableService::BuildModel() {
194 // For now, use the AppListControllerDelegate associated with the native 199 // For now, use the AppListControllerDelegate associated with the native
195 // desktop. TODO(stevenjb): Remove ExtensionAppModelBuilder controller 200 // desktop. TODO(stevenjb): Remove ExtensionAppModelBuilder controller
196 // dependency and move the dependent methods from AppListControllerDelegate 201 // dependency and move the dependent methods from AppListControllerDelegate
197 // to an extension service delegate associated with this class. 202 // to an extension service delegate associated with this class.
198 AppListControllerDelegate* controller = NULL; 203 AppListControllerDelegate* controller = NULL;
(...skipping 26 matching lines...) Expand all
225 230
226 const AppListSyncableService::SyncItem* 231 const AppListSyncableService::SyncItem*
227 AppListSyncableService::GetSyncItem(const std::string& id) const { 232 AppListSyncableService::GetSyncItem(const std::string& id) const {
228 SyncItemMap::const_iterator iter = sync_items_.find(id); 233 SyncItemMap::const_iterator iter = sync_items_.find(id);
229 if (iter != sync_items_.end()) 234 if (iter != sync_items_.end())
230 return iter->second; 235 return iter->second;
231 return NULL; 236 return NULL;
232 } 237 }
233 238
234 void AppListSyncableService::AddItem(AppListItem* app_item) { 239 void AppListSyncableService::AddItem(AppListItem* app_item) {
235 SyncItem* sync_item = AddOrUpdateSyncItem(app_item); 240 SyncItem* sync_item = FindOrAddSyncItem(app_item);
236 if (!sync_item) 241 if (!sync_item)
237 return; // Item is not valid. 242 return; // Item is not valid.
238 243
239 DVLOG(1) << this << ": AddItem: " << sync_item->ToString(); 244 DVLOG(1) << this << ": AddItem: " << sync_item->ToString();
240 245 model_->AddItem(app_item);
241 // Add the item to the model if necessary.
242 if (!model_->item_list()->FindItem(app_item->id()))
243 model_->item_list()->AddItem(app_item);
244 else
245 model_->item_list()->SetItemPosition(app_item, sync_item->item_ordinal);
246 } 246 }
247 247
248 AppListSyncableService::SyncItem* AppListSyncableService::AddOrUpdateSyncItem( 248 AppListSyncableService::SyncItem* AppListSyncableService::FindOrAddSyncItem(
249 AppListItem* app_item) { 249 AppListItem* app_item) {
250 const std::string& item_id = app_item->id(); 250 const std::string& item_id = app_item->id();
251 if (item_id.empty()) { 251 if (item_id.empty()) {
252 LOG(ERROR) << "AppListItem item with empty ID"; 252 LOG(ERROR) << "AppListItem item with empty ID";
253 return NULL; 253 return NULL;
254 } 254 }
255 SyncItem* sync_item = FindSyncItem(item_id); 255 SyncItem* sync_item = FindSyncItem(item_id);
256 if (sync_item) { 256 if (sync_item) {
257 // If there is an existing, non-REMOVE_DEFAULT entry, update it. 257 // If there is an existing, non-REMOVE_DEFAULT entry, return it.
258 if (sync_item->item_type != 258 if (sync_item->item_type !=
259 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { 259 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) {
260 DVLOG(2) << this << ": AddItem already exists: " << sync_item->ToString(); 260 DVLOG(2) << this << ": AddItem already exists: " << sync_item->ToString();
261 UpdateSyncItem(app_item);
262 return sync_item; 261 return sync_item;
263 } 262 }
264 263
265 if (RemoveDefaultApp(app_item, sync_item)) 264 if (RemoveDefaultApp(app_item, sync_item))
266 return NULL; 265 return NULL;
267 266
268 // Fall through. The REMOVE_DEFAULT_APP entry has been deleted, now a new 267 // Fall through. The REMOVE_DEFAULT_APP entry has been deleted, now a new
269 // App entry can be added. 268 // App entry can be added.
270 } 269 }
271 270
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 bool changed = UpdateSyncItemFromAppItem(app_item, sync_item); 335 bool changed = UpdateSyncItemFromAppItem(app_item, sync_item);
337 if (!changed) { 336 if (!changed) {
338 DVLOG(2) << this << " - Update: SYNC NO CHANGE: " << sync_item->ToString(); 337 DVLOG(2) << this << " - Update: SYNC NO CHANGE: " << sync_item->ToString();
339 return; 338 return;
340 } 339 }
341 SendSyncChange(sync_item, SyncChange::ACTION_UPDATE); 340 SendSyncChange(sync_item, SyncChange::ACTION_UPDATE);
342 } 341 }
343 342
344 void AppListSyncableService::RemoveItem(const std::string& id) { 343 void AppListSyncableService::RemoveItem(const std::string& id) {
345 RemoveSyncItem(id); 344 RemoveSyncItem(id);
346 model_->item_list()->DeleteItem(id); 345 model_->DeleteItem(id);
347 } 346 }
348 347
349 void AppListSyncableService::RemoveSyncItem(const std::string& id) { 348 void AppListSyncableService::RemoveSyncItem(const std::string& id) {
350 DVLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8); 349 DVLOG(2) << this << ": RemoveSyncItem: " << id.substr(0, 8);
351 SyncItemMap::iterator iter = sync_items_.find(id); 350 SyncItemMap::iterator iter = sync_items_.find(id);
352 if (iter == sync_items_.end()) { 351 if (iter == sync_items_.end()) {
353 DVLOG(2) << this << " : RemoveSyncItem: No Item."; 352 DVLOG(2) << this << " : RemoveSyncItem: No Item.";
354 return; 353 return;
355 } 354 }
356 355
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 syncer::SyncChangeList change_list; 427 syncer::SyncChangeList change_list;
429 for (std::set<std::string>::iterator iter = unsynced_items.begin(); 428 for (std::set<std::string>::iterator iter = unsynced_items.begin();
430 iter != unsynced_items.end(); ++iter) { 429 iter != unsynced_items.end(); ++iter) {
431 SyncItem* sync_item = FindSyncItem(*iter); 430 SyncItem* sync_item = FindSyncItem(*iter);
432 DVLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString(); 431 DVLOG(2) << this << " -> SYNC ADD: " << sync_item->ToString();
433 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD, 432 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD,
434 GetSyncDataFromSyncItem(sync_item))); 433 GetSyncDataFromSyncItem(sync_item)));
435 } 434 }
436 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list); 435 sync_processor_->ProcessSyncChanges(FROM_HERE, change_list);
437 436
437 // Start observing app list model changes.
438 model_observer_.reset(new ModelObserver(this));
439
438 return result; 440 return result;
439 } 441 }
440 442
441 void AppListSyncableService::StopSyncing(syncer::ModelType type) { 443 void AppListSyncableService::StopSyncing(syncer::ModelType type) {
442 DCHECK_EQ(type, syncer::APP_LIST); 444 DCHECK_EQ(type, syncer::APP_LIST);
443 445
444 sync_processor_.reset(); 446 sync_processor_.reset();
445 sync_error_handler_.reset(); 447 sync_error_handler_.reset();
446 } 448 }
447 449
(...skipping 14 matching lines...) Expand all
462 syncer::SyncError AppListSyncableService::ProcessSyncChanges( 464 syncer::SyncError AppListSyncableService::ProcessSyncChanges(
463 const tracked_objects::Location& from_here, 465 const tracked_objects::Location& from_here,
464 const syncer::SyncChangeList& change_list) { 466 const syncer::SyncChangeList& change_list) {
465 if (!sync_processor_.get()) { 467 if (!sync_processor_.get()) {
466 return syncer::SyncError(FROM_HERE, 468 return syncer::SyncError(FROM_HERE,
467 syncer::SyncError::DATATYPE_ERROR, 469 syncer::SyncError::DATATYPE_ERROR,
468 "App List syncable service is not started.", 470 "App List syncable service is not started.",
469 syncer::APP_LIST); 471 syncer::APP_LIST);
470 } 472 }
471 473
474 // Don't observe the model while processing incoming sync changes.
475 model_observer_.reset();
476
472 DVLOG(1) << this << ": ProcessSyncChanges: " << change_list.size(); 477 DVLOG(1) << this << ": ProcessSyncChanges: " << change_list.size();
473 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); 478 for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
474 iter != change_list.end(); ++iter) { 479 iter != change_list.end(); ++iter) {
475 const SyncChange& change = *iter; 480 const SyncChange& change = *iter;
476 DVLOG(2) << this << " Change: " 481 DVLOG(2) << this << " Change: "
477 << change.sync_data().GetSpecifics().app_list().item_id() 482 << change.sync_data().GetSpecifics().app_list().item_id()
478 << " (" << change.change_type() << ")"; 483 << " (" << change.change_type() << ")";
479 if (change.change_type() == SyncChange::ACTION_ADD || 484 if (change.change_type() == SyncChange::ACTION_ADD ||
480 change.change_type() == SyncChange::ACTION_UPDATE) { 485 change.change_type() == SyncChange::ACTION_UPDATE) {
481 ProcessSyncItemSpecifics(change.sync_data().GetSpecifics().app_list()); 486 ProcessSyncItemSpecifics(change.sync_data().GetSpecifics().app_list());
482 } else if (change.change_type() == SyncChange::ACTION_DELETE) { 487 } else if (change.change_type() == SyncChange::ACTION_DELETE) {
483 DeleteSyncItemSpecifics(change.sync_data().GetSpecifics().app_list()); 488 DeleteSyncItemSpecifics(change.sync_data().GetSpecifics().app_list());
484 } else { 489 } else {
485 LOG(ERROR) << "Invalid sync change"; 490 LOG(ERROR) << "Invalid sync change";
486 } 491 }
487 } 492 }
493
494 // Continue observing app list model changes.
495 model_observer_.reset(new ModelObserver(this));
496
488 return syncer::SyncError(); 497 return syncer::SyncError();
489 } 498 }
490 499
491 // AppListSyncableService private 500 // AppListSyncableService private
492 501
493 bool AppListSyncableService::ProcessSyncItemSpecifics( 502 bool AppListSyncableService::ProcessSyncItemSpecifics(
494 const sync_pb::AppListSpecifics& specifics) { 503 const sync_pb::AppListSpecifics& specifics) {
495 const std::string& item_id = specifics.item_id(); 504 const std::string& item_id = specifics.item_id();
496 if (item_id.empty()) { 505 if (item_id.empty()) {
497 LOG(ERROR) << "AppList item with empty ID"; 506 LOG(ERROR) << "AppList item with empty ID";
498 return false; 507 return false;
499 } 508 }
500 SyncItem* sync_item = FindSyncItem(item_id); 509 SyncItem* sync_item = FindSyncItem(item_id);
501 if (sync_item) { 510 if (sync_item) {
502 // If an item of the same type exists, update it. 511 // If an item of the same type exists, update it.
503 if (sync_item->item_type == specifics.item_type()) { 512 if (sync_item->item_type == specifics.item_type()) {
504 UpdateSyncItemFromSync(specifics, sync_item); 513 UpdateSyncItemFromSync(specifics, sync_item);
505 ProcessExistingSyncItem(sync_item); 514 ProcessExistingSyncItem(sync_item);
506 DVLOG(2) << this << " <- SYNC UPDATE: " << sync_item->ToString(); 515 DVLOG(2) << this << " <- SYNC UPDATE: " << sync_item->ToString();
507 return false; 516 return false;
508 } 517 }
509 // Otherwise, one of the entries should be TYPE_REMOVE_DEFAULT_APP. 518 // Otherwise, one of the entries should be TYPE_REMOVE_DEFAULT_APP.
510 if (sync_item->item_type != 519 if (sync_item->item_type !=
511 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP && 520 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP &&
512 specifics.item_type() != 521 specifics.item_type() !=
513 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { 522 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) {
514 LOG(ERROR) << "Synced item type: " << specifics.item_type() 523 LOG(ERROR) << "Synced item type: " << specifics.item_type()
515 << " != existing sync item type: " << sync_item->item_type 524 << " != existing sync item type: " << sync_item->item_type
516 << " Deleting item from model!"; 525 << " Deleting item from model!";
517 model_->item_list()->DeleteItem(item_id); 526 model_->DeleteItem(item_id);
518 } 527 }
519 DVLOG(2) << this << " - ProcessSyncItem: Delete existing entry: " 528 DVLOG(2) << this << " - ProcessSyncItem: Delete existing entry: "
520 << sync_item->ToString(); 529 << sync_item->ToString();
521 delete sync_item; 530 delete sync_item;
522 sync_items_.erase(item_id); 531 sync_items_.erase(item_id);
523 } 532 }
524 533
525 sync_item = CreateSyncItem(item_id, specifics.item_type()); 534 sync_item = CreateSyncItem(item_id, specifics.item_type());
526 UpdateSyncItemFromSync(specifics, sync_item); 535 UpdateSyncItemFromSync(specifics, sync_item);
527 ProcessNewSyncItem(sync_item); 536 ProcessNewSyncItem(sync_item);
(...skipping 20 matching lines...) Expand all
548 // TODO(stevenjb): Implement 557 // TODO(stevenjb): Implement
549 LOG(WARNING) << "TYPE_FOLDER not supported"; 558 LOG(WARNING) << "TYPE_FOLDER not supported";
550 return; 559 return;
551 } 560 }
552 case sync_pb::AppListSpecifics::TYPE_URL: { 561 case sync_pb::AppListSpecifics::TYPE_URL: {
553 // TODO(stevenjb): Implement 562 // TODO(stevenjb): Implement
554 LOG(WARNING) << "TYPE_URL not supported"; 563 LOG(WARNING) << "TYPE_URL not supported";
555 return; 564 return;
556 } 565 }
557 } 566 }
558 NOTREACHED() << "Unrecoginized sync item type: " << sync_item->ToString(); 567 NOTREACHED() << "Unrecognized sync item type: " << sync_item->ToString();
559 } 568 }
560 569
561 void AppListSyncableService::ProcessExistingSyncItem(SyncItem* sync_item) { 570 void AppListSyncableService::ProcessExistingSyncItem(SyncItem* sync_item) {
562 if (sync_item->item_type == 571 if (sync_item->item_type ==
563 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { 572 sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) {
564 return; 573 return;
565 } 574 }
566 DVLOG(2) << "ProcessExistingSyncItem: " << sync_item->ToString(); 575 DVLOG(2) << "ProcessExistingSyncItem: " << sync_item->ToString();
567 AppListItem* app_item = model_->item_list()->FindItem(sync_item->item_id); 576 AppListItem* app_item = model_->FindItem(sync_item->item_id);
577 DVLOG(2) << " AppItem: " << app_item->ToDebugString();
568 if (!app_item) { 578 if (!app_item) {
569 LOG(ERROR) << "Item not found in model: " << sync_item->ToString(); 579 LOG(ERROR) << "Item not found in model: " << sync_item->ToString();
570 return; 580 return;
571 } 581 }
572 UpdateAppItemFromSyncItem(sync_item, app_item); 582 UpdateAppItemFromSyncItem(sync_item, app_item);
573 } 583 }
574 584
575 void AppListSyncableService::UpdateAppItemFromSyncItem( 585 void AppListSyncableService::UpdateAppItemFromSyncItem(
576 const AppListSyncableService::SyncItem* sync_item, 586 const AppListSyncableService::SyncItem* sync_item,
577 AppListItem* app_item) { 587 AppListItem* app_item) {
578 if (!app_item->position().Equals(sync_item->item_ordinal)) 588 if (!app_item->position().Equals(sync_item->item_ordinal))
579 model_->item_list()->SetItemPosition(app_item, sync_item->item_ordinal); 589 model_->SetItemPosition(app_item, sync_item->item_ordinal);
580 } 590 }
581 591
582 bool AppListSyncableService::SyncStarted() { 592 bool AppListSyncableService::SyncStarted() {
583 if (sync_processor_.get()) 593 if (sync_processor_.get())
584 return true; 594 return true;
585 if (flare_.is_null()) { 595 if (flare_.is_null()) {
586 DVLOG(2) << this << ": SyncStarted: Flare."; 596 DVLOG(2) << this << ": SyncStarted: Flare.";
587 flare_ = sync_start_util::GetFlareForSyncableService(profile_->GetPath()); 597 flare_ = sync_start_util::GetFlareForSyncableService(profile_->GetPath());
588 flare_.Run(syncer::APP_LIST); 598 flare_.Run(syncer::APP_LIST);
589 } 599 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 DVLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8); 646 DVLOG(2) << this << ": DeleteSyncItemSpecifics: " << item_id.substr(0, 8);
637 SyncItemMap::iterator iter = sync_items_.find(item_id); 647 SyncItemMap::iterator iter = sync_items_.find(item_id);
638 if (iter == sync_items_.end()) 648 if (iter == sync_items_.end())
639 return; 649 return;
640 sync_pb::AppListSpecifics::AppListItemType item_type = 650 sync_pb::AppListSpecifics::AppListItemType item_type =
641 iter->second->item_type; 651 iter->second->item_type;
642 DVLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString(); 652 DVLOG(2) << this << " <- SYNC DELETE: " << iter->second->ToString();
643 delete iter->second; 653 delete iter->second;
644 sync_items_.erase(iter); 654 sync_items_.erase(iter);
645 if (item_type != sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) 655 if (item_type != sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP)
646 model_->item_list()->DeleteItem(item_id); 656 model_->DeleteItem(item_id);
647 } 657 }
648 658
649 std::string AppListSyncableService::SyncItem::ToString() const { 659 std::string AppListSyncableService::SyncItem::ToString() const {
650 std::string res = item_id.substr(0, 8); 660 std::string res = item_id.substr(0, 8);
651 if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { 661 if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) {
652 res += " { RemoveDefault }"; 662 res += " { RemoveDefault }";
653 } else { 663 } else {
654 res += " { " + item_name + " }"; 664 res += " { " + item_name + " }";
655 res += " [" + item_ordinal.ToDebugString() + "]"; 665 res += " [" + item_ordinal.ToDebugString() + "]";
666 if (!parent_id.empty())
667 res += " <" + parent_id.substr(0, 8) + ">";
656 } 668 }
657 return res; 669 return res;
658 } 670 }
659 671
660 } // namespace app_list 672 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698