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

Side by Side 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 unified diff | Download patch
OLDNEW
(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
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);
81 }
82
83 } // namespace chromeos
OLDNEW
« 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