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

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

Issue 1921403002: Pin apps from prefs on the mash shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only include arc for cros. Created 4 years, 8 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 b81ad446cc5ab7b71d271dcb72e95bf4d121113e..53fbef5080e76a676ec398abd5dddb07e1ea45dc 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/ui/ash/app_sync_ui_state.h"
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h"
+#include "chrome/browser/ui/ash/launcher/app_tab_helper.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
@@ -117,11 +118,6 @@ ChromeLauncherController* ChromeLauncherController::instance_ = NULL;
namespace {
-// This will be used as placeholder in the list of the pinned applciatons.
-// Note that this is NOT a valid extension identifier so that pre M31 versions
-// will ignore it.
-const char kAppShelfIdPlaceholder[] = "AppShelfIDPlaceholder--------";
-
int64_t GetDisplayIDForShelf(ash::Shelf* shelf) {
aura::Window* root_window =
shelf->shelf_widget()->GetNativeWindow()->GetRootWindow();
@@ -203,25 +199,6 @@ bool IsAppForUserPinned(const std::string& app_id,
return true;
}
-void update_pinned_apps(const std::string& app_id,
- bool valid_for_current_user,
- std::vector<std::string>* pinned_apps,
- bool* chrome_icon_added,
- bool* app_list_icon_added) {
- if (app_id == extension_misc::kChromeAppId) {
- *chrome_icon_added = true;
- pinned_apps->push_back(extension_misc::kChromeAppId);
- } else if (app_id == kAppShelfIdPlaceholder) {
- *app_list_icon_added = true;
- pinned_apps->push_back(kAppShelfIdPlaceholder);
- } else if (valid_for_current_user) {
- // Note: In multi profile scenarios we only want to show pinnable apps
- // here which is correct. Running applications from the other users will
- // continue to run. So no need for multi profile modifications.
- pinned_apps->push_back(app_id);
- }
-}
-
} // namespace
#if defined(OS_CHROMEOS)
@@ -879,8 +856,8 @@ void ChromeLauncherController::PersistPinnedState() {
} 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(
- kAppShelfIdPlaceholder);
+ base::DictionaryValue* app_value =
+ ash::CreateAppDict(ash::kPinnedAppsPlaceholder);
if (app_value)
updater->Append(app_value);
}
@@ -1503,7 +1480,8 @@ void ChromeLauncherController::UpdateAppLaunchersFromPref() {
// 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 = GetListOfPinnedAppsAndBrowser();
+ std::vector<std::string> pinned_apps =
+ ash::GetPinnedAppsFromPrefs(profile_->GetPrefs(), app_tab_helper_.get());
int index = 0;
int max_index = model_->item_count();
@@ -1520,7 +1498,7 @@ void ChromeLauncherController::UpdateAppLaunchersFromPref() {
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 == kAppShelfIdPlaceholder ||
+ *pref_app_id == ash::kPinnedAppsPlaceholder ||
IsAppPinned(*pref_app_id)) {
for (; index < max_index; ++index) {
const ash::ShelfItem& item(model_->items()[index]);
@@ -1529,7 +1507,7 @@ void ChromeLauncherController::UpdateAppLaunchersFromPref() {
if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome)
continue;
LauncherItemController* controller = GetLauncherItemController(item.id);
- if ((kAppShelfIdPlaceholder == *pref_app_id && is_app_list) ||
+ 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.
@@ -1615,7 +1593,7 @@ void ChromeLauncherController::UpdateAppLaunchersFromPref() {
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 == kAppShelfIdPlaceholder;
+ 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
@@ -1790,14 +1768,6 @@ void ChromeLauncherController::PersistChromeItemIndex(int index) {
profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
}
-int ChromeLauncherController::GetChromeIconIndexFromPref() const {
- size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex);
- const base::ListValue* pinned_apps_pref =
- profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
- return std::max(static_cast<size_t>(0),
- std::min(pinned_apps_pref->GetSize(), index));
-}
-
void ChromeLauncherController::MoveChromeOrApplistToFinalPosition(
bool is_chrome,
bool is_app_list,
@@ -1843,7 +1813,8 @@ int ChromeLauncherController::FindInsertionPoint(bool is_app_list) {
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 = GetListOfPinnedAppsAndBrowser();
+ std::vector<std::string> pinned_apps =
+ ash::GetPinnedAppsFromPrefs(profile_->GetPrefs(), app_tab_helper_.get());
std::vector<std::string>::iterator it =
std::find(pinned_apps.begin(),
@@ -1860,88 +1831,6 @@ int ChromeLauncherController::GetChromeIconIndexForCreation() {
return std::min(model_->item_count(), index);
}
-std::vector<std::string>
-ChromeLauncherController::GetListOfPinnedAppsAndBrowser() {
- // Adding the app list item to the list of items requires that the ID is not
- // a valid and known ID for the extension system. The ID was constructed that
- // way - but just to make sure...
- DCHECK(!app_tab_helper_->IsValidIDForCurrentUser(kAppShelfIdPlaceholder));
-
- std::vector<std::string> pinned_apps;
-
- // Get the new incarnation of the list.
- const base::ListValue* pinned_apps_pref =
- profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
-
- const base::ListValue* policy_pinned_apps_pref =
- profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
-
- // Keep track of the addition of the chrome and the app list icon.
- bool chrome_icon_added = false;
- bool app_list_icon_added = false;
- size_t chrome_icon_index = GetChromeIconIndexFromPref();
-
- // See if the chrome string is already in the pinned list and remove it if
- // needed.
- base::Value* chrome_app = ash::CreateAppDict(extension_misc::kChromeAppId);
- if (chrome_app) {
- chrome_icon_added = pinned_apps_pref->Find(*chrome_app) !=
- pinned_apps_pref->end();
- delete chrome_app;
- }
-
- if (policy_pinned_apps_pref) {
- for (size_t index = 0; index < policy_pinned_apps_pref->GetSize();
- ++index) {
- const base::DictionaryValue* app = NULL;
- std::string app_id;
- if (policy_pinned_apps_pref->GetDictionary(index, &app) &&
- app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) &&
- (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) ==
- pinned_apps.end()))
- update_pinned_apps(
- app_id, app_tab_helper_->IsValidIDForCurrentUser(app_id),
- &pinned_apps, &chrome_icon_added, &app_list_icon_added);
- }
- }
-
- for (size_t index = 0; index < pinned_apps_pref->GetSize(); ++index) {
- // We need to position the chrome icon relative to it's place in the pinned
- // preference list - even if an item of that list isn't shown yet.
- if (index == chrome_icon_index && !chrome_icon_added) {
- pinned_apps.push_back(extension_misc::kChromeAppId);
- chrome_icon_added = true;
- }
- const base::DictionaryValue* app = NULL;
- std::string app_id;
- if (pinned_apps_pref->GetDictionary(index, &app) &&
- app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) &&
- (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) ==
- pinned_apps.end())) {
- bool pinned_by_policy;
- if (app->GetBoolean(ash::kPinnedAppsPrefPinnedByPolicy,
- &pinned_by_policy) &&
- pinned_by_policy) {
- continue;
- }
- update_pinned_apps(
- app_id, app_tab_helper_->IsValidIDForCurrentUser(app_id),
- &pinned_apps, &chrome_icon_added, &app_list_icon_added);
- }
- }
-
- // If not added yet, the chrome item will be the last item in the list.
- if (!chrome_icon_added)
- pinned_apps.push_back(extension_misc::kChromeAppId);
-
- // If not added yet, add the app list item either at the end or at the
- // beginning - depending on the shelf layout.
- if (!app_list_icon_added) {
- pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder);
- }
- return pinned_apps;
-}
-
bool ChromeLauncherController::IsIncognito(
const content::WebContents* web_contents) const {
const Profile* profile =
@@ -1995,7 +1884,7 @@ void ChromeLauncherController::AttachProfile(Profile* profile) {
else
app_tab_helper_->SetCurrentUser(profile_);
// TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
- // image is associated with a profile (it's loader requires the profile).
+ // image is associated with a profile (its loader requires the profile).
// Since icon size changes are possible, the icon could be requested to be
// reloaded. However - having it not multi profile aware would cause problems
// if the icon cache gets deleted upon user switch.

Powered by Google App Engine
This is Rietveld 408576698