Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/note_taking_app_utils.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "apps/launcher.h" | |
| 11 #include "ash/common/system/chromeos/palette/palette_utils.h" | |
| 12 #include "base/command_line.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/strings/string_split.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 16 #include "chromeos/chromeos_switches.h" | |
| 17 #include "extensions/browser/extension_registry.h" | |
| 18 #include "extensions/common/extension.h" | |
| 19 #include "url/gurl.h" | |
| 20 | |
| 21 namespace chromeos { | |
| 22 namespace { | |
| 23 | |
| 24 // TODO(derat): Add more IDs. | |
| 25 const char* const kExtensionIds[] = { | |
| 26 "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store) | |
| 27 }; | |
| 28 | |
| 29 // Returns the first installed and enabled whitelisted note-taking app, or null | |
| 30 // if none is installed. | |
| 31 const extensions::Extension* GetApp(Profile* profile) { | |
| 32 // TODO(derat): Check the to-be-added "note-taking app enabled" pref here and | |
| 33 // return null if it's disabled. | |
| 34 | |
| 35 std::vector<std::string> ids; | |
| 36 | |
| 37 // TODO(derat): Instead of a using hardcoded list of IDs, use an app | |
| 38 // designated by a to-be-added pref. | |
| 39 const std::string switch_value = | |
|
jdufault
2016/08/08 19:44:23
Pull into a helper method? I'm fine as is.
Daniel Erat
2016/08/08 20:04:36
thanks, i'll probably leave it like this (since it
| |
| 40 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 41 switches::kNoteTakingAppIds); | |
| 42 if (!switch_value.empty()) { | |
| 43 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, | |
| 44 base::SPLIT_WANT_NONEMPTY); | |
| 45 } else { | |
| 46 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); | |
| 47 } | |
| 48 | |
| 49 const extensions::ExtensionRegistry* extension_registry = | |
| 50 extensions::ExtensionRegistry::Get(profile); | |
| 51 const extensions::ExtensionSet& enabled_extensions = | |
| 52 extension_registry->enabled_extensions(); | |
| 53 for (const auto& id : ids) { | |
| 54 if (enabled_extensions.Contains(id)) { | |
| 55 return extension_registry->GetExtensionById( | |
| 56 id, extensions::ExtensionRegistry::ENABLED); | |
| 57 } | |
| 58 } | |
| 59 return nullptr; | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 bool IsNoteTakingAppAvailable(Profile* profile) { | |
| 65 DCHECK(profile); | |
| 66 return ash::IsPaletteEnabled() && GetApp(profile); | |
| 67 } | |
| 68 | |
| 69 void LaunchNoteTakingAppForNewNote(Profile* profile, | |
| 70 const base::FilePath& path) { | |
| 71 DCHECK(profile); | |
| 72 const extensions::Extension* app = GetApp(profile); | |
| 73 if (!app) { | |
| 74 LOG(ERROR) << "Failed to find note-taking app"; | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 // TODO(derat): Launch with a "create new note" launch action once that's been | |
| 79 // added to chrome.appRuntime. | |
| 80 if (path.empty()) | |
| 81 apps::LaunchPlatformApp(profile, app, extensions::SOURCE_UNTRACKED); | |
|
jdufault
2016/08/08 19:44:23
We should probably specify the launch source - add
Daniel Erat
2016/08/08 20:04:36
do you think we should add new launch sources name
| |
| 82 else | |
| 83 apps::LaunchPlatformAppWithPath(profile, app, path); | |
| 84 } | |
| 85 | |
| 86 } // namespace chromeos | |
| OLD | NEW |