Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_model_builder.cc |
| diff --git a/chrome/browser/ui/app_list/app_list_model_builder.cc b/chrome/browser/ui/app_list/app_list_model_builder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb84cfc198d4d05e8e120a63e417dad15261414c |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/app_list_model_builder.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/app_list/app_list_model_builder.h" |
| + |
| +#include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| +#include "ui/app_list/app_list_item.h" |
| +#include "ui/app_list/app_list_model.h" |
| + |
| +AppListModelBuilder::AppListModelBuilder(AppListControllerDelegate* controller, |
| + const char* item_type) |
| + : controller_(controller), |
| + item_type_(item_type) { |
| +} |
| + |
| +AppListModelBuilder::~AppListModelBuilder() { |
| + if (!service_) { |
|
jochen (gone - plz use gerrit)
2015/12/03 10:25:39
no {} for single line body
khmel1
2015/12/03 12:34:49
Done.
|
| + model_->top_level_item_list()->RemoveObserver(this); |
| + } |
| +} |
| + |
| +void AppListModelBuilder::InitializeWithService( |
| + app_list::AppListSyncableService* service, |
| + app_list::AppListModel* model) { |
| + DCHECK(!service_ && !profile_); |
| + model_ = model; |
| + service_ = service; |
| + profile_ = service->profile(); |
| + |
| + BuildModel(); |
| +} |
| + |
| +void AppListModelBuilder::InitializeWithProfile(Profile* profile, |
| + app_list::AppListModel* model) { |
| + DCHECK(!service_ && !profile_); |
| + model_ = model; |
| + model_->top_level_item_list()->AddObserver(this); |
| + profile_ = profile; |
| + |
| + BuildModel(); |
| +} |
| + |
| +void AppListModelBuilder::InsertApp(scoped_ptr<app_list::AppListItem> app) { |
| + if (service_) { |
| + service_->AddItem(app.Pass()); |
| + return; |
| + } |
| + model_->AddItem(app.Pass()); |
| +} |
| + |
| +const app_list::AppListSyncableService::SyncItem* |
| + AppListModelBuilder::GetSyncItem(const std::string& id) { |
| + return service_ ? service_->GetSyncItem(id) : nullptr; |
| +} |
| + |
| +app_list::AppListItem* AppListModelBuilder::GetAppItem(const std::string& id) { |
| + app_list::AppListItem* item = model_->FindItem(id); |
| + LOG_IF(ERROR, item && item->GetItemType() != item_type_) |
|
jochen (gone - plz use gerrit)
2015/12/03 10:25:39
VLOG() or DVLOG().
why are we returning the item
khmel1
2015/12/03 12:34:49
Good point. Return nullptr in this case
|
| + << "App Item matching id: " << id |
| + << " has incorrect type: '" << item->GetItemType() << "'"; |
| + return item; |
| +} |