Chromium Code Reviews| 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_app_utils.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/app_window/app_window.h" | |
| 18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/common/api/app_runtime.h" | 20 #include "extensions/common/api/app_runtime.h" |
| 20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace app_runtime = extensions::api::app_runtime; | 24 namespace app_runtime = extensions::api::app_runtime; |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // TODO(derat): Add more IDs. | 29 // TODO(derat): Add more IDs. |
| 29 const char* const kExtensionIds[] = { | 30 const char* const kExtensionIds[] = { |
| 30 // TODO(jdufault): Remove testing version after m54. See crbug.com/640828. | 31 // TODO(jdufault): Remove testing version after m54. See crbug.com/640828. |
| 31 "ogfjaccbdfhecploibfbhighmebiffla", // Testing Keep app | 32 "ogfjaccbdfhecploibfbhighmebiffla", // Testing Keep app |
| 32 "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store) | 33 "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store) |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 // Returns the first installed and enabled whitelisted note-taking app, or null | 36 // Returns a list of app IDs. |
| 36 // if none is installed. | 37 std::vector<std::string> GetAppIds() { |
| 37 const extensions::Extension* GetApp(Profile* profile) { | |
| 38 // TODO(derat): Check the to-be-added "note-taking app enabled" pref here and | |
| 39 // return null if it's disabled. | |
| 40 | |
| 41 std::vector<std::string> ids; | 38 std::vector<std::string> ids; |
| 42 | 39 |
| 43 // TODO(derat): Instead of a using hardcoded list of IDs, use an app | 40 // TODO(derat): Instead of a using hardcoded list of IDs, use an app |
| 44 // designated by a to-be-added pref. | 41 // designated by a to-be-added pref. |
| 45 const std::string switch_value = | 42 const std::string switch_value = |
| 46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 43 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 47 switches::kNoteTakingAppIds); | 44 switches::kNoteTakingAppIds); |
| 48 if (!switch_value.empty()) { | 45 if (!switch_value.empty()) { |
| 49 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, | 46 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, |
| 50 base::SPLIT_WANT_NONEMPTY); | 47 base::SPLIT_WANT_NONEMPTY); |
| 51 } else { | 48 } else { |
| 52 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); | 49 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); |
| 53 } | 50 } |
| 51 return ids; | |
| 52 } | |
| 53 | |
| 54 // Returns the first installed and enabled whitelisted note-taking app, or null | |
| 55 // if none is installed. | |
| 56 const extensions::Extension* GetApp(Profile* profile) { | |
| 57 // TODO(derat): Check the to-be-added "note-taking app enabled" pref here and | |
| 58 // return null if it's disabled. | |
| 54 | 59 |
| 55 const extensions::ExtensionRegistry* extension_registry = | 60 const extensions::ExtensionRegistry* extension_registry = |
| 56 extensions::ExtensionRegistry::Get(profile); | 61 extensions::ExtensionRegistry::Get(profile); |
| 57 const extensions::ExtensionSet& enabled_extensions = | 62 const extensions::ExtensionSet& enabled_extensions = |
| 58 extension_registry->enabled_extensions(); | 63 extension_registry->enabled_extensions(); |
| 59 for (const auto& id : ids) { | 64 for (const auto& id : GetAppIds()) { |
| 60 if (enabled_extensions.Contains(id)) { | 65 if (enabled_extensions.Contains(id)) { |
| 61 return extension_registry->GetExtensionById( | 66 return extension_registry->GetExtensionById( |
| 62 id, extensions::ExtensionRegistry::ENABLED); | 67 id, extensions::ExtensionRegistry::ENABLED); |
| 63 } | 68 } |
| 64 } | 69 } |
| 65 return nullptr; | 70 return nullptr; |
| 66 } | 71 } |
| 67 | 72 |
| 68 } // namespace | 73 } // namespace |
| 69 | 74 |
| 70 bool IsNoteTakingAppAvailable(Profile* profile) { | 75 bool IsNoteTakingAppAvailable(Profile* profile) { |
| 71 DCHECK(profile); | 76 DCHECK(profile); |
| 72 return ash::IsPaletteFeatureEnabled() && GetApp(profile); | 77 return ash::IsPaletteFeatureEnabled() && GetApp(profile); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void LaunchNoteTakingAppForNewNote(Profile* profile, | 80 void LaunchNoteTakingAppForNewNote(Profile* profile, |
| 76 const base::FilePath& path) { | 81 const base::FilePath& path) { |
| 77 DCHECK(profile); | 82 DCHECK(profile); |
| 78 const extensions::Extension* app = GetApp(profile); | 83 const extensions::Extension* app = GetApp(profile); |
| 79 if (!app) { | 84 if (!app) { |
| 80 LOG(ERROR) << "Failed to find note-taking app"; | 85 LOG(ERROR) << "Failed to find note-taking app"; |
| 81 return; | 86 return; |
| 82 } | 87 } |
| 83 | 88 |
| 84 auto action_data = base::MakeUnique<app_runtime::ActionData>(); | 89 auto action_data = base::MakeUnique<app_runtime::ActionData>(); |
| 85 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; | 90 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; |
| 86 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path); | 91 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path); |
| 87 } | 92 } |
| 88 | 93 |
| 94 bool IsNoteTakingApp(extensions::AppWindow* app_window) { | |
| 95 for (const auto& id : GetAppIds()) { | |
|
Daniel Erat
2016/09/19 22:08:47
the changelist description describes us as measuri
xiaoyinh(OOO Sep 11-29)
2016/09/19 22:45:49
Thank you for your comments. GetApp will return th
| |
| 96 if (id == app_window->extension_id()) | |
| 97 return true; | |
| 98 } | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 89 } // namespace chromeos | 102 } // namespace chromeos |
| OLD | NEW |