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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 =
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. Also decide what should be passed as the launch
80 // source.
81 if (path.empty())
82 apps::LaunchPlatformApp(profile, app, extensions::SOURCE_UNTRACKED);
83 else
84 apps::LaunchPlatformAppWithPath(profile, app, path);
85 }
86
87 } // namespace chromeos
OLDNEW
« 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