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

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

Issue 2219953004: Refactor download image-MIME-type-detection code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more tests 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/browser/download/download_commands.cc » ('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..ff06087d71cc1dc27faed4eb54a170020b0bc3c9
--- /dev/null
+++ b/chrome/browser/chromeos/note_taking_app_utils.cc
@@ -0,0 +1,83 @@
+// 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.
+// TODO(derat): Instead of a using hardcoded list of IDs, use an app designated
+// by a pref.
+const extensions::Extension* GetApp(Profile* profile) {
+ std::vector<std::string> ids;
+
+ 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: Launch with an "action" launch source and the appropriate action type
+ // to create a new note once that's been added to chrome.appRuntime.
+ 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/browser/download/download_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698