| 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_( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 223 content::NotificationService::AllBrowserContextsAndSources()); | 223 content::NotificationService::AllBrowserContextsAndSources()); |
| 224 for (Profile* profile : | 224 for (Profile* profile : |
| 225 g_browser_process->profile_manager()->GetLoadedProfiles()) { | 225 g_browser_process->profile_manager()->GetLoadedProfiles()) { |
| 226 extension_registry_observer_.Add( | 226 extension_registry_observer_.Add( |
| 227 extensions::ExtensionRegistry::Get(profile)); | 227 extensions::ExtensionRegistry::Get(profile)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Check if the primary profile has already enabled ARC and watch for changes. | 230 // Check if the primary profile has already enabled ARC and watch for changes. |
| 231 auto session_manager = arc::ArcSessionManager::Get(); | 231 auto session_manager = arc::ArcSessionManager::Get(); |
| 232 session_manager->AddObserver(this); | 232 session_manager->AddObserver(this); |
| 233 android_enabled_ = session_manager->IsArcPlayStoreEnabled(); | 233 play_store_enabled_ = session_manager->IsArcPlayStoreEnabled(); |
| 234 | 234 |
| 235 // ArcIntentHelperBridge will notify us about changes to the list of available | 235 // ArcIntentHelperBridge will notify us about changes to the list of available |
| 236 // Android apps. | 236 // Android apps. |
| 237 auto intent_helper_bridge = | 237 auto intent_helper_bridge = |
| 238 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); | 238 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); |
| 239 if (intent_helper_bridge) | 239 if (intent_helper_bridge) |
| 240 intent_helper_bridge->AddObserver(this); | 240 intent_helper_bridge->AddObserver(this); |
| 241 | 241 |
| 242 // If the ARC intent helper is ready, get the Android apps. Otherwise, | 242 // If the ARC intent helper is ready, get the Android apps. Otherwise, |
| 243 // UpdateAndroidApps() will be called when ArcServiceManager calls | 243 // UpdateAndroidApps() will be called when ArcServiceManager calls |
| 244 // OnIntentFiltersUpdated(). | 244 // OnIntentFiltersUpdated(). |
| 245 if (android_enabled_ && | 245 if (play_store_enabled_ && |
| 246 arc::ArcServiceManager::Get() | 246 arc::ArcServiceManager::Get() |
| 247 ->arc_bridge_service() | 247 ->arc_bridge_service() |
| 248 ->intent_helper() | 248 ->intent_helper() |
| 249 ->has_instance()) | 249 ->has_instance()) |
| 250 UpdateAndroidApps(); | 250 UpdateAndroidApps(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 NoteTakingHelper::~NoteTakingHelper() { | 253 NoteTakingHelper::~NoteTakingHelper() { |
| 254 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 254 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 255 | 255 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 if (!helper) | 307 if (!helper) |
| 308 return; | 308 return; |
| 309 helper->RequestIntentHandlerList( | 309 helper->RequestIntentHandlerList( |
| 310 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, | 310 CreateIntentInfo(GURL()), base::Bind(&NoteTakingHelper::OnGotAndroidApps, |
| 311 weak_ptr_factory_.GetWeakPtr())); | 311 weak_ptr_factory_.GetWeakPtr())); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void NoteTakingHelper::OnGotAndroidApps( | 314 void NoteTakingHelper::OnGotAndroidApps( |
| 315 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { | 315 std::vector<arc::mojom::IntentHandlerInfoPtr> handlers) { |
| 316 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 316 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 317 if (!android_enabled_) | 317 if (!play_store_enabled_) |
| 318 return; | 318 return; |
| 319 | 319 |
| 320 android_apps_.clear(); | 320 android_apps_.clear(); |
| 321 android_apps_.reserve(handlers.size()); | 321 android_apps_.reserve(handlers.size()); |
| 322 for (const auto& it : handlers) { | 322 for (const auto& it : handlers) { |
| 323 android_apps_.emplace_back( | 323 android_apps_.emplace_back( |
| 324 NoteTakingAppInfo{it->name, it->package_name, false}); | 324 NoteTakingAppInfo{it->name, it->package_name, false}); |
| 325 } | 325 } |
| 326 android_apps_received_ = true; | 326 android_apps_received_ = true; |
| 327 | 327 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 for (auto& observer : observers_) | 414 for (auto& observer : observers_) |
| 415 observer.OnAvailableNoteTakingAppsUpdated(); | 415 observer.OnAvailableNoteTakingAppsUpdated(); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 419 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 420 extension_registry_observer_.Remove(registry); | 420 extension_registry_observer_.Remove(registry); |
| 421 } | 421 } |
| 422 | 422 |
| 423 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |