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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 {"__MSG_TRANSLITERATION_SA__", IDS_IME_NAME_TRANSLITERATION_SA}, | 225 {"__MSG_TRANSLITERATION_SA__", IDS_IME_NAME_TRANSLITERATION_SA}, |
226 {"__MSG_TRANSLITERATION_SR__", IDS_IME_NAME_TRANSLITERATION_SR}, | 226 {"__MSG_TRANSLITERATION_SR__", IDS_IME_NAME_TRANSLITERATION_SR}, |
227 {"__MSG_TRANSLITERATION_TA__", IDS_IME_NAME_TRANSLITERATION_TA}, | 227 {"__MSG_TRANSLITERATION_TA__", IDS_IME_NAME_TRANSLITERATION_TA}, |
228 {"__MSG_TRANSLITERATION_TE__", IDS_IME_NAME_TRANSLITERATION_TE}, | 228 {"__MSG_TRANSLITERATION_TE__", IDS_IME_NAME_TRANSLITERATION_TE}, |
229 {"__MSG_TRANSLITERATION_TI__", IDS_IME_NAME_TRANSLITERATION_TI}, | 229 {"__MSG_TRANSLITERATION_TI__", IDS_IME_NAME_TRANSLITERATION_TI}, |
230 {"__MSG_TRANSLITERATION_UR__", IDS_IME_NAME_TRANSLITERATION_UR}, | 230 {"__MSG_TRANSLITERATION_UR__", IDS_IME_NAME_TRANSLITERATION_UR}, |
231 }; | 231 }; |
232 | 232 |
233 const char kImePathKeyName[] = "ime_path"; | 233 const char kImePathKeyName[] = "ime_path"; |
234 | 234 |
235 extensions::ComponentLoader* GetComponentLoader() { | 235 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { |
236 // TODO(skuhne, nkostylev): At this time the only thing which makes sense here | |
237 // is to use the active profile. Nkostylev is working on getting IME settings | |
238 // to work for multi user by collecting all settings from all users. Once that | |
239 // is done we might have to re-visit this decision. | |
240 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
241 extensions::ExtensionSystem* extension_system = | 236 extensions::ExtensionSystem* extension_system = |
242 extensions::ExtensionSystem::Get(profile); | 237 extensions::ExtensionSystem::Get(profile); |
243 ExtensionService* extension_service = extension_system->extension_service(); | 238 ExtensionService* extension_service = extension_system->extension_service(); |
244 return extension_service->component_loader(); | 239 return extension_service->component_loader(); |
245 } | 240 } |
246 } // namespace | 241 } // namespace |
247 | 242 |
248 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() | 243 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() |
249 : weak_ptr_factory_(this) { | 244 : weak_ptr_factory_(this) { |
250 ReadComponentExtensionsInfo(&component_extension_list_); | 245 ReadComponentExtensionsInfo(&component_extension_list_); |
251 } | 246 } |
252 | 247 |
253 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { | 248 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { |
254 } | 249 } |
255 | 250 |
256 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { | 251 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { |
257 return component_extension_list_; | 252 return component_extension_list_; |
258 } | 253 } |
259 | 254 |
260 bool ComponentExtensionIMEManagerImpl::Load(const std::string& extension_id, | 255 bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, |
| 256 const std::string& extension_id, |
261 const std::string& manifest, | 257 const std::string& manifest, |
262 const base::FilePath& file_path) { | 258 const base::FilePath& file_path) { |
263 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
264 extensions::ExtensionSystem* extension_system = | 259 extensions::ExtensionSystem* extension_system = |
265 extensions::ExtensionSystem::Get(profile); | 260 extensions::ExtensionSystem::Get(profile); |
266 ExtensionService* extension_service = extension_system->extension_service(); | 261 ExtensionService* extension_service = extension_system->extension_service(); |
267 if (extension_service->GetExtensionById(extension_id, false)) | 262 if (extension_service->GetExtensionById(extension_id, false)) |
268 return false; | 263 return false; |
269 const std::string loaded_extension_id = | 264 const std::string loaded_extension_id = |
270 GetComponentLoader()->Add(manifest, file_path); | 265 GetComponentLoader(profile)->Add(manifest, file_path); |
271 DCHECK_EQ(loaded_extension_id, extension_id); | 266 DCHECK_EQ(loaded_extension_id, extension_id); |
272 return true; | 267 return true; |
273 } | 268 } |
274 | 269 |
275 void ComponentExtensionIMEManagerImpl::Unload(const std::string& extension_id, | 270 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, |
| 271 const std::string& extension_id, |
276 const base::FilePath& file_path) { | 272 const base::FilePath& file_path) { |
277 // Remove(extension_id) does nothing when the extension has already been | 273 // Remove(extension_id) does nothing when the extension has already been |
278 // removed or not been registered. | 274 // removed or not been registered. |
279 GetComponentLoader()->Remove(extension_id); | 275 GetComponentLoader(profile)->Remove(extension_id); |
280 } | 276 } |
281 | 277 |
282 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( | 278 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( |
283 const std::string& manifest_string) { | 279 const std::string& manifest_string) { |
284 std::string error; | 280 std::string error; |
285 JSONStringValueSerializer serializer(manifest_string); | 281 JSONStringValueSerializer serializer(manifest_string); |
286 scoped_ptr<base::Value> manifest(serializer.Deserialize(NULL, &error)); | 282 scoped_ptr<base::Value> manifest(serializer.Deserialize(NULL, &error)); |
287 if (!manifest.get()) | 283 if (!manifest.get()) |
288 LOG(ERROR) << "Failed at getting manifest"; | 284 LOG(ERROR) << "Failed at getting manifest"; |
289 | 285 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 444 |
449 ComponentExtensionEngine engine; | 445 ComponentExtensionEngine engine; |
450 ReadEngineComponent(component_ime, *dictionary, &engine); | 446 ReadEngineComponent(component_ime, *dictionary, &engine); |
451 component_ime.engines.push_back(engine); | 447 component_ime.engines.push_back(engine); |
452 } | 448 } |
453 out_imes->push_back(component_ime); | 449 out_imes->push_back(component_ime); |
454 } | 450 } |
455 } | 451 } |
456 | 452 |
457 } // namespace chromeos | 453 } // namespace chromeos |
OLD | NEW |