OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/note_taking_helper.h" | 5 #include "chrome/browser/chromeos/note_taking_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "apps/launcher.h" | 10 #include "apps/launcher.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 prefs::kNoteTakingAppEnabledOnLockScreen)) { | 146 prefs::kNoteTakingAppEnabledOnLockScreen)) { |
147 info.lock_screen_support = NoteTakingLockScreenSupport::kSelected; | 147 info.lock_screen_support = NoteTakingLockScreenSupport::kSelected; |
148 } | 148 } |
149 break; | 149 break; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 return infos; | 153 return infos; |
154 } | 154 } |
155 | 155 |
| 156 std::unique_ptr<NoteTakingAppInfo> NoteTakingHelper::GetPreferredChromeAppInfo( |
| 157 Profile* profile) { |
| 158 const std::string preferred_app_id = |
| 159 profile->GetPrefs()->GetString(prefs::kNoteTakingAppId); |
| 160 if (LooksLikeAndroidPackageName(preferred_app_id)) |
| 161 return nullptr; |
| 162 |
| 163 const extensions::Extension* preferred_app = |
| 164 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 165 preferred_app_id, extensions::ExtensionRegistry::ENABLED); |
| 166 if (!preferred_app) |
| 167 return nullptr; |
| 168 |
| 169 if (!IsWhitelistedChromeApp(preferred_app) && |
| 170 !extensions::ActionHandlersInfo::HasActionHandler( |
| 171 preferred_app, app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 172 return nullptr; |
| 173 } |
| 174 |
| 175 NoteTakingLockScreenSupport lock_screen_support = |
| 176 NoteTakingLockScreenSupport::kNotSupported; |
| 177 if (IsLockScreenEnabled(preferred_app)) { |
| 178 if (profile->GetPrefs()->GetBoolean( |
| 179 prefs::kNoteTakingAppEnabledOnLockScreen)) { |
| 180 lock_screen_support = NoteTakingLockScreenSupport::kSelected; |
| 181 } else { |
| 182 lock_screen_support = NoteTakingLockScreenSupport::kSupported; |
| 183 } |
| 184 } |
| 185 |
| 186 std::unique_ptr<NoteTakingAppInfo> info = |
| 187 base::MakeUnique<NoteTakingAppInfo>(); |
| 188 info->name = preferred_app->name(); |
| 189 info->app_id = preferred_app->id(); |
| 190 info->preferred = true; |
| 191 info->lock_screen_support = lock_screen_support; |
| 192 return info; |
| 193 } |
| 194 |
156 void NoteTakingHelper::SetPreferredApp(Profile* profile, | 195 void NoteTakingHelper::SetPreferredApp(Profile* profile, |
157 const std::string& app_id) { | 196 const std::string& app_id) { |
158 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 197 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
159 DCHECK(profile); | 198 DCHECK(profile); |
160 | 199 |
161 const extensions::Extension* app = | 200 const extensions::Extension* app = |
162 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 201 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
163 app_id, extensions::ExtensionRegistry::ENABLED); | 202 app_id, extensions::ExtensionRegistry::ENABLED); |
164 | 203 |
165 if (!app || !IsLockScreenEnabled(app)) { | 204 if (!app || !IsLockScreenEnabled(app)) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 for (auto& observer : observers_) | 501 for (auto& observer : observers_) |
463 observer.OnAvailableNoteTakingAppsUpdated(); | 502 observer.OnAvailableNoteTakingAppsUpdated(); |
464 } | 503 } |
465 } | 504 } |
466 | 505 |
467 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 506 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
468 extension_registry_observer_.Remove(registry); | 507 extension_registry_observer_.Remove(registry); |
469 } | 508 } |
470 | 509 |
471 } // namespace chromeos | 510 } // namespace chromeos |
OLD | NEW |