Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5735)

Unified Diff: chrome/browser/chromeos/note_taking_app_utils.cc

Issue 2225543002: chromeos: Add note-taking-app utility functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update TODO for review comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/note_taking_app_utils.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/note_taking_app_utils.cc
diff --git a/chrome/browser/chromeos/note_taking_app_utils.cc b/chrome/browser/chromeos/note_taking_app_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e3cef1ae66c233cac487ed25b832f1efc7ecb18
--- /dev/null
+++ b/chrome/browser/chromeos/note_taking_app_utils.cc
@@ -0,0 +1,87 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/note_taking_app_utils.h"
+
+#include <string>
+#include <vector>
+
+#include "apps/launcher.h"
+#include "ash/common/system/chromeos/palette/palette_utils.h"
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/strings/string_split.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chromeos/chromeos_switches.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/common/extension.h"
+#include "url/gurl.h"
+
+namespace chromeos {
+namespace {
+
+// TODO(derat): Add more IDs.
+const char* const kExtensionIds[] = {
+ "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store)
+};
+
+// Returns the first installed and enabled whitelisted note-taking app, or null
+// if none is installed.
+const extensions::Extension* GetApp(Profile* profile) {
+ // TODO(derat): Check the to-be-added "note-taking app enabled" pref here and
+ // return null if it's disabled.
+
+ std::vector<std::string> ids;
+
+ // TODO(derat): Instead of a using hardcoded list of IDs, use an app
+ // designated by a to-be-added pref.
+ const std::string switch_value =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kNoteTakingAppIds);
+ if (!switch_value.empty()) {
+ ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY);
+ } else {
+ ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds));
+ }
+
+ const extensions::ExtensionRegistry* extension_registry =
+ extensions::ExtensionRegistry::Get(profile);
+ const extensions::ExtensionSet& enabled_extensions =
+ extension_registry->enabled_extensions();
+ for (const auto& id : ids) {
+ if (enabled_extensions.Contains(id)) {
+ return extension_registry->GetExtensionById(
+ id, extensions::ExtensionRegistry::ENABLED);
+ }
+ }
+ return nullptr;
+}
+
+} // namespace
+
+bool IsNoteTakingAppAvailable(Profile* profile) {
+ DCHECK(profile);
+ return ash::IsPaletteEnabled() && GetApp(profile);
+}
+
+void LaunchNoteTakingAppForNewNote(Profile* profile,
+ const base::FilePath& path) {
+ DCHECK(profile);
+ const extensions::Extension* app = GetApp(profile);
+ if (!app) {
+ LOG(ERROR) << "Failed to find note-taking app";
+ return;
+ }
+
+ // TODO(derat): Launch with a "create new note" launch action once that's been
+ // added to chrome.appRuntime. Also decide what should be passed as the launch
+ // source.
+ if (path.empty())
+ apps::LaunchPlatformApp(profile, app, extensions::SOURCE_UNTRACKED);
+ else
+ apps::LaunchPlatformAppWithPath(profile, app, path);
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/note_taking_app_utils.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698