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

Unified Diff: chrome/browser/ui/app_list/arc_app_model_builder.cc

Issue 1413153007: arc-app-launcher: Minimal support for ARC app launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch to new IPC Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/arc_app_model_builder.cc
diff --git a/chrome/browser/ui/app_list/arc_app_model_builder.cc b/chrome/browser/ui/app_list/arc_app_model_builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e9ea82f0c5dca1691d2cd48704b06bcd62eb7d94
--- /dev/null
+++ b/chrome/browser/ui/app_list/arc_app_model_builder.cc
@@ -0,0 +1,121 @@
+// Copyright (c) 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/arc_app_model_builder.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
+#include "chrome/browser/ui/app_list/arc_app_item.h"
+#include "ui/app_list/app_list_model.h"
+
+ArcAppModelBuilder::ArcAppModelBuilder(AppListControllerDelegate* controller)
+ : profile_(NULL),
xiyuan 2015/11/11 22:15:50 nit: Use in-class member initialization and use nu
khmel1 2015/11/12 08:05:30 Done.
+ prefs_(NULL),
+ controller_(controller),
+ model_(NULL),
+ service_(NULL) {
+}
+
+ArcAppModelBuilder::~ArcAppModelBuilder() {
+ prefs_->RemoveObserver(this);
xiyuan 2015/11/11 22:15:50 Think we need to make AppListSyncableService depen
khmel1 2015/11/12 08:05:30 Done.
+}
+
+void ArcAppModelBuilder::InitializeWithService(
+ app_list::AppListSyncableService* service,
+ app_list::AppListModel* model) {
+ DCHECK(!service_ && !profile_);
+ model_ = model;
+ service_ = service;
+ profile_ = service->profile();
+
+ BuildModel();
+}
+
+void ArcAppModelBuilder::InitializeWithProfile(Profile* profile,
+ app_list::AppListModel* model) {
+ DCHECK(!service_ && !profile_);
+ model_ = model;
+ profile_ = profile;
+
+ BuildModel();
+}
+
+void ArcAppModelBuilder::BuildModel() {
+ prefs_ = ArcAppPrefs::Get(profile_);
+
+ PopulateApps();
+ prefs_->AddObserver(this);
+}
+
+void ArcAppModelBuilder::PopulateApps() {
+ std::vector<std::string> app_ids = prefs_->GetAppIds();
xiyuan 2015/11/11 22:15:50 nit: #include <vector>
khmel1 2015/11/12 08:05:30 Done.
+ for (size_t i = 0; i < app_ids.size(); ++i) {
+ const std::string app_id = app_ids[i];
+ scoped_ptr<ArcAppPrefs::AppInfo> app_info = prefs_->GetApp(app_id);
+ if (!app_info) {
+ continue;
+ }
+ InsertApp(CreateApp(app_id, *app_info));
+ }
+}
+
+ArcAppItem* ArcAppModelBuilder::GetArcAppItem(const std::string& item_id) {
+ app_list::AppListItem* item = model_->FindItem(item_id);
+ LOG_IF(ERROR, item &&
+ item->GetItemType() != ArcAppItem::kItemType)
+ << "App Item matching id: " << item_id
+ << " has incorrect type: '" << item->GetItemType() << "'";
+ return static_cast<ArcAppItem*>(item);
+}
+
+scoped_ptr<ArcAppItem> ArcAppModelBuilder::CreateApp(
+ const std::string& app_id,
+ const ArcAppPrefs::AppInfo& app_info) {
+ const app_list::AppListSyncableService::SyncItem* sync_item =
+ service_ ? service_->GetSyncItem(app_id) : NULL;
+ scoped_ptr<ArcAppItem> app_item(new ArcAppItem(profile_,
+ sync_item,
+ app_id,
+ app_info.name,
+ app_info.ready));
+ return app_item;
+}
+
+void ArcAppModelBuilder::InsertApp(scoped_ptr<ArcAppItem> app) {
+ DCHECK(!GetArcAppItem(app->id()));
+ if (service_) {
+ service_->AddItem(app.Pass());
+ return;
+ }
+ model_->AddItem(app.Pass());
+}
+
+void ArcAppModelBuilder::OnAppRegistered(const std::string& app_id,
+ const ArcAppPrefs::AppInfo& app_info) {
+ InsertApp(CreateApp(app_id, app_info));
+}
+
+void ArcAppModelBuilder::OnAppReady(const std::string& app_id, bool ready) {
+ ArcAppItem* app_item = GetArcAppItem(app_id);
+ if (!app_item) {
+ LOG(WARNING) << "Could not update the state of arc app(" << app_id
+ << ") because it was not found.";
+ return;
+ }
+
+ app_item->SetReady(ready);
+}
+
+void ArcAppModelBuilder::OnAppIconUpdated(const std::string& app_id,
+ ui::ScaleFactor scale_factor) {
+ ArcAppItem* app_item = GetArcAppItem(app_id);
+ if (!app_item) {
+ LOG(WARNING) << "Could not update the icon of arc app(" << app_id
+ << ") because it was not found.";
+ return;
+ }
+
+ // Initiate async icon reloading.
+ app_item->icon()->LoadForScaleFactor(scale_factor);
+}

Powered by Google App Engine
This is Rietveld 408576698