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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/device_stylus_handler.cc

Issue 2630623002: cros: Allow user to configure note taking app in md-settings. (Closed)
Patch Set: Initial upload Created 3 years, 11 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 2017 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/ui/webui/settings/chromeos/device_stylus_handler.h"
6
7 #include "chrome/browser/profiles/profile.h"
8
9 namespace chromeos {
10 namespace settings {
11
12 namespace {
13
14 // Keys in objects passed to onNoteTakingAppsUpdated.
15 constexpr char kAppNameKey[] = "name";
16 constexpr char kAppIdKey[] = "value";
17 constexpr char kAppPreferredKey[] = "preferred";
18
19 } // namespace
20
21 StylusHandler::StylusHandler() {
22 NoteTakingHelper::Get()->AddObserver(this);
23 }
24
25 StylusHandler::~StylusHandler() {
26 NoteTakingHelper::Get()->RemoveObserver(this);
27 }
28
29 void StylusHandler::RegisterMessages() {
30 DCHECK(web_ui());
31
32 web_ui()->RegisterMessageCallback(
33 "requestNoteTakingApps",
34 base::Bind(&StylusHandler::RequestApps, base::Unretained(this)));
35 web_ui()->RegisterMessageCallback(
36 "setPreferredNoteTakingApp",
37 base::Bind(&StylusHandler::SetPreferredNoteTakingApp,
38 base::Unretained(this)));
39 }
40
41 void StylusHandler::OnAvailableNoteTakingAppsUpdated() {
42 UpdateNoteTakingApps();
43 }
44
45 void StylusHandler::UpdateNoteTakingApps() {
46 bool waiting_for_android = false;
47 note_taking_app_ids_.clear();
48 base::ListValue apps_list;
49
50 NoteTakingHelper* helper = NoteTakingHelper::Get();
51 if (helper->android_enabled() && !helper->android_apps_received()) {
52 // If Android is enabled but not ready yet, let the JS know so it can
53 // disable the menu and display an explanatory message.
54 waiting_for_android = true;
55 } else {
56 for (const NoteTakingAppInfo& info :
57 NoteTakingHelper::Get()->GetAvailableApps(
58 Profile::FromWebUI(web_ui()))) {
stevenjb 2017/01/19 17:48:53 nit: This might be a little more clear with: auto
jdufault 2017/01/25 00:52:22 Done.
59 auto dict = base::MakeUnique<base::DictionaryValue>();
60 dict->SetString(kAppNameKey, info.name);
61 dict->SetString(kAppIdKey, info.app_id);
62 dict->SetBoolean(kAppPreferredKey, info.preferred);
63 apps_list.Append(std::move(dict));
64
65 note_taking_app_ids_.insert(info.app_id);
66 }
67 }
68
69 CallJavascriptFunction(
70 "cr.webUIListenerCallback", base::StringValue("onNoteTakingAppsUpdated"),
71 apps_list, base::FundamentalValue(waiting_for_android));
72 }
73
74 void StylusHandler::RequestApps(const base::ListValue* unused_args) {
75 AllowJavascript();
76 UpdateNoteTakingApps();
77 }
78
79 void StylusHandler::SetPreferredNoteTakingApp(const base::ListValue* args) {
80 std::string app_id;
81 CHECK(args->GetString(0, &app_id));
82
83 // Sanity check: make sure that the ID we got back from WebUI is in the
84 // currently-available set.
85 if (!note_taking_app_ids_.count(app_id)) {
86 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\"";
87 return;
88 }
89
90 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()),
Daniel Erat 2017/01/19 00:50:05 since we discussed it before: it ended up making s
jdufault 2017/01/25 00:52:22 Yea, given the nature of how preferred values are
91 app_id);
92 }
93
94 } // namespace settings
95 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698