| 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_app_utils.h" | 5 #include "chrome/browser/chromeos/note_taking_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 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/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chromeos/chromeos_switches.h" | 17 #include "chromeos/chromeos_switches.h" |
| 18 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/common/api/app_runtime.h" | 19 #include "extensions/common/api/app_runtime.h" |
| 20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace app_runtime = extensions::api::app_runtime; | 23 namespace app_runtime = extensions::api::app_runtime; |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Pointer to singleton instance. |
| 29 NoteTakingHelper* g_helper = nullptr; |
| 30 |
| 28 // TODO(derat): Add more IDs. | 31 // TODO(derat): Add more IDs. |
| 29 const char* const kExtensionIds[] = { | 32 const char* const kExtensionIds[] = { |
| 30 // TODO(jdufault): Remove testing version after m54. See crbug.com/640828. | 33 // TODO(jdufault): Remove testing version after m54. See crbug.com/640828. |
| 31 "ogfjaccbdfhecploibfbhighmebiffla", // Testing Keep app | 34 "ogfjaccbdfhecploibfbhighmebiffla", // Testing Keep app |
| 32 "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store) | 35 "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store) |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 // Returns the first installed and enabled whitelisted note-taking app, or null | 38 // Returns the first installed and enabled whitelisted note-taking app, or null |
| 36 // if none is installed. | 39 // if none is installed. |
| 37 const extensions::Extension* GetApp(Profile* profile) { | 40 const extensions::Extension* GetApp(Profile* profile) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 60 if (enabled_extensions.Contains(id)) { | 63 if (enabled_extensions.Contains(id)) { |
| 61 return extension_registry->GetExtensionById( | 64 return extension_registry->GetExtensionById( |
| 62 id, extensions::ExtensionRegistry::ENABLED); | 65 id, extensions::ExtensionRegistry::ENABLED); |
| 63 } | 66 } |
| 64 } | 67 } |
| 65 return nullptr; | 68 return nullptr; |
| 66 } | 69 } |
| 67 | 70 |
| 68 } // namespace | 71 } // namespace |
| 69 | 72 |
| 70 bool IsNoteTakingAppAvailable(Profile* profile) { | 73 // static |
| 74 void NoteTakingHelper::Initialize() { |
| 75 DCHECK(!g_helper); |
| 76 g_helper = new NoteTakingHelper(); |
| 77 } |
| 78 |
| 79 // static |
| 80 void NoteTakingHelper::Shutdown() { |
| 81 DCHECK(g_helper); |
| 82 delete g_helper; |
| 83 g_helper = nullptr; |
| 84 } |
| 85 |
| 86 // static |
| 87 NoteTakingHelper* NoteTakingHelper::Get() { |
| 88 DCHECK(g_helper); |
| 89 return g_helper; |
| 90 } |
| 91 |
| 92 bool NoteTakingHelper::IsAppAvailable(Profile* profile) { |
| 71 DCHECK(profile); | 93 DCHECK(profile); |
| 72 return ash::IsPaletteFeatureEnabled() && GetApp(profile); | 94 return ash::IsPaletteFeatureEnabled() && GetApp(profile); |
| 73 } | 95 } |
| 74 | 96 |
| 75 void LaunchNoteTakingAppForNewNote(Profile* profile, | 97 void NoteTakingHelper::LaunchAppForNewNote(Profile* profile, |
| 76 const base::FilePath& path) { | 98 const base::FilePath& path) { |
| 77 DCHECK(profile); | 99 DCHECK(profile); |
| 78 const extensions::Extension* app = GetApp(profile); | 100 const extensions::Extension* app = GetApp(profile); |
| 79 if (!app) { | 101 if (!app) { |
| 80 LOG(ERROR) << "Failed to find note-taking app"; | 102 LOG(ERROR) << "Failed to find note-taking app"; |
| 81 return; | 103 return; |
| 82 } | 104 } |
| 83 | 105 |
| 84 auto action_data = base::MakeUnique<app_runtime::ActionData>(); | 106 auto action_data = base::MakeUnique<app_runtime::ActionData>(); |
| 85 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; | 107 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; |
| 86 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path); | 108 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path); |
| 87 } | 109 } |
| 88 | 110 |
| 111 NoteTakingHelper::NoteTakingHelper() {} |
| 112 |
| 113 NoteTakingHelper::~NoteTakingHelper() {} |
| 114 |
| 89 } // namespace chromeos | 115 } // namespace chromeos |
| OLD | NEW |