| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMP
L_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMP
L_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/bind.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/values.h" |
| 16 #include "chromeos/ime/component_extension_ime_manager.h" |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 // The implementation class of ComponentExtentionIMEManagerDelegate. |
| 21 class ComponentExtentionIMEManagerImpl : |
| 22 public ComponentExtentionIMEManagerDelegate { |
| 23 public: |
| 24 ComponentExtentionIMEManagerImpl(); |
| 25 virtual ~ComponentExtentionIMEManagerImpl(); |
| 26 |
| 27 // ComponentExtentionIMEManagerDelegate overrides: |
| 28 virtual std::vector<ComponentExtensionIME> ListIME() OVERRIDE; |
| 29 virtual bool Load(const std::string& extension_id, |
| 30 const base::FilePath& file_path) OVERRIDE; |
| 31 virtual bool Unload(const std::string& extension_id, |
| 32 const base::FilePath& file_path) OVERRIDE; |
| 33 |
| 34 // Loads extension list and reads their manifest file. After finished |
| 35 // initialization, |callback| will be called on original thread. |
| 36 void Initialize( |
| 37 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, |
| 38 const base::Closure& callback); |
| 39 |
| 40 // Returns true if this class is initialized and ready to use, otherwise |
| 41 // returns false. |
| 42 bool IsInitialized(); |
| 43 |
| 44 private: |
| 45 // Reads component extensions and extract their localized information: name, |
| 46 // description and ime id. This function fills them into |out_imes|. This |
| 47 // function must be called on file thread. |
| 48 static void ReadComponentExtensionsInfo( |
| 49 std::vector<ComponentExtensionIME>* out_imes); |
| 50 |
| 51 // This function is called on UI thread after ReadComponentExtensionsInfo |
| 52 // function is finished. No need to release |result|. |
| 53 void OnReadComponentExtensionsInfo(std::vector<ComponentExtensionIME>* result, |
| 54 const base::Closure& callback); |
| 55 |
| 56 // Reads manifest.json file in |file_path|. This function must be called on |
| 57 // file thread. |
| 58 static scoped_ptr<DictionaryValue> GetManifest( |
| 59 const base::FilePath& file_path); |
| 60 |
| 61 // Reads extension information: description, option page. This function |
| 62 // returns true on success, otherwise returns false. This function must be |
| 63 // called on file thread. |
| 64 static bool ReadExtensionInfo(const DictionaryValue& manifest, |
| 65 ComponentExtensionIME* out); |
| 66 |
| 67 // Reads each engine component in |dict|. |dict| is given by GetList with |
| 68 // kInputComponents key from manifest. This function returns true on success, |
| 69 // otherwise retrun false. This function must be called on file thread. |
| 70 static bool ReadEngineComponent(const DictionaryValue& dict, |
| 71 IBusComponent::EngineDescription* out); |
| 72 |
| 73 // True if initialized. |
| 74 bool is_initialized_; |
| 75 |
| 76 // The list of component extension IME. |
| 77 std::vector<ComponentExtensionIME> component_extension_list_; |
| 78 |
| 79 // The list of already loaded extension ids. |
| 80 std::set<std::string> loaded_extension_id_; |
| 81 |
| 82 base::ThreadChecker thread_checker_; |
| 83 base::WeakPtrFactory<ComponentExtentionIMEManagerImpl> weak_ptr_factory_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(ComponentExtentionIMEManagerImpl); |
| 86 }; |
| 87 |
| 88 } // namespace chromeos |
| 89 |
| 90 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_
IMPL_H_ |
| 91 |
| OLD | NEW |