OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input_method/component_extension_ime_manager_i
mpl.h" | 5 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 {"__MSG_TRANSLITERATION_SA__", IDS_IME_NAME_TRANSLITERATION_SA}, | 221 {"__MSG_TRANSLITERATION_SA__", IDS_IME_NAME_TRANSLITERATION_SA}, |
222 {"__MSG_TRANSLITERATION_SR__", IDS_IME_NAME_TRANSLITERATION_SR}, | 222 {"__MSG_TRANSLITERATION_SR__", IDS_IME_NAME_TRANSLITERATION_SR}, |
223 {"__MSG_TRANSLITERATION_TA__", IDS_IME_NAME_TRANSLITERATION_TA}, | 223 {"__MSG_TRANSLITERATION_TA__", IDS_IME_NAME_TRANSLITERATION_TA}, |
224 {"__MSG_TRANSLITERATION_TE__", IDS_IME_NAME_TRANSLITERATION_TE}, | 224 {"__MSG_TRANSLITERATION_TE__", IDS_IME_NAME_TRANSLITERATION_TE}, |
225 {"__MSG_TRANSLITERATION_TI__", IDS_IME_NAME_TRANSLITERATION_TI}, | 225 {"__MSG_TRANSLITERATION_TI__", IDS_IME_NAME_TRANSLITERATION_TI}, |
226 {"__MSG_TRANSLITERATION_UR__", IDS_IME_NAME_TRANSLITERATION_UR}, | 226 {"__MSG_TRANSLITERATION_UR__", IDS_IME_NAME_TRANSLITERATION_UR}, |
227 }; | 227 }; |
228 | 228 |
229 const char kImePathKeyName[] = "ime_path"; | 229 const char kImePathKeyName[] = "ime_path"; |
230 | 230 |
231 extensions::ComponentLoader* GetComponentLoader() { | 231 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { |
232 // TODO(skuhne, nkostylev): At this time the only thing which makes sense here | |
233 // is to use the active profile. Nkostylev is working on getting IME settings | |
234 // to work for multi user by collecting all settings from all users. Once that | |
235 // is done we might have to re-visit this decision. | |
236 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
237 extensions::ExtensionSystem* extension_system = | 232 extensions::ExtensionSystem* extension_system = |
238 extensions::ExtensionSystem::Get(profile); | 233 extensions::ExtensionSystem::Get(profile); |
239 ExtensionService* extension_service = extension_system->extension_service(); | 234 ExtensionService* extension_service = extension_system->extension_service(); |
240 return extension_service->component_loader(); | 235 return extension_service->component_loader(); |
241 } | 236 } |
242 } // namespace | 237 } // namespace |
243 | 238 |
244 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() | 239 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() |
245 : weak_ptr_factory_(this) { | 240 : weak_ptr_factory_(this) { |
246 ReadComponentExtensionsInfo(&component_extension_list_); | 241 ReadComponentExtensionsInfo(&component_extension_list_); |
247 } | 242 } |
248 | 243 |
249 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { | 244 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { |
250 } | 245 } |
251 | 246 |
252 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { | 247 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { |
253 return component_extension_list_; | 248 return component_extension_list_; |
254 } | 249 } |
255 | 250 |
256 bool ComponentExtensionIMEManagerImpl::Load(const std::string& extension_id, | 251 bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, |
| 252 const std::string& extension_id, |
257 const std::string& manifest, | 253 const std::string& manifest, |
258 const base::FilePath& file_path) { | 254 const base::FilePath& file_path) { |
259 // If current environment is linux_chromeos, there should be no file path for | 255 // If current environment is linux_chromeos, there should be no file path for |
260 // the component extensions, so avoid loading them. | 256 // the component extensions, so avoid loading them. |
261 // The tests are also running on linux_chromeos environment. No test should | 257 // The tests are also running on linux_chromeos environment. No test should |
262 // run with the real component extensions because the component extension | 258 // run with the real component extensions because the component extension |
263 // contents are not in chromium code base. They're installed through ebuild | 259 // contents are not in chromium code base. They're installed through ebuild |
264 // scripts from chromeos. | 260 // scripts from chromeos. |
265 if (!base::SysInfo::IsRunningOnChromeOS()) | 261 if (!base::SysInfo::IsRunningOnChromeOS()) |
266 return false; | 262 return false; |
267 | 263 |
268 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
269 extensions::ExtensionSystem* extension_system = | 264 extensions::ExtensionSystem* extension_system = |
270 extensions::ExtensionSystem::Get(profile); | 265 extensions::ExtensionSystem::Get(profile); |
271 ExtensionService* extension_service = extension_system->extension_service(); | 266 ExtensionService* extension_service = extension_system->extension_service(); |
272 if (extension_service->GetExtensionById(extension_id, false)) | 267 if (extension_service->GetExtensionById(extension_id, false)) |
273 return false; | 268 return false; |
274 const std::string loaded_extension_id = | 269 const std::string loaded_extension_id = |
275 GetComponentLoader()->Add(manifest, file_path); | 270 GetComponentLoader(profile)->Add(manifest, file_path); |
276 DCHECK_EQ(loaded_extension_id, extension_id); | 271 DCHECK_EQ(loaded_extension_id, extension_id); |
277 return true; | 272 return true; |
278 } | 273 } |
279 | 274 |
280 void ComponentExtensionIMEManagerImpl::Unload(const std::string& extension_id, | 275 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, |
| 276 const std::string& extension_id, |
281 const base::FilePath& file_path) { | 277 const base::FilePath& file_path) { |
282 // Remove(extension_id) does nothing when the extension has already been | 278 // Remove(extension_id) does nothing when the extension has already been |
283 // removed or not been registered. | 279 // removed or not been registered. |
284 GetComponentLoader()->Remove(extension_id); | 280 GetComponentLoader(profile)->Remove(extension_id); |
285 } | 281 } |
286 | 282 |
287 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( | 283 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( |
288 const std::string& manifest_string) { | 284 const std::string& manifest_string) { |
289 std::string error; | 285 std::string error; |
290 JSONStringValueSerializer serializer(manifest_string); | 286 JSONStringValueSerializer serializer(manifest_string); |
291 scoped_ptr<base::Value> manifest(serializer.Deserialize(NULL, &error)); | 287 scoped_ptr<base::Value> manifest(serializer.Deserialize(NULL, &error)); |
292 if (!manifest.get()) | 288 if (!manifest.get()) |
293 LOG(ERROR) << "Failed at getting manifest"; | 289 LOG(ERROR) << "Failed at getting manifest"; |
294 | 290 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 449 |
454 ComponentExtensionEngine engine; | 450 ComponentExtensionEngine engine; |
455 ReadEngineComponent(component_ime, *dictionary, &engine); | 451 ReadEngineComponent(component_ime, *dictionary, &engine); |
456 component_ime.engines.push_back(engine); | 452 component_ime.engines.push_back(engine); |
457 } | 453 } |
458 out_imes->push_back(component_ime); | 454 out_imes->push_back(component_ime); |
459 } | 455 } |
460 } | 456 } |
461 | 457 |
462 } // namespace chromeos | 458 } // namespace chromeos |
OLD | NEW |