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

Side by Side 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: nit: fix typo in header, rename test lib to test_support 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/app_list/arc_app_model_builder.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
9 #include "chrome/browser/ui/app_list/arc_app_item.h"
10 #include "ui/app_list/app_list_model.h"
11
12 ArcAppModelBuilder::ArcAppModelBuilder(AppListControllerDelegate* controller)
13 : controller_(controller) {
14 }
15
16 ArcAppModelBuilder::~ArcAppModelBuilder() {
17 prefs_->RemoveObserver(this);
18 }
19
20 void ArcAppModelBuilder::InitializeWithService(
Matt Giuca 2015/11/19 09:12:36 This is almost the same as ExtensionAppModelBuilde
khmel1 2015/11/19 17:11:42 Done.
21 app_list::AppListSyncableService* service,
22 app_list::AppListModel* model) {
23 DCHECK(!service_ && !profile_);
24 model_ = model;
25 service_ = service;
26 profile_ = service->profile();
27
28 BuildModel();
29 }
30
31 void ArcAppModelBuilder::InitializeWithProfile(Profile* profile,
32 app_list::AppListModel* model) {
Matt Giuca 2015/11/19 09:12:36 This is almost the same as ExtensionAppModelBuilde
khmel1 2015/11/19 17:11:42 Yes, need more explanation here. There are 2 possi
33 DCHECK(!service_ && !profile_);
34 model_ = model;
35 profile_ = profile;
36
37 BuildModel();
38 }
39
40 void ArcAppModelBuilder::BuildModel() {
41 prefs_ = ArcAppListPrefs::Get(profile_);
42
43 PopulateApps();
44 prefs_->AddObserver(this);
45 }
46
47 void ArcAppModelBuilder::PopulateApps() {
48 std::vector<std::string> app_ids = prefs_->GetAppIds();
49 for (auto& app_id : app_ids) {
50 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs_->GetApp(app_id);
51 if (!app_info) {
52 continue;
53 }
54 InsertApp(CreateApp(app_id, *app_info));
55 }
56 }
57
58 ArcAppItem* ArcAppModelBuilder::GetArcAppItem(const std::string& item_id) {
Matt Giuca 2015/11/19 09:12:36 This is almost the same as ExtensionAppModelBuilde
khmel1 2015/11/19 17:11:42 Refactored. BTW. Which error do you refer to?
59 app_list::AppListItem* item = model_->FindItem(item_id);
60 LOG_IF(ERROR, item &&
61 item->GetItemType() != ArcAppItem::kItemType)
62 << "App Item matching id: " << item_id
63 << " has incorrect type: '" << item->GetItemType() << "'";
64 return static_cast<ArcAppItem*>(item);
65 }
66
67 scoped_ptr<ArcAppItem> ArcAppModelBuilder::CreateApp(
68 const std::string& app_id,
69 const ArcAppListPrefs::AppInfo& app_info) {
70 const app_list::AppListSyncableService::SyncItem* sync_item =
71 service_ ? service_->GetSyncItem(app_id) : NULL;
72 scoped_ptr<ArcAppItem> app_item(new ArcAppItem(profile_,
73 sync_item,
74 app_id,
75 app_info.name,
76 app_info.ready));
77 return app_item;
78 }
79
80 void ArcAppModelBuilder::InsertApp(scoped_ptr<ArcAppItem> app) {
Matt Giuca 2015/11/19 09:12:36 This is exactly the same as ExtensionAppModelBuild
khmel1 2015/11/19 17:11:42 Done.
81 DCHECK(!GetArcAppItem(app->id()));
82 if (service_) {
83 service_->AddItem(app.Pass());
84 return;
85 }
86 model_->AddItem(app.Pass());
87 }
88
89 void ArcAppModelBuilder::OnAppRegistered(
90 const std::string& app_id,
91 const ArcAppListPrefs::AppInfo& app_info) {
92 InsertApp(CreateApp(app_id, app_info));
93 }
94
95 void ArcAppModelBuilder::OnAppReadyChanged(const std::string& app_id,
96 bool ready) {
97 ArcAppItem* app_item = GetArcAppItem(app_id);
98 if (!app_item) {
99 LOG(WARNING) << "Could not update the state of ARC app(" << app_id
100 << ") because it was not found.";
101 return;
102 }
103
104 app_item->SetReady(ready);
105 }
106
107 void ArcAppModelBuilder::OnAppIconUpdated(const std::string& app_id,
108 ui::ScaleFactor scale_factor) {
109 ArcAppItem* app_item = GetArcAppItem(app_id);
110 if (!app_item) {
111 LOG(WARNING) << "Could not update the icon of ARC app(" << app_id
112 << ") because it was not found.";
113 return;
114 }
115
116 // Initiate async icon reloading.
117 app_item->arc_app_icon()->LoadForScaleFactor(scale_factor);
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698