| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/ash/launcher/chrome_launcher_controller_util.h" |
| 6 |
| 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 9 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 11 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/pref_names.h" |
| 14 #include "components/prefs/pref_service.h" |
| 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/common/extension.h" |
| 17 |
| 18 bool IsBrowserFromActiveUser(Browser* browser) { |
| 19 // If running multi user mode with separate desktops, we have to check if the |
| 20 // browser is from the active user. |
| 21 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != |
| 22 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) |
| 23 return true; |
| 24 return multi_user_util::IsProfileFromActiveUser(browser->profile()); |
| 25 } |
| 26 |
| 27 const extensions::Extension* GetExtensionForAppID(const std::string& app_id, |
| 28 Profile* profile) { |
| 29 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 30 app_id, extensions::ExtensionRegistry::EVERYTHING); |
| 31 } |
| 32 |
| 33 AppListControllerDelegate::Pinnable GetPinnableForAppID( |
| 34 const std::string& app_id, |
| 35 Profile* profile) { |
| 36 const base::ListValue* pref = |
| 37 profile->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); |
| 38 if (!pref) |
| 39 return AppListControllerDelegate::PIN_EDITABLE; |
| 40 // Pinned ARC apps policy defines the package name of the apps, that must |
| 41 // be pinned. All the launch activities of any package in policy are pinned. |
| 42 // In turn the input parameter to this function is app_id, which |
| 43 // is 32 chars hash. In case of ARC app this is a hash of |
| 44 // (package name + activity). This means that we must identify the package |
| 45 // from the hash, and check if this package is pinned by policy. |
| 46 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(profile); |
| 47 std::string arc_app_packege_name; |
| 48 if (arc_prefs) { |
| 49 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 50 arc_prefs->GetApp(app_id); |
| 51 if (app_info) |
| 52 arc_app_packege_name = app_info->package_name; |
| 53 } |
| 54 for (size_t index = 0; index < pref->GetSize(); ++index) { |
| 55 const base::DictionaryValue* app = nullptr; |
| 56 std::string app_id_or_package; |
| 57 if (pref->GetDictionary(index, &app) && |
| 58 app->GetString(ash::launcher::kPinnedAppsPrefAppIDPath, |
| 59 &app_id_or_package) && |
| 60 (app_id == app_id_or_package || |
| 61 arc_app_packege_name == app_id_or_package)) { |
| 62 return AppListControllerDelegate::PIN_FIXED; |
| 63 } |
| 64 } |
| 65 return AppListControllerDelegate::PIN_EDITABLE; |
| 66 } |
| OLD | NEW |