| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (infos.empty()) | 179 if (infos.empty()) |
| 180 LOG(WARNING) << "Unable to launch note-taking app; none available"; | 180 LOG(WARNING) << "Unable to launch note-taking app; none available"; |
| 181 else | 181 else |
| 182 result = LaunchAppInternal(profile, infos[0].app_id, path); | 182 result = LaunchAppInternal(profile, infos[0].app_id, path); |
| 183 UMA_HISTOGRAM_ENUMERATION(kDefaultLaunchResultHistogramName, | 183 UMA_HISTOGRAM_ENUMERATION(kDefaultLaunchResultHistogramName, |
| 184 static_cast<int>(result), | 184 static_cast<int>(result), |
| 185 static_cast<int>(LaunchResult::MAX)); | 185 static_cast<int>(LaunchResult::MAX)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void NoteTakingHelper::OnIntentFiltersUpdated() { | 188 void NoteTakingHelper::OnIntentFiltersUpdated() { |
| 189 if (android_enabled_) | 189 if (play_store_enabled_) |
| 190 UpdateAndroidApps(); | 190 UpdateAndroidApps(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void NoteTakingHelper::OnArcPlayStoreEnabledChanged(bool enabled) { | 193 void NoteTakingHelper::OnArcPlayStoreEnabledChanged(bool enabled) { |
| 194 android_enabled_ = enabled; | 194 play_store_enabled_ = enabled; |
| 195 if (!enabled) { | 195 if (!enabled) { |
| 196 android_apps_.clear(); | 196 android_apps_.clear(); |
| 197 android_apps_received_ = false; | 197 android_apps_received_ = false; |
| 198 } | 198 } |
| 199 for (auto& observer : observers_) | 199 for (auto& observer : observers_) |
| 200 observer.OnAvailableNoteTakingAppsUpdated(); | 200 observer.OnAvailableNoteTakingAppsUpdated(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 NoteTakingHelper::NoteTakingHelper() | 203 NoteTakingHelper::NoteTakingHelper() |
| 204 : launch_chrome_app_callback_( | 204 : launch_chrome_app_callback_( |
| 205 base::Bind(&apps::LaunchPlatformAppWithAction)), | 205 base::Bind(&apps::LaunchPlatformAppWithAction)), |
| 206 extension_registry_observer_(this), | 206 extension_registry_observer_(this), |
| 207 weak_ptr_factory_(this) { | 207 weak_ptr_factory_(this) { |
| 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 209 | 209 |
| 210 const std::string switch_value = | 210 const std::string switch_value = |
| 211 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 211 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 212 switches::kNoteTakingAppIds); | 212 switches::kNoteTakingAppIds); |
| 213 if (!switch_value.empty()) { | 213 if (!switch_value.empty()) { |
| 214 whitelisted_chrome_app_ids_ = base::SplitString( | 214 whitelisted_chrome_app_ids_ = base::SplitString( |
| 215 switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 215 switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 216 } | 216 } |
| 217 whitelisted_chrome_app_ids_.insert(whitelisted_chrome_app_ids_.end(), | 217 whitelisted_chrome_app_ids_.insert(whitelisted_chrome_app_ids_.end(), |
| 218 kExtensionIds, | 218 kExtensionIds, |
| 219 kExtensionIds + arraysize(kExtensionIds)); | 219 kExtensionIds + arraysize(kExtensionIds)); |
| 220 | 220 |
| 221 // Track profiles so we can observe their extension registries. | 221 // Track profiles so we can observe their extension registries. |
| 222 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 222 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
| 223 content::NotificationService::AllBrowserContextsAndSources()); | 223 content::NotificationService::AllBrowserContextsAndSources()); |
| 224 android_enabled_ = false; | 224 play_store_enabled_ = false; |
| 225 for (Profile* profile : | 225 for (Profile* profile : |
| 226 g_browser_process->profile_manager()->GetLoadedProfiles()) { | 226 g_browser_process->profile_manager()->GetLoadedProfiles()) { |
| 227 extension_registry_observer_.Add( | 227 extension_registry_observer_.Add( |
| 228 extensions::ExtensionRegistry::Get(profile)); | 228 extensions::ExtensionRegistry::Get(profile)); |
| 229 // Check if the profile has already enabled Google Play Store. | 229 // Check if the profile has already enabled Google Play Store. |
| 230 // IsArcPlayStoreEnabledForProfile() can return true only for the primary | 230 // IsArcPlayStoreEnabledForProfile() can return true only for the primary |
| 231 // profile. | 231 // profile. |
| 232 android_enabled_ |= arc::IsArcPlayStoreEnabledForProfile(profile); | 232 play_store_enabled_ |= arc::IsArcPlayStoreEnabledForProfile(profile); |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Watch for changes of Google Play Store enabled state. | 235 // Watch for changes of Google Play Store enabled state. |
| 236 auto session_manager = arc::ArcSessionManager::Get(); | 236 auto session_manager = arc::ArcSessionManager::Get(); |
| 237 session_manager->AddObserver(this); | 237 session_manager->AddObserver(this); |
| 238 | 238 |
| 239 // ArcIntentHelperBridge will notify us about changes to the list of available | 239 // ArcIntentHelperBridge will notify us about changes to the list of available |
| 240 // Android apps. | 240 // Android apps. |
| 241 auto intent_helper_bridge = | 241 auto intent_helper_bridge = |
| 242 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); | 242 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); |
| 243 if (intent_helper_bridge) | 243 if (intent_helper_bridge) |
| 244 intent_helper_bridge->AddObserver(this); | 244 intent_helper_bridge->AddObserver(this); |
| 245 | 245 |
| 246 // If the ARC intent helper is ready, get the Android apps. Otherwise, | 246 // If the ARC intent helper is ready, get the Android apps. Otherwise, |
| 247 // UpdateAndroidApps() will be called when ArcServiceManager calls | 247 // UpdateAndroidApps() will be called when ArcServiceManager calls |
| 248 // OnIntentFiltersUpdated(). | 248 // OnIntentFiltersUpdated(). |
| 249 if (android_enabled_ && | 249 if (play_store_enabled_ && arc::ArcServiceManager::Get() |
| 250 arc::ArcServiceManager::Get() | 250 ->arc_bridge_service() |
| 251 ->arc_bridge_service() | 251 ->intent_helper() |
| 252 ->intent_helper() | 252 ->has_instance()) |
| 253 ->has_instance()) | |
| 254 UpdateAndroidApps(); | 253 UpdateAndroidApps(); |
| 255 } | 254 } |
| 256 | 255 |
| 257 NoteTakingHelper::~NoteTakingHelper() { | 256 NoteTakingHelper::~NoteTakingHelper() { |
| 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 257 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 259 | 258 |
| 260 // ArcSessionManagerTest shuts down ARC before NoteTakingHelper. | 259 // ArcSessionManagerTest shuts down ARC before NoteTakingHelper. |
| 261 auto intent_helper_bridge = | 260 auto intent_helper_bridge = |
| 262 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); | 261 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); |
| 263 if (intent_helper_bridge) | 262 if (intent_helper_bridge) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (!helper) | 310 if (!helper) |
| 312 return; | 311 return; |
| 313 helper->RequestIntentHandlerList( | 312 helper->RequestIntentHandlerList( |
| 314 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, | 313 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, |
| 315 weak_ptr_factory_.GetWeakPtr())); | 314 weak_ptr_factory_.GetWeakPtr())); |
| 316 } | 315 } |
| 317 | 316 |
| 318 void NoteTakingHelper::OnGotAndroidApps( | 317 void NoteTakingHelper::OnGotAndroidApps( |
| 319 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { | 318 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { |
| 320 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 319 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 321 if (!android_enabled_) | 320 if (!play_store_enabled_) |
| 322 return; | 321 return; |
| 323 | 322 |
| 324 android_apps_.clear(); | 323 android_apps_.clear(); |
| 325 android_apps_.reserve(handlers.size()); | 324 android_apps_.reserve(handlers.size()); |
| 326 for (const auto& it : handlers) { | 325 for (const auto& it : handlers) { |
| 327 android_apps_.emplace_back( | 326 android_apps_.emplace_back( |
| 328 NoteTakingAppInfo{it->name, it->package_name, false}); | 327 NoteTakingAppInfo{it->name, it->package_name, false}); |
| 329 } | 328 } |
| 330 android_apps_received_ = true; | 329 android_apps_received_ = true; |
| 331 | 330 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 for (auto& observer : observers_) | 417 for (auto& observer : observers_) |
| 419 observer.OnAvailableNoteTakingAppsUpdated(); | 418 observer.OnAvailableNoteTakingAppsUpdated(); |
| 420 } | 419 } |
| 421 } | 420 } |
| 422 | 421 |
| 423 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 422 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 424 extension_registry_observer_.Remove(registry); | 423 extension_registry_observer_.Remove(registry); |
| 425 } | 424 } |
| 426 | 425 |
| 427 } // namespace chromeos | 426 } // namespace chromeos |
| OLD | NEW |