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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.cc

Issue 2090133003: Moved methods that don't rely on internal state out of ChromeLauncherController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed usage in unittests Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 "ash/accelerators/accelerator_controller.h"
8 #include "ash/shell.h"
9 #include "base/macros.h"
10 #include "build/build_config.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
14 #include "chrome/browser/ui/ash/ash_init.h"
15 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
16 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
18 #include "chrome/common/pref_names.h"
19 #include "components/prefs/scoped_user_pref_update.h"
20 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/extension.h"
22 #include "ui/aura/window_event_dispatcher.h"
23
24 #if defined(MOJO_SHELL_CLIENT)
25 #include "content/public/common/mojo_shell_connection.h"
26 #endif
27
28 namespace chrome {
29 namespace util {
30
31 bool IsBrowserFromActiveUser(Browser* browser) {
32 // If running multi user mode with separate desktops, we have to check if the
33 // browser is from the active user.
34 if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
35 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED)
36 return true;
37 return multi_user_util::IsProfileFromActiveUser(browser->profile());
38 }
39
40 const extensions::Extension* GetExtensionForAppID(Profile* profile,
41 const std::string& app_id) {
42 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
43 app_id, extensions::ExtensionRegistry::EVERYTHING);
44 }
45
46 AppListControllerDelegate::Pinnable GetPinnable(Profile* profile,
47 const std::string& app_id) {
48 const base::ListValue* pref =
49 profile->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
50 if (!pref)
51 return AppListControllerDelegate::PIN_EDITABLE;
52 // Pinned ARC apps policy defines the package name of the apps, that must
53 // be pinned. All the launch activities of any package in policy are pinned.
54 // In turn the input parameter to this function is app_id, which
55 // is 32 chars hash. In case of ARC app this is a hash of
56 // (package name + activity). This means that we must identify the package
57 // from the hash, and check if this package is pinned by policy.
58 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(profile);
59 std::string arc_app_packege_name;
60 if (arc_prefs) {
61 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
62 arc_prefs->GetApp(app_id);
63 if (app_info)
64 arc_app_packege_name = app_info->package_name;
65 }
66 for (size_t index = 0; index < pref->GetSize(); ++index) {
67 const base::DictionaryValue* app = nullptr;
68 std::string app_id_or_package;
69 if (pref->GetDictionary(index, &app) &&
70 app->GetString(ash::launcher::kPinnedAppsPrefAppIDPath,
71 &app_id_or_package) &&
72 (app_id == app_id_or_package ||
73 arc_app_packege_name == app_id_or_package)) {
74 return AppListControllerDelegate::PIN_FIXED;
75 }
76 }
77 return AppListControllerDelegate::PIN_EDITABLE;
78 }
79
80 } // namespace util
81 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698