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

Side by Side Diff: chrome/browser/chromeos/note_taking_app_utils.cc

Issue 2526893003: chromeos: Add NoteTakingHelper class. (Closed)
Patch Set: drop is-note-taking-app-window stuff Created 4 years 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/memory/ptr_util.h"
15 #include "base/strings/string_split.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "extensions/browser/extension_registry.h"
19 #include "extensions/common/api/app_runtime.h"
20 #include "extensions/common/extension.h"
21 #include "url/gurl.h"
22
23 namespace app_runtime = extensions::api::app_runtime;
24
25 namespace chromeos {
26 namespace {
27
28 // TODO(derat): Add more IDs.
29 const char* const kExtensionIds[] = {
30 // TODO(jdufault): Remove testing version after m54. See crbug.com/640828.
31 "ogfjaccbdfhecploibfbhighmebiffla", // Testing Keep app
32 "hmjkmjkepdijhoojdojkdfohbdgmmhki", // Google Keep app (Web Store)
33 };
34
35 // Returns the first installed and enabled whitelisted note-taking app, or null
36 // if none is installed.
37 const extensions::Extension* GetApp(Profile* profile) {
38 // TODO(derat): Check the to-be-added "note-taking app enabled" pref here and
39 // return null if it's disabled.
40
41 std::vector<std::string> ids;
42
43 // TODO(derat): Instead of a using hardcoded list of IDs, use an app
44 // designated by a to-be-added pref.
45 const std::string switch_value =
46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
47 switches::kNoteTakingAppIds);
48 if (!switch_value.empty()) {
49 ids = base::SplitString(switch_value, ",", base::TRIM_WHITESPACE,
50 base::SPLIT_WANT_NONEMPTY);
51 } else {
52 ids.assign(kExtensionIds, kExtensionIds + arraysize(kExtensionIds));
53 }
54
55 const extensions::ExtensionRegistry* extension_registry =
56 extensions::ExtensionRegistry::Get(profile);
57 const extensions::ExtensionSet& enabled_extensions =
58 extension_registry->enabled_extensions();
59 for (const auto& id : ids) {
60 if (enabled_extensions.Contains(id)) {
61 return extension_registry->GetExtensionById(
62 id, extensions::ExtensionRegistry::ENABLED);
63 }
64 }
65 return nullptr;
66 }
67
68 } // namespace
69
70 bool IsNoteTakingAppAvailable(Profile* profile) {
71 DCHECK(profile);
72 return ash::IsPaletteFeatureEnabled() && GetApp(profile);
73 }
74
75 void LaunchNoteTakingAppForNewNote(Profile* profile,
76 const base::FilePath& path) {
77 DCHECK(profile);
78 const extensions::Extension* app = GetApp(profile);
79 if (!app) {
80 LOG(ERROR) << "Failed to find note-taking app";
81 return;
82 }
83
84 auto action_data = base::MakeUnique<app_runtime::ActionData>();
85 action_data->action_type = app_runtime::ActionType::ACTION_TYPE_NEW_NOTE;
86 apps::LaunchPlatformAppWithAction(profile, app, std::move(action_data), path);
87 }
88
89 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698