| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 prefs::kNoteTakingAppEnabledOnLockScreen)) { | 148 prefs::kNoteTakingAppEnabledOnLockScreen)) { |
| 149 info.lock_screen_support = NoteTakingLockScreenSupport::kSelected; | 149 info.lock_screen_support = NoteTakingLockScreenSupport::kSelected; |
| 150 } | 150 } |
| 151 break; | 151 break; |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 return infos; | 155 return infos; |
| 156 } | 156 } |
| 157 | 157 |
| 158 std::unique_ptr<NoteTakingAppInfo> NoteTakingHelper::GetPreferredChromeAppInfo( |
| 159 Profile* profile) { |
| 160 const std::string preferred_app_id = |
| 161 profile->GetPrefs()->GetString(prefs::kNoteTakingAppId); |
| 162 if (LooksLikeAndroidPackageName(preferred_app_id)) |
| 163 return nullptr; |
| 164 |
| 165 const extensions::Extension* preferred_app = |
| 166 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 167 preferred_app_id, extensions::ExtensionRegistry::ENABLED); |
| 168 if (!preferred_app) |
| 169 return nullptr; |
| 170 |
| 171 if (!IsWhitelistedChromeApp(preferred_app) && |
| 172 !extensions::ActionHandlersInfo::HasActionHandler( |
| 173 preferred_app, app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 174 return nullptr; |
| 175 } |
| 176 |
| 177 NoteTakingLockScreenSupport lock_screen_support = |
| 178 NoteTakingLockScreenSupport::kNotSupported; |
| 179 if (IsLockScreenEnabled(preferred_app)) { |
| 180 if (profile->GetPrefs()->GetBoolean( |
| 181 prefs::kNoteTakingAppEnabledOnLockScreen)) { |
| 182 lock_screen_support = NoteTakingLockScreenSupport::kSelected; |
| 183 } else { |
| 184 lock_screen_support = NoteTakingLockScreenSupport::kSupported; |
| 185 } |
| 186 } |
| 187 |
| 188 std::unique_ptr<NoteTakingAppInfo> info = |
| 189 base::MakeUnique<NoteTakingAppInfo>(); |
| 190 info->name = preferred_app->name(); |
| 191 info->app_id = preferred_app->id(); |
| 192 info->preferred = true; |
| 193 info->lock_screen_support = lock_screen_support; |
| 194 return info; |
| 195 } |
| 196 |
| 158 void NoteTakingHelper::SetPreferredApp(Profile* profile, | 197 void NoteTakingHelper::SetPreferredApp(Profile* profile, |
| 159 const std::string& app_id) { | 198 const std::string& app_id) { |
| 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 199 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 161 DCHECK(profile); | 200 DCHECK(profile); |
| 162 | 201 |
| 163 const extensions::Extension* app = | 202 const extensions::Extension* app = |
| 164 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 203 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 165 app_id, extensions::ExtensionRegistry::ENABLED); | 204 app_id, extensions::ExtensionRegistry::ENABLED); |
| 166 | 205 |
| 167 if (!app || !IsLockScreenEnabled(app)) { | 206 if (!app || !IsLockScreenEnabled(app)) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 for (auto& observer : observers_) | 505 for (auto& observer : observers_) |
| 467 observer.OnAvailableNoteTakingAppsUpdated(); | 506 observer.OnAvailableNoteTakingAppsUpdated(); |
| 468 } | 507 } |
| 469 } | 508 } |
| 470 | 509 |
| 471 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 510 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 472 extension_registry_observer_.Remove(registry); | 511 extension_registry_observer_.Remove(registry); |
| 473 } | 512 } |
| 474 | 513 |
| 475 } // namespace chromeos | 514 } // namespace chromeos |
| OLD | NEW |