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 // TODO(derat): Instead of a using hardcoded list of IDs, use an app designated | |
| 32 // by a pref. | |
| 33 const extensions::Extension* GetApp(Profile* profile) { | |
| 34 std::vector<std::string> ids; | |
| 35 | |
| 36 const std::string switch_value = | |
| 37 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 38 switches::kNoteTakingAppIds); | |
| 39 if (!switch_value.empty()) { | |
| 40 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE, | |
| 41 base::SPLIT_WANT_NONEMPTY); | |
| 42 } else { | |
| 43 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds)); | |
| 44 } | |
| 45 | |
| 46 const extensions::ExtensionRegistry* extension_registry = | |
| 47 extensions::ExtensionRegistry::Get(profile); | |
| 48 const extensions::ExtensionSet& enabled_extensions = | |
| 49 extension_registry->enabled_extensions(); | |
| 50 for (const auto& id : ids) { | |
| 51 if (enabled_extensions.Contains(id)) { | |
| 52 return extension_registry->GetExtensionById( | |
| 53 id, extensions::ExtensionRegistry::ENABLED); | |
| 54 } | |
| 55 } | |
| 56 return nullptr; | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 bool IsNoteTakingAppAvailable(Profile* profile) { | |
| 62 DCHECK(profile); | |
| 63 return ash::IsPaletteEnabled() && GetApp(profile); | |
| 64 } | |
| 65 | |
| 66 void LaunchNoteTakingAppForNewNote(Profile* profile, | |
| 67 const base::FilePath& path) { | |
| 68 DCHECK(profile); | |
| 69 const extensions::Extension* app = GetApp(profile); | |
| 70 if (!app) { | |
| 71 LOG(ERROR) << "Failed to find note-taking app"; | |
| 72 return; | |
| 73 } | |
| 74 | |
| 75 // TODO: Launch with an "action" launch source and the appropriate action type | |
|
jdufault
2016/08/05 22:59:38
FYI, I have a CL that I'll upload shortly that doe
Daniel Erat
2016/08/05 23:19:23
i'd read the doc and figured you were were working
| |
| 76 // to create a new note once that's been added to chrome.appRuntime. | |
| 77 if (path.empty()) | |
| 78 apps::LaunchPlatformApp(profile, app, extensions::SOURCE_UNTRACKED); | |
| 79 else | |
| 80 apps::LaunchPlatformAppWithPath(profile, app, path); | |
|
jdufault
2016/08/05 22:59:38
Did you have a chance to take a look at the API pr
Daniel Erat
2016/08/05 23:19:23
i chatted with tom about this yesterday. i didn't
| |
| 81 } | |
| 82 | |
| 83 } // namespace chromeos | |
| OLD | NEW |