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_IMPL_H_ 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMPL_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 ComponentExtensionIMEManagerDelegate. 21 class ComponentExtensionIMEManagerImpl 22 : public ComponentExtensionIMEManagerDelegate { 23 public: 24 ComponentExtensionIMEManagerImpl(); 25 virtual ~ComponentExtensionIMEManagerImpl(); 26 27 // ComponentExtensionIMEManagerDelegate overrides: 28 virtual std::vector<ComponentExtensionIME> ListIME() OVERRIDE; 29 virtual bool Load(const std::string& extension_id, 30 const std::string& manifest, 31 const base::FilePath& file_path) OVERRIDE; 32 virtual void Unload(const std::string& extension_id, 33 const base::FilePath& file_path) OVERRIDE; 34 35 // Loads extension list and reads their manifest file. After finished 36 // initialization, |callback| will be called on original thread. 37 void InitializeAsync(const base::Closure& callback); 38 39 // Returns true if this class is initialized and ready to use, otherwise 40 // returns false. 41 bool IsInitialized(); 42 43 private: 44 // Reads component extensions and extract their localized information: name, 45 // description and ime id. This function fills them into |out_imes|. This 46 // function must be called on file thread. 47 static void ReadComponentExtensionsInfo( 48 std::vector<ComponentExtensionIME>* out_imes); 49 50 // This function is called on UI thread after ReadComponentExtensionsInfo 51 // function is finished. No need to release |result|. 52 void OnReadComponentExtensionsInfo(std::vector<ComponentExtensionIME>* result, 53 const base::Closure& callback); 54 55 // Reads manifest.json file in |file_path|. This function must be called on 56 // file thread. 57 static scoped_ptr<base::DictionaryValue> GetManifest( 58 const base::FilePath& file_path); 59 60 // Reads extension information: description, option page. This function 61 // returns true on success, otherwise returns false. This function must be 62 // called on file thread. 63 static bool ReadExtensionInfo(const base::DictionaryValue& manifest, 64 const std::string& extension_id, 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( 71 const ComponentExtensionIME& component_extension, 72 const base::DictionaryValue& dict, 73 ComponentExtensionEngine* out); 74 75 // True if initialized. 76 bool is_initialized_; 77 78 // The list of component extension IME. 79 std::vector<ComponentExtensionIME> component_extension_list_; 80 81 // For checking the function should be called on UI thread. 82 base::ThreadChecker thread_checker_; 83 base::WeakPtrFactory<ComponentExtensionIMEManagerImpl> weak_ptr_factory_; 84 85 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManagerImpl); 86 }; 87 88 } // namespace chromeos 89 90 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMPL_H_ 91 92