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

Side by Side Diff: chrome/browser/chromeos/extensions/input_method_api.cc

Issue 2038083004: Reland of ExtensionFunction: don't pass ownership of base::Value by raw pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/input_method_api.h" 5 #include "chrome/browser/chromeos/extensions/input_method_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/memory/ptr_util.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" 18 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h"
18 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h" 19 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h"
19 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 20 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
20 #include "chrome/browser/chromeos/input_method/input_method_util.h" 21 #include "chrome/browser/chromeos/input_method/input_method_util.h"
21 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" 22 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/spellchecker/spellcheck_factory.h" 24 #include "chrome/browser/spellchecker/spellcheck_factory.h"
24 #include "chrome/browser/spellchecker/spellcheck_service.h" 25 #include "chrome/browser/spellchecker/spellcheck_service.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 69
69 } // namespace 70 } // namespace
70 71
71 namespace extensions { 72 namespace extensions {
72 73
73 ExtensionFunction::ResponseAction 74 ExtensionFunction::ResponseAction
74 InputMethodPrivateGetInputMethodConfigFunction::Run() { 75 InputMethodPrivateGetInputMethodConfigFunction::Run() {
75 #if !defined(OS_CHROMEOS) 76 #if !defined(OS_CHROMEOS)
76 EXTENSION_FUNCTION_VALIDATE(false); 77 EXTENSION_FUNCTION_VALIDATE(false);
77 #else 78 #else
78 base::DictionaryValue* output = new base::DictionaryValue(); 79 std::unique_ptr<base::DictionaryValue> output(new base::DictionaryValue());
79 output->SetBoolean( 80 output->SetBoolean(
80 "isPhysicalKeyboardAutocorrectEnabled", 81 "isPhysicalKeyboardAutocorrectEnabled",
81 !base::CommandLine::ForCurrentProcess()->HasSwitch( 82 !base::CommandLine::ForCurrentProcess()->HasSwitch(
82 chromeos::switches::kDisablePhysicalKeyboardAutocorrect)); 83 chromeos::switches::kDisablePhysicalKeyboardAutocorrect));
83 output->SetBoolean("isImeMenuActivated", 84 output->SetBoolean("isImeMenuActivated",
84 base::FeatureList::IsEnabled(features::kOptInImeMenu) && 85 base::FeatureList::IsEnabled(features::kOptInImeMenu) &&
85 Profile::FromBrowserContext(browser_context()) 86 Profile::FromBrowserContext(browser_context())
86 ->GetPrefs() 87 ->GetPrefs()
87 ->GetBoolean(prefs::kLanguageImeMenuActivated)); 88 ->GetBoolean(prefs::kLanguageImeMenuActivated));
88 return RespondNow(OneArgument(output)); 89 return RespondNow(OneArgument(std::move(output)));
89 #endif 90 #endif
90 } 91 }
91 92
92 ExtensionFunction::ResponseAction 93 ExtensionFunction::ResponseAction
93 InputMethodPrivateGetCurrentInputMethodFunction::Run() { 94 InputMethodPrivateGetCurrentInputMethodFunction::Run() {
94 #if !defined(OS_CHROMEOS) 95 #if !defined(OS_CHROMEOS)
95 EXTENSION_FUNCTION_VALIDATE(false); 96 EXTENSION_FUNCTION_VALIDATE(false);
96 #else 97 #else
97 chromeos::input_method::InputMethodManager* manager = 98 chromeos::input_method::InputMethodManager* manager =
98 chromeos::input_method::InputMethodManager::Get(); 99 chromeos::input_method::InputMethodManager::Get();
99 return RespondNow(OneArgument(new base::StringValue( 100 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>(
100 manager->GetActiveIMEState()->GetCurrentInputMethod().id()))); 101 manager->GetActiveIMEState()->GetCurrentInputMethod().id())));
101 #endif 102 #endif
102 } 103 }
103 104
104 ExtensionFunction::ResponseAction 105 ExtensionFunction::ResponseAction
105 InputMethodPrivateSetCurrentInputMethodFunction::Run() { 106 InputMethodPrivateSetCurrentInputMethodFunction::Run() {
106 #if !defined(OS_CHROMEOS) 107 #if !defined(OS_CHROMEOS)
107 EXTENSION_FUNCTION_VALIDATE(false); 108 EXTENSION_FUNCTION_VALIDATE(false);
108 #else 109 #else
109 std::unique_ptr<SetCurrentInputMethod::Params> params( 110 std::unique_ptr<SetCurrentInputMethod::Params> params(
(...skipping 13 matching lines...) Expand all
123 } 124 }
124 return RespondNow(Error("Invalid input method id.")); 125 return RespondNow(Error("Invalid input method id."));
125 #endif 126 #endif
126 } 127 }
127 128
128 ExtensionFunction::ResponseAction 129 ExtensionFunction::ResponseAction
129 InputMethodPrivateGetInputMethodsFunction::Run() { 130 InputMethodPrivateGetInputMethodsFunction::Run() {
130 #if !defined(OS_CHROMEOS) 131 #if !defined(OS_CHROMEOS)
131 EXTENSION_FUNCTION_VALIDATE(false); 132 EXTENSION_FUNCTION_VALIDATE(false);
132 #else 133 #else
133 base::ListValue* output = new base::ListValue(); 134 std::unique_ptr<base::ListValue> output(new base::ListValue());
134 chromeos::input_method::InputMethodManager* manager = 135 chromeos::input_method::InputMethodManager* manager =
135 chromeos::input_method::InputMethodManager::Get(); 136 chromeos::input_method::InputMethodManager::Get();
136 chromeos::input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); 137 chromeos::input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
137 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state = 138 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state =
138 manager->GetActiveIMEState(); 139 manager->GetActiveIMEState();
139 std::unique_ptr<chromeos::input_method::InputMethodDescriptors> 140 std::unique_ptr<chromeos::input_method::InputMethodDescriptors>
140 input_methods = ime_state->GetActiveInputMethods(); 141 input_methods = ime_state->GetActiveInputMethods();
141 for (size_t i = 0; i < input_methods->size(); ++i) { 142 for (size_t i = 0; i < input_methods->size(); ++i) {
142 const chromeos::input_method::InputMethodDescriptor& input_method = 143 const chromeos::input_method::InputMethodDescriptor& input_method =
143 (*input_methods)[i]; 144 (*input_methods)[i];
144 base::DictionaryValue* val = new base::DictionaryValue(); 145 base::DictionaryValue* val = new base::DictionaryValue();
145 val->SetString("id", input_method.id()); 146 val->SetString("id", input_method.id());
146 val->SetString("name", util->GetInputMethodLongName(input_method)); 147 val->SetString("name", util->GetInputMethodLongName(input_method));
147 val->SetString("indicator", util->GetInputMethodShortName(input_method)); 148 val->SetString("indicator", util->GetInputMethodShortName(input_method));
148 output->Append(val); 149 output->Append(val);
149 } 150 }
150 return RespondNow(OneArgument(output)); 151 return RespondNow(OneArgument(std::move(output)));
151 #endif 152 #endif
152 } 153 }
153 154
154 ExtensionFunction::ResponseAction 155 ExtensionFunction::ResponseAction
155 InputMethodPrivateFetchAllDictionaryWordsFunction::Run() { 156 InputMethodPrivateFetchAllDictionaryWordsFunction::Run() {
156 #if !defined(OS_CHROMEOS) 157 #if !defined(OS_CHROMEOS)
157 EXTENSION_FUNCTION_VALIDATE(false); 158 EXTENSION_FUNCTION_VALIDATE(false);
158 #else 159 #else
159 SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext( 160 SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext(
160 context_); 161 context_);
161 if (!spellcheck) { 162 if (!spellcheck) {
162 return RespondNow(Error("Spellcheck service not available.")); 163 return RespondNow(Error("Spellcheck service not available."));
163 } 164 }
164 SpellcheckCustomDictionary* dictionary = spellcheck->GetCustomDictionary(); 165 SpellcheckCustomDictionary* dictionary = spellcheck->GetCustomDictionary();
165 if (!dictionary->IsLoaded()) { 166 if (!dictionary->IsLoaded()) {
166 return RespondNow(Error("Custom dictionary not loaded yet.")); 167 return RespondNow(Error("Custom dictionary not loaded yet."));
167 } 168 }
168 169
169 const std::set<std::string>& words = dictionary->GetWords(); 170 const std::set<std::string>& words = dictionary->GetWords();
170 base::ListValue* output = new base::ListValue(); 171 std::unique_ptr<base::ListValue> output(new base::ListValue());
171 for (auto it = words.begin(); it != words.end(); ++it) { 172 for (auto it = words.begin(); it != words.end(); ++it) {
172 output->AppendString(*it); 173 output->AppendString(*it);
173 } 174 }
174 return RespondNow(OneArgument(output)); 175 return RespondNow(OneArgument(std::move(output)));
175 #endif 176 #endif
176 } 177 }
177 178
178 ExtensionFunction::ResponseAction 179 ExtensionFunction::ResponseAction
179 InputMethodPrivateAddWordToDictionaryFunction::Run() { 180 InputMethodPrivateAddWordToDictionaryFunction::Run() {
180 #if !defined(OS_CHROMEOS) 181 #if !defined(OS_CHROMEOS)
181 EXTENSION_FUNCTION_VALIDATE(false); 182 EXTENSION_FUNCTION_VALIDATE(false);
182 #else 183 #else
183 std::unique_ptr<AddWordToDictionary::Params> params( 184 std::unique_ptr<AddWordToDictionary::Params> params(
184 AddWordToDictionary::Params::Create(*args_)); 185 AddWordToDictionary::Params::Create(*args_));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > 369 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> >
369 g_factory = LAZY_INSTANCE_INITIALIZER; 370 g_factory = LAZY_INSTANCE_INITIALIZER;
370 371
371 // static 372 // static
372 BrowserContextKeyedAPIFactory<InputMethodAPI>* 373 BrowserContextKeyedAPIFactory<InputMethodAPI>*
373 InputMethodAPI::GetFactoryInstance() { 374 InputMethodAPI::GetFactoryInstance() {
374 return g_factory.Pointer(); 375 return g_factory.Pointer();
375 } 376 }
376 377
377 } // namespace extensions 378 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698