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 | |
| 44 // designated by a to-be-added pref. | |
| 45 const std::string switch_value = | 40 const std::string switch_value = |
| 46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 41 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 47 switches::kNoteTakingAppIds); | 42 switches::kNoteTakingAppIds); |
| 48 if (!switch_value.empty()) { | 43 if (!switch_value.empty()) { |
| 49 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, | 44 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, |
| 50 base::SPLIT_WANT_NONEMPTY); | 45 base::SPLIT_WANT_NONEMPTY); |
| 51 } else { | 46 } else { |
| 52 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); | 47 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); |
| 53 } | 48 } |
| 49 return ids; | |
| 50 } | |
| 51 | |
| 52 // Returns the first installed and enabled whitelisted note-taking app, or null | |
| 53 // if none is installed. | |
| 54 const extensions::Extension* GetApp(Profile* profile) { | |
| 55 // TODO(derat): Check the to-be-added "note-taking app enabled" pref here and | |
| 56 // return null if it's disabled. | |
| 57 | |
| 58 std::vector<std::string> ids; | |
| 59 | |
| 60 // TODO(derat): Instead of a using hardcoded list of IDs, use an app | |
| 61 // designated by a to-be-added pref. | |
| 62 ids = GetAppIds(); | |
|
xiyuan
2016/09/16 20:07:53
nit: Move the declaration in L58 down here,
i.e.
xiaoyinh(OOO Sep 11-29)
2016/09/16 22:34:25
Done.
| |
| 54 | 63 |
| 55 const extensions::ExtensionRegistry* extension_registry = | 64 const extensions::ExtensionRegistry* extension_registry = |
| 56 extensions::ExtensionRegistry::Get(profile); | 65 extensions::ExtensionRegistry::Get(profile); |
| 57 const extensions::ExtensionSet& enabled_extensions = | 66 const extensions::ExtensionSet& enabled_extensions = |
| 58 extension_registry->enabled_extensions(); | 67 extension_registry->enabled_extensions(); |
| 59 for (const auto& id : ids) { | 68 for (const auto& id : ids) { |
| 60 if (enabled_extensions.Contains(id)) { | 69 if (enabled_extensions.Contains(id)) { |
| 61 return extension_registry->GetExtensionById( | 70 return extension_registry->GetExtensionById( |
| 62 id, extensions::ExtensionRegistry::ENABLED); | 71 id, extensions::ExtensionRegistry::ENABLED); |
| 63 } | 72 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 79 if (!app) { | 88 if (!app) { |
| 80 LOG(ERROR) << "Failed to find note-taking app"; | 89 LOG(ERROR) << "Failed to find note-taking app"; |
| 81 return; | 90 return; |
| 82 } | 91 } |
| 83 | 92 |
| 84 auto action_data = base::MakeUnique<app_runtime::ActionData>(); | 93 auto action_data = base::MakeUnique<app_runtime::ActionData>(); |
| 85 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; | 94 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE; |
| 86 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path); | 95 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path); |
| 87 } | 96 } |
| 88 | 97 |
| 98 bool IsNoteTakingApp(extensions::AppWindow* app_window) { | |
| 99 std::vector<std::string> ids = GetAppIds(); | |
| 100 for (const auto& id : ids) { | |
| 101 if (id == app_window->extension_id()) | |
| 102 return true; | |
| 103 } | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 89 } // namespace chromeos | 107 } // namespace chromeos |
| OLD | NEW |