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

Unified Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc

Issue 2055553004: arc: Support pinned apps across Arc-enabled and Arc-disabled platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, comments addressed, removed item_pinned_by_policy Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
index 9c034830bbd6210bb132226767c4617f35e505a4..2424b9c937390a5b7fda65b4655f2e37d6bcf01e 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
@@ -27,7 +27,6 @@
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/chromeos/arc/arc_support_host.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_app_icon_loader.h"
#include "chrome/browser/extensions/extension_util.h"
@@ -35,6 +34,7 @@
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
#include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
@@ -118,61 +118,6 @@ int64_t GetDisplayIDForShelf(ash::Shelf* shelf) {
return display.id();
}
-/*
- * Return whether an app is pinned only by user.
- * This function doesn't expect an app_id neither pinned by user nor by
- * policy, the app_id in the arguments list MUST be pinned by either of
- * those. Invalid input may lead to unexpected result.
- * If this app is pinned by policy, but not by user, false is returned.
- * If this app is pinned by both policy and user, false is returned.
- * If this app is pinned not by policy, but by user, true is returned.
- */
-bool IsAppForUserPinned(const std::string& app_id,
- const base::ListValue* pinned_apps_pref,
- const base::ListValue* policy_pinned_apps_pref) {
- for (size_t index = 0; index < pinned_apps_pref->GetSize(); ++index) {
- const base::DictionaryValue* app;
- if (pinned_apps_pref->GetDictionary(index, &app)) {
- std::string current_app_id;
- bool pinned_by_policy = false;
- if (app->GetString(ash::kPinnedAppsPrefAppIDPath, &current_app_id)) {
- if (app_id == current_app_id) {
- if (app->GetBoolean(ash::kPinnedAppsPrefPinnedByPolicy,
- &pinned_by_policy) &&
- pinned_by_policy) {
- // Pinned by policy in the past or present.
- // Need to check policy_pinned_apps to determine
- break;
- } else {
- // User Preference Already Pinned
- return true;
- }
- }
- }
- }
- }
- for (size_t index = 0; index < policy_pinned_apps_pref->GetSize(); ++index) {
- const base::DictionaryValue* app;
- if (policy_pinned_apps_pref->GetDictionary(index, &app)) {
- std::string app_id_;
- if (app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id_)) {
- // Only pinned by policy, which is not part of user-pinned
- if (app_id == app_id_)
- return false;
- }
- }
- }
- // Default, user added new pins
- return true;
-}
-
-const char* const kPinProhibitedExtensionIds[] = {
- ArcSupportHost::kHostAppId, arc::kPlayStoreAppId,
-};
-
-const size_t kPinProhibitedExtensionIdsLength =
- arraysize(kPinProhibitedExtensionIds);
-
} // namespace
// A class to get events from ChromeOS when a user gets changed or added.
@@ -247,11 +192,7 @@ void ChromeLauncherControllerUserSwitchObserver::AddUser(Profile* profile) {
ChromeLauncherController::ChromeLauncherController(Profile* profile,
ash::ShelfModel* model)
- : model_(model),
- item_delegate_manager_(NULL),
- profile_(profile),
- app_sync_ui_state_(NULL),
- ignore_persist_pinned_state_change_(false) {
+ : model_(model), profile_(profile) {
if (!profile_) {
// If no profile was passed, we take the currently active profile and use it
// as the owner of the current desktop.
@@ -376,7 +317,7 @@ void ChromeLauncherController::Init() {
SetVirtualKeyboardBehaviorFromPrefs();
prefs_observer_ =
- ash::ChromeLauncherPrefsObserver::CreateIfNecessary(profile_);
+ ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile_);
}
ash::ShelfID ChromeLauncherController::CreateAppLauncherItem(
@@ -439,11 +380,6 @@ void ChromeLauncherController::CloseLauncherItem(ash::ShelfID id) {
AppListControllerDelegate::Pinnable ChromeLauncherController::GetPinnable(
const std::string& app_id) {
- for (size_t i = 0; i < kPinProhibitedExtensionIdsLength; ++i) {
- if (kPinProhibitedExtensionIds[i] == app_id)
- return AppListControllerDelegate::NO_PIN;
- }
-
const base::ListValue* pref =
profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
if (!pref)
@@ -468,7 +404,8 @@ AppListControllerDelegate::Pinnable ChromeLauncherController::GetPinnable(
const base::DictionaryValue* app = nullptr;
std::string app_id_or_package;
if (pref->GetDictionary(index, &app) &&
- app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id_or_package) &&
+ app->GetString(ash::launcher::kPinnedAppsPrefAppIDPath,
+ &app_id_or_package) &&
(app_id == app_id_or_package ||
arc_app_packege_name == app_id_or_package)) {
return AppListControllerDelegate::PIN_FIXED;
@@ -493,14 +430,14 @@ void ChromeLauncherController::Pin(ash::ShelfID id) {
return;
}
- if (GetLauncherItemController(id)->CanPin())
- PersistPinnedState();
+ SyncPinPosition(id);
}
void ChromeLauncherController::Unpin(ash::ShelfID id) {
LauncherItemController* controller = GetLauncherItemController(id);
CHECK(controller);
- const bool can_pin = controller->CanPin();
+
+ ash::launcher::RemovePinPosition(profile_, GetAppIDForShelfID(id));
if (controller->type() == LauncherItemController::TYPE_APP ||
controller->locked()) {
@@ -508,8 +445,6 @@ void ChromeLauncherController::Unpin(ash::ShelfID id) {
} else {
LauncherItemClosed(id);
}
- if (can_pin)
- PersistPinnedState();
}
bool ChromeLauncherController::IsPinned(ash::ShelfID id) {
@@ -747,62 +682,6 @@ void ChromeLauncherController::OnSetShelfItemDelegate(
id_to_item_controller_map_.erase(iter);
}
-void ChromeLauncherController::PersistPinnedState() {
- if (ignore_persist_pinned_state_change_)
- return;
- // It is a coding error to call PersistPinnedState() if the pinned apps are
- // not user-editable. The code should check earlier and not perform any
- // modification actions that trigger persisting the state.
- // Mutating kPinnedLauncherApps is going to notify us and trigger us to
- // process the change. We don't want that to happen so remove ourselves as a
- // listener.
- pref_change_registrar_.Remove(prefs::kPinnedLauncherApps);
- {
- std::unique_ptr<const base::ListValue> pinned_apps_pref =
- profile_->GetPrefs()
- ->GetList(prefs::kPinnedLauncherApps)
- ->CreateDeepCopy();
-
- const base::ListValue* policy_pinned_apps_pref =
- profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
-
- ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
- updater->Clear();
- for (size_t i = 0; i < model_->items().size(); ++i) {
- if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) {
- ash::ShelfID id = model_->items()[i].id;
- LauncherItemController* controller = GetLauncherItemController(id);
- // Don't persist pinning state for apps that are handled internally and
- // have pinnable state AppListControllerDelegate::NO_PIN.
- if (controller && IsPinned(id) &&
- GetPinnable(controller->app_id()) !=
- AppListControllerDelegate::NO_PIN) {
- base::DictionaryValue* app_value = ash::CreateAppDict(
- controller->app_id());
- if (app_value) {
- if (!IsAppForUserPinned(controller->app_id(),
- pinned_apps_pref.get(),
- policy_pinned_apps_pref))
- app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true);
- updater->Append(app_value);
- }
- }
- } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) {
- PersistChromeItemIndex(i);
- } else if (model_->items()[i].type == ash::TYPE_APP_LIST) {
- base::DictionaryValue* app_value =
- ash::CreateAppDict(ash::kPinnedAppsPlaceholder);
- if (app_value)
- updater->Append(app_value);
- }
- }
- }
- pref_change_registrar_.Add(
- prefs::kPinnedLauncherApps,
- base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
- base::Unretained(this)));
-}
-
Profile* ChromeLauncherController::profile() {
return profile_;
}
@@ -926,24 +805,25 @@ void ChromeLauncherController::OnShelfCreated(ash::Shelf* shelf) {
PrefService* prefs = profile_->GetPrefs();
const int64_t display = GetDisplayIDForShelf(shelf);
- shelf->SetAutoHideBehavior(ash::GetShelfAutoHideBehaviorPref(prefs, display));
+ shelf->SetAutoHideBehavior(
+ ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display));
if (ash::ShelfWidget::ShelfAlignmentAllowed())
- shelf->SetAlignment(ash::GetShelfAlignmentPref(prefs, display));
+ shelf->SetAlignment(ash::launcher::GetShelfAlignmentPref(prefs, display));
}
void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) {}
void ChromeLauncherController::OnShelfAlignmentChanged(ash::Shelf* shelf) {
- ash::SetShelfAlignmentPref(profile_->GetPrefs(), GetDisplayIDForShelf(shelf),
- shelf->alignment());
+ ash::launcher::SetShelfAlignmentPref(
+ profile_->GetPrefs(), GetDisplayIDForShelf(shelf), shelf->alignment());
}
void ChromeLauncherController::OnShelfAutoHideBehaviorChanged(
ash::Shelf* shelf) {
- ash::SetShelfAutoHideBehaviorPref(profile_->GetPrefs(),
- GetDisplayIDForShelf(shelf),
- shelf->auto_hide_behavior());
+ ash::launcher::SetShelfAutoHideBehaviorPref(profile_->GetPrefs(),
+ GetDisplayIDForShelf(shelf),
+ shelf->auto_hide_behavior());
}
void ChromeLauncherController::OnShelfAutoHideStateChanged(ash::Shelf* shelf) {}
@@ -952,11 +832,6 @@ void ChromeLauncherController::OnShelfVisibilityStateChanged(
ash::Shelf* shelf) {}
void ChromeLauncherController::ShelfItemAdded(int index) {
- // The app list launcher can get added to the shelf after we applied the
- // preferences. In that case the item might be at the wrong spot. As such we
- // call the function again.
- if (model_->items()[index].type == ash::TYPE_APP_LIST)
- UpdateAppLaunchersFromPref();
}
void ChromeLauncherController::ShelfItemRemoved(int index, ash::ShelfID id) {
@@ -976,9 +851,9 @@ void ChromeLauncherController::ShelfItemMoved(int start_index,
const ash::ShelfItem& item = model_->items()[target_index];
// We remember the moved item position if it is either pinnable or
// it is the app list with the alternate shelf layout.
- if ((HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) ||
- item.type == ash::TYPE_APP_LIST)
- PersistPinnedState();
+ DCHECK_NE(ash::TYPE_APP_LIST, item.type);
+ if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id))
+ SyncPinPosition(item.id);
}
void ChromeLauncherController::ShelfItemChanged(
@@ -1295,14 +1170,16 @@ bool ChromeLauncherController::ShelfBoundsChangesProbablyWithUser(
PrefService* prefs = profile_->GetPrefs();
PrefService* other_prefs = other_profile->GetPrefs();
const int64_t display = GetDisplayIDForShelf(shelf);
- bool currently_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
- ash::GetShelfAutoHideBehaviorPref(prefs, display);
- bool other_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
- ash::GetShelfAutoHideBehaviorPref(other_prefs, display);
+ bool currently_shown =
+ ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
+ ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display);
+ bool other_shown =
+ ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
+ ash::launcher::GetShelfAutoHideBehaviorPref(other_prefs, display);
return currently_shown != other_shown ||
- ash::GetShelfAlignmentPref(prefs, display) !=
- ash::GetShelfAlignmentPref(other_prefs, display);
+ ash::launcher::GetShelfAlignmentPref(prefs, display) !=
+ ash::launcher::GetShelfAlignmentPref(other_prefs, display);
}
void ChromeLauncherController::OnUserProfileReadyToSwitch(Profile* profile) {
@@ -1338,8 +1215,7 @@ void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) {
} else {
// Otherwise, create a shortcut item for it.
shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count());
- if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
- PersistPinnedState();
+ SyncPinPosition(shelf_id);
}
}
@@ -1380,25 +1256,69 @@ void ChromeLauncherController::UnpinRunningAppInternal(int index) {
model_->Set(index, item);
}
+void ChromeLauncherController::SyncPinPosition(ash::ShelfID shelf_id) {
+ DCHECK(shelf_id);
+ if (ignore_persist_pinned_state_change_)
+ return;
+
+ const int max_index = model_->item_count();
+ const int index = model_->ItemIndexByID(shelf_id);
+ DCHECK_GT(index, 0);
+
+ const std::string& app_id = GetAppIDForShelfID(shelf_id);
+ DCHECK(!app_id.empty());
+
+ std::string app_id_before;
+ std::string app_id_after;
+
+ for (int i = index - 1; i > 0; --i) {
+ const ash::ShelfID shelf_id_before = model_->items()[i].id;
+ if (IsPinned(shelf_id_before)) {
+ app_id_before = GetAppIDForShelfID(shelf_id_before);
+ DCHECK(!app_id_before.empty());
+ break;
+ }
+ }
+
+ for (int i = index + 1; i < max_index; ++i) {
+ const ash::ShelfID shelf_id_after = model_->items()[i].id;
+ if (IsPinned(shelf_id_after)) {
+ app_id_after = GetAppIDForShelfID(shelf_id_after);
+ DCHECK(!app_id_after.empty());
+ break;
+ }
+ }
+
+ ash::launcher::SetPinPosition(profile_, app_id, app_id_before, app_id_after);
+}
+
+void ChromeLauncherController::OnSyncModelUpdated() {
+ UpdateAppLaunchersFromPref();
+}
+
void ChromeLauncherController::UpdateAppLaunchersFromPref() {
- // There are various functions which will trigger a |PersistPinnedState| call
- // like a direct call to |DoPinAppWithID|, or an indirect call to the menu
- // model which will use weights to re-arrange the icons to new positions.
+ // There are various functions which will trigger a |SyncPinPosition| call
+ // like a direct call to |DoPinAppWithID|, or an indirect call to the
+ // menu model which will use weights to re-arrange the icons to new positions.
// Since this function is meant to synchronize the "is state" with the
// "sync state", it makes no sense to store any changes by this function back
// into the pref state. Therefore we tell |persistPinnedState| to ignore any
// invocations while we are running.
base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
- std::vector<std::string> pinned_apps = ash::GetPinnedAppsFromPrefs(
+
+ std::vector<std::string> pinned_apps = ash::launcher::GetPinnedAppsFromPrefs(
profile_->GetPrefs(), launcher_controller_helper_.get());
int index = 0;
int max_index = model_->item_count();
+ int seen_chrome_index = -1;
+
+ // At least chrome browser shortcut should exist.
+ DCHECK_GT(max_index, 0);
- // When one of the two special items cannot be moved (and we do not know where
- // yet), we remember the current location in one of these variables.
- int chrome_index = -1;
- int app_list_index = -1;
+ // Skip app list items if it exists.
+ if (model_->items()[0].type == ash::TYPE_APP_LIST)
+ ++index;
// Walk the model and |pinned_apps| from the pref lockstep, adding and
// removing items as necessary. NB: This code uses plain old indexing instead
@@ -1406,53 +1326,40 @@ void ChromeLauncherController::UpdateAppLaunchersFromPref() {
std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin());
for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) {
// Check if we have an item which we need to handle.
- if (*pref_app_id == extension_misc::kChromeAppId ||
- *pref_app_id == ash::kPinnedAppsPlaceholder ||
- IsAppPinned(*pref_app_id)) {
+ if (IsAppPinned(*pref_app_id)) {
+ if (seen_chrome_index >= 0 &&
+ *pref_app_id == extension_misc::kChromeAppId) {
+ // Current item is Chrome browser and we saw it before.
+ model_->Move(seen_chrome_index, index);
+ ++pref_app_id;
+ --index;
+ continue;
+ }
for (; index < max_index; ++index) {
const ash::ShelfItem& item(model_->items()[index]);
- bool is_app_list = item.type == ash::TYPE_APP_LIST;
- bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT;
- if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome)
+ if (item.type != ash::TYPE_APP_SHORTCUT &&
+ item.type != ash::TYPE_BROWSER_SHORTCUT)
continue;
LauncherItemController* controller = GetLauncherItemController(item.id);
- if ((ash::kPinnedAppsPlaceholder == *pref_app_id && is_app_list) ||
- (extension_misc::kChromeAppId == *pref_app_id && is_chrome) ||
- (controller && controller->app_id() == *pref_app_id)) {
- // Check if an item needs to be moved here.
- MoveChromeOrApplistToFinalPosition(
- is_chrome, is_app_list, index, &chrome_index, &app_list_index);
+ if (controller && controller->app_id() == *pref_app_id) {
++pref_app_id;
break;
+ } else if (item.type == ash::TYPE_BROWSER_SHORTCUT) {
+ // We cannot close browser shortcut. Remember its position.
+ seen_chrome_index = index;
} else {
- if (is_chrome || is_app_list) {
- // We cannot delete any of these shortcuts. As such we remember
- // their positions and move them later where they belong.
- if (is_chrome)
- chrome_index = index;
- else
- app_list_index = index;
- // And skip the item - or exit the loop if end is reached (note that
- // in that case we will reduce the index again by one and this only
- // compensates for it).
- if (index >= max_index - 1)
- break;
- ++index;
+ // Check if this is a platform or a windowed app.
+ if (item.type == ash::TYPE_APP_SHORTCUT && controller &&
+ (controller->locked() ||
+ controller->type() == LauncherItemController::TYPE_APP)) {
+ // Note: This will not change the amount of items (|max_index|).
+ // Even changes to the actual |index| due to item weighting
+ // changes should be fine.
+ UnpinRunningAppInternal(index);
} else {
- // Check if this is a platform or a windowed app.
- if (item.type == ash::TYPE_APP_SHORTCUT &&
- controller &&
- (controller->locked() ||
- controller->type() == LauncherItemController::TYPE_APP)) {
- // Note: This will not change the amount of items (|max_index|).
- // Even changes to the actual |index| due to item weighting
- // changes should be fine.
- UnpinRunningAppInternal(index);
- } else {
- if (controller)
- LauncherItemClosed(item.id);
- --max_index;
- }
+ if (controller)
+ LauncherItemClosed(item.id);
+ --max_index;
}
--index;
}
@@ -1490,39 +1397,23 @@ void ChromeLauncherController::UpdateAppLaunchersFromPref() {
}
}
} else {
- if (item.type == ash::TYPE_BROWSER_SHORTCUT)
- chrome_index = index;
- else if (item.type == ash::TYPE_APP_LIST)
- app_list_index = index;
++index;
}
}
// Append unprocessed items from the pref to the end of the model.
for (; pref_app_id != pinned_apps.end(); ++pref_app_id) {
- // All items but the chrome and / or app list shortcut needs to be added.
- bool is_chrome = *pref_app_id == extension_misc::kChromeAppId;
- bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder;
- // Coming here we know the next item which can be finalized, either the
- // chrome item or the app launcher. The final position is the end of the
- // list. The menu model will make sure that the item is grouped according
- // to its weight (which we do not know here).
- if (!is_chrome && !is_app_list) {
+ if (*pref_app_id == extension_misc::kChromeAppId) {
+ int target_index = FindInsertionPoint();
+ DCHECK(seen_chrome_index >= 0 && seen_chrome_index < target_index);
+ model_->Move(seen_chrome_index, target_index);
+ } else {
DoPinAppWithID(*pref_app_id);
- int target_index = FindInsertionPoint(false);
+ int target_index = FindInsertionPoint();
ash::ShelfID id = GetShelfIDForAppID(*pref_app_id);
int source_index = model_->ItemIndexByID(id);
if (source_index != target_index)
model_->Move(source_index, target_index);
-
- // Needed for the old layout - the weight might force it to be lower in
- // rank.
- if (app_list_index != -1 && target_index <= app_list_index)
- ++app_list_index;
- } else {
- int target_index = FindInsertionPoint(is_app_list);
- MoveChromeOrApplistToFinalPosition(
- is_chrome, is_app_list, target_index, &chrome_index, &app_list_index);
}
}
}
@@ -1531,7 +1422,7 @@ void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() {
for (auto* window : ash::Shell::GetAllRootWindows()) {
ash::Shelf* shelf = ash::Shelf::ForWindow(window);
if (shelf) {
- shelf->SetAutoHideBehavior(ash::GetShelfAutoHideBehaviorPref(
+ shelf->SetAutoHideBehavior(ash::launcher::GetShelfAutoHideBehaviorPref(
profile_->GetPrefs(), GetDisplayIDForShelf(shelf)));
}
}
@@ -1544,7 +1435,7 @@ void ChromeLauncherController::SetShelfAlignmentFromPrefs() {
for (auto* window : ash::Shell::GetAllRootWindows()) {
ash::Shelf* shelf = ash::Shelf::ForWindow(window);
if (shelf) {
- shelf->SetAlignment(ash::GetShelfAlignmentPref(
+ shelf->SetAlignment(ash::launcher::GetShelfAlignmentPref(
profile_->GetPrefs(), GetDisplayIDForShelf(shelf)));
}
}
@@ -1662,8 +1553,7 @@ ash::ShelfID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
ash::ShelfID id = model_->next_id();
- size_t index = GetChromeIconIndexForCreation();
- model_->AddAt(index, browser_shortcut);
+ model_->AddAt(0, browser_shortcut);
id_to_item_controller_map_[id] =
new BrowserShortcutLauncherItemController(this, model_);
id_to_item_controller_map_[id]->set_shelf_id(id);
@@ -1672,45 +1562,13 @@ ash::ShelfID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
return id;
}
-void ChromeLauncherController::PersistChromeItemIndex(int index) {
- profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
-}
-
-void ChromeLauncherController::MoveChromeOrApplistToFinalPosition(
- bool is_chrome,
- bool is_app_list,
- int target_index,
- int* chrome_index,
- int* app_list_index) {
- if (is_chrome && *chrome_index != -1) {
- model_->Move(*chrome_index, target_index);
- if (*app_list_index != -1 &&
- *chrome_index < *app_list_index &&
- target_index > *app_list_index)
- --(*app_list_index);
- *chrome_index = -1;
- } else if (is_app_list && *app_list_index != -1) {
- model_->Move(*app_list_index, target_index);
- if (*chrome_index != -1 &&
- *app_list_index < *chrome_index &&
- target_index > *chrome_index)
- --(*chrome_index);
- *app_list_index = -1;
- }
-}
-
-int ChromeLauncherController::FindInsertionPoint(bool is_app_list) {
- // Keeping this change small to backport to M33&32 (see crbug.com/329597).
- // TODO(skuhne): With the removal of the legacy shelf layout we should remove
- // the ability to move the app list item since this was never used. We should
- // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index.
- if (is_app_list)
- return 0;
+int ChromeLauncherController::FindInsertionPoint() {
+ DCHECK_GT(model_->item_count(), 0);
for (int i = model_->item_count() - 1; i > 0; --i) {
ash::ShelfItemType type = model_->items()[i].type;
+ DCHECK_NE(ash::TYPE_APP_LIST, type);
if (type == ash::TYPE_APP_SHORTCUT ||
- (is_app_list && type == ash::TYPE_APP_LIST) ||
type == ash::TYPE_BROWSER_SHORTCUT) {
return i;
}
@@ -1718,27 +1576,6 @@ int ChromeLauncherController::FindInsertionPoint(bool is_app_list) {
return 0;
}
-int ChromeLauncherController::GetChromeIconIndexForCreation() {
- // We get the list of pinned apps as they currently would get pinned.
- // Within this list the chrome icon will be the correct location.
- std::vector<std::string> pinned_apps = ash::GetPinnedAppsFromPrefs(
- profile_->GetPrefs(), launcher_controller_helper_.get());
-
- std::vector<std::string>::iterator it =
- std::find(pinned_apps.begin(),
- pinned_apps.end(),
- std::string(extension_misc::kChromeAppId));
- DCHECK(it != pinned_apps.end());
- int index = it - pinned_apps.begin();
-
- // We should do here a comparison between the is state and the "want to be"
- // state since some apps might be able to pin but are not yet. Instead - for
- // the time being we clamp against the amount of known items and wait for the
- // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since
- // the pinning will be done then.
- return std::min(model_->item_count(), index);
-}
-
bool ChromeLauncherController::IsIncognito(
const content::WebContents* web_contents) const {
const Profile* profile =
@@ -1811,10 +1648,6 @@ void ChromeLauncherController::AttachProfile(Profile* profile) {
pref_change_registrar_.Init(profile_->GetPrefs());
pref_change_registrar_.Add(
- prefs::kPinnedLauncherApps,
- base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
- base::Unretained(this)));
- pref_change_registrar_.Add(
prefs::kPolicyPinnedLauncherApps,
base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref,
base::Unretained(this)));
@@ -1845,6 +1678,11 @@ void ChromeLauncherController::AttachProfile(Profile* profile) {
new LauncherArcAppUpdater(this, profile_));
app_updaters_.push_back(std::move(arc_app_updater));
}
+
+ app_list::AppListSyncableService* app_service =
+ app_list::AppListSyncableServiceFactory::GetForProfile(profile_);
+ if (app_service)
+ app_service->AddObserverAndStart(this);
}
void ChromeLauncherController::ReleaseProfile() {
@@ -1856,6 +1694,11 @@ void ChromeLauncherController::ReleaseProfile() {
prefs_observer_.reset();
pref_change_registrar_.RemoveAll();
+
+ app_list::AppListSyncableService* app_service =
+ app_list::AppListSyncableServiceFactory::GetForProfile(profile_);
+ if (app_service)
+ app_service->RemoveObserver(this);
}
AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp(

Powered by Google App Engine
This is Rietveld 408576698