| 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" |
| 11 #include "ash/common/system/chromeos/palette/palette_utils.h" | 11 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/chromeos/arc/arc_util.h" | 23 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 23 #include "chrome/browser/chromeos/file_manager/path_util.h" | 24 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 28 #include "components/arc/arc_bridge_service.h" | 29 #include "components/arc/arc_bridge_service.h" |
| 29 #include "components/arc/arc_service_manager.h" | 30 #include "components/arc/arc_service_manager.h" |
| 30 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 31 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
| 31 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 34 #include "extensions/browser/extension_registry.h" | 35 #include "extensions/browser/extension_registry.h" |
| 35 #include "extensions/common/api/app_runtime.h" | 36 #include "extensions/common/api/app_runtime.h" |
| 36 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 38 #include "extensions/common/manifest_handlers/action_handlers_handler.h" |
| 37 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 38 | 40 |
| 39 namespace app_runtime = extensions::api::app_runtime; | 41 namespace app_runtime = extensions::api::app_runtime; |
| 40 | 42 |
| 41 namespace chromeos { | 43 namespace chromeos { |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // Pointer to singleton instance. | 46 // Pointer to singleton instance. |
| 45 NoteTakingHelper* g_helper = nullptr; | 47 NoteTakingHelper* g_helper = nullptr; |
| 46 | 48 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); | 257 arc::ArcServiceManager::GetGlobalService<arc::ArcIntentHelperBridge>(); |
| 256 if (intent_helper_bridge) | 258 if (intent_helper_bridge) |
| 257 intent_helper_bridge->RemoveObserver(this); | 259 intent_helper_bridge->RemoveObserver(this); |
| 258 if (arc::ArcSessionManager::Get()) | 260 if (arc::ArcSessionManager::Get()) |
| 259 arc::ArcSessionManager::Get()->RemoveObserver(this); | 261 arc::ArcSessionManager::Get()->RemoveObserver(this); |
| 260 } | 262 } |
| 261 | 263 |
| 262 bool NoteTakingHelper::IsWhitelistedChromeApp( | 264 bool NoteTakingHelper::IsWhitelistedChromeApp( |
| 263 const extensions::Extension* extension) const { | 265 const extensions::Extension* extension) const { |
| 264 DCHECK(extension); | 266 DCHECK(extension); |
| 265 return std::find(whitelisted_chrome_app_ids_.begin(), | 267 return base::ContainsValue(whitelisted_chrome_app_ids_, extension->id()); |
| 266 whitelisted_chrome_app_ids_.end(), | |
| 267 extension->id()) != whitelisted_chrome_app_ids_.end(); | |
| 268 } | 268 } |
| 269 | 269 |
| 270 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( | 270 std::vector<const extensions::Extension*> NoteTakingHelper::GetChromeApps( |
| 271 Profile* profile) const { | 271 Profile* profile) const { |
| 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 273 const extensions::ExtensionRegistry* extension_registry = | 273 const extensions::ExtensionRegistry* extension_registry = |
| 274 extensions::ExtensionRegistry::Get(profile); | 274 extensions::ExtensionRegistry::Get(profile); |
| 275 const extensions::ExtensionSet& enabled_extensions = | 275 const extensions::ExtensionSet& enabled_extensions = |
| 276 extension_registry->enabled_extensions(); | 276 extension_registry->enabled_extensions(); |
| 277 | 277 |
| 278 // TODO(derat): Query for additional Chrome apps once http://crbug.com/657139 | |
| 279 // is resolved. | |
| 280 std::vector<const extensions::Extension*> extensions; | 278 std::vector<const extensions::Extension*> extensions; |
| 281 for (const auto& id : whitelisted_chrome_app_ids_) { | 279 for (const auto& id : whitelisted_chrome_app_ids_) { |
| 282 if (enabled_extensions.Contains(id)) { | 280 if (enabled_extensions.Contains(id)) { |
| 283 extensions.push_back(extension_registry->GetExtensionById( | 281 extensions.push_back(extension_registry->GetExtensionById( |
| 284 id, extensions::ExtensionRegistry::ENABLED)); | 282 id, extensions::ExtensionRegistry::ENABLED)); |
| 285 } | 283 } |
| 286 } | 284 } |
| 285 |
| 286 // Add any extensions which have a "note" action in their manifest |
| 287 // "action_handler" entry. |
| 288 for (const auto& extension : enabled_extensions) { |
| 289 if (base::ContainsValue(extensions, extension.get())) |
| 290 continue; |
| 291 |
| 292 if (extensions::ActionHandlersInfo::HasActionHandler( |
| 293 extension.get(), app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 294 extensions.push_back(extension.get()); |
| 295 } |
| 296 } |
| 297 |
| 287 return extensions; | 298 return extensions; |
| 288 } | 299 } |
| 289 | 300 |
| 290 void NoteTakingHelper::UpdateAndroidApps() { | 301 void NoteTakingHelper::UpdateAndroidApps() { |
| 291 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 302 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 292 auto* helper = ARC_GET_INSTANCE_FOR_METHOD( | 303 auto* helper = ARC_GET_INSTANCE_FOR_METHOD( |
| 293 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), | 304 arc::ArcServiceManager::Get()->arc_bridge_service()->intent_helper(), |
| 294 RequestIntentHandlerList); | 305 RequestIntentHandlerList); |
| 295 if (!helper) | 306 if (!helper) |
| 296 return; | 307 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); | 388 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); |
| 378 auto registry = extensions::ExtensionRegistry::Get( | 389 auto registry = extensions::ExtensionRegistry::Get( |
| 379 content::Source<Profile>(source).ptr()); | 390 content::Source<Profile>(source).ptr()); |
| 380 DCHECK(!extension_registry_observer_.IsObserving(registry)); | 391 DCHECK(!extension_registry_observer_.IsObserving(registry)); |
| 381 extension_registry_observer_.Add(registry); | 392 extension_registry_observer_.Add(registry); |
| 382 } | 393 } |
| 383 | 394 |
| 384 void NoteTakingHelper::OnExtensionLoaded( | 395 void NoteTakingHelper::OnExtensionLoaded( |
| 385 content::BrowserContext* browser_context, | 396 content::BrowserContext* browser_context, |
| 386 const extensions::Extension* extension) { | 397 const extensions::Extension* extension) { |
| 387 if (IsWhitelistedChromeApp(extension)) { | 398 if (IsWhitelistedChromeApp(extension) || |
| 399 extensions::ActionHandlersInfo::HasActionHandler( |
| 400 extension, app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 388 for (auto& observer : observers_) | 401 for (auto& observer : observers_) |
| 389 observer.OnAvailableNoteTakingAppsUpdated(); | 402 observer.OnAvailableNoteTakingAppsUpdated(); |
| 390 } | 403 } |
| 391 } | 404 } |
| 392 | 405 |
| 393 void NoteTakingHelper::OnExtensionUnloaded( | 406 void NoteTakingHelper::OnExtensionUnloaded( |
| 394 content::BrowserContext* browser_context, | 407 content::BrowserContext* browser_context, |
| 395 const extensions::Extension* extension, | 408 const extensions::Extension* extension, |
| 396 extensions::UnloadedExtensionInfo::Reason reason) { | 409 extensions::UnloadedExtensionInfo::Reason reason) { |
| 397 if (IsWhitelistedChromeApp(extension)) { | 410 if (IsWhitelistedChromeApp(extension) || |
| 411 extensions::ActionHandlersInfo::HasActionHandler( |
| 412 extension, app_runtime::ACTION_TYPE_NEW_NOTE)) { |
| 398 for (auto& observer : observers_) | 413 for (auto& observer : observers_) |
| 399 observer.OnAvailableNoteTakingAppsUpdated(); | 414 observer.OnAvailableNoteTakingAppsUpdated(); |
| 400 } | 415 } |
| 401 } | 416 } |
| 402 | 417 |
| 403 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { | 418 void NoteTakingHelper::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 404 extension_registry_observer_.Remove(registry); | 419 extension_registry_observer_.Remove(registry); |
| 405 } | 420 } |
| 406 | 421 |
| 407 } // namespace chromeos | 422 } // namespace chromeos |
| OLD | NEW |