| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/common/extensions/api/launcher_search_provider.h" | |
| 12 #include "components/keyed_service/core/keyed_service.h" | |
| 13 #include "content/public/browser/browser_context.h" | |
| 14 #include "extensions/browser/event_router.h" | |
| 15 #include "extensions/browser/extension_registry_observer.h" | |
| 16 #include "extensions/common/extension.h" | |
| 17 | |
| 18 namespace app_list { | |
| 19 class LauncherSearchProvider; | |
| 20 } // namespace app_list | |
| 21 | |
| 22 namespace chromeos { | |
| 23 namespace launcher_search_provider { | |
| 24 | |
| 25 // Relevance score should be provided in a range from 0 to 4. 0 is the lowest | |
| 26 // relevance, 4 is the highest. | |
| 27 const int kMaxSearchResultScore = 4; | |
| 28 | |
| 29 // Manages listener extensions and routes events. Listener extensions are | |
| 30 // extensions which are allowed to use this API. When this API becomes public, | |
| 31 // this API is white listed for file manager, and opt-in for other extensions. | |
| 32 // This service provides access control for it. | |
| 33 // | |
| 34 // TODO(yawano): Implement opt-in control (crbug.com/440649). | |
| 35 class Service : public KeyedService, | |
| 36 public extensions::ExtensionRegistryObserver { | |
| 37 public: | |
| 38 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); | |
| 39 ~Service() override; | |
| 40 static Service* Get(content::BrowserContext* context); | |
| 41 | |
| 42 // Dispatches onQueryStarted events to listener extensions. | |
| 43 void OnQueryStarted(app_list::LauncherSearchProvider* provider, | |
| 44 const std::string& query, | |
| 45 const int max_result); | |
| 46 | |
| 47 // Dispatches onQueryEnded events to listener extensions. | |
| 48 void OnQueryEnded(); | |
| 49 | |
| 50 // Dispatches onOpenResult event of |item_id| to |extension_id|. | |
| 51 void OnOpenResult(const extensions::ExtensionId& extension_id, | |
| 52 const std::string& item_id); | |
| 53 | |
| 54 // Sets search results of a listener extension. | |
| 55 void SetSearchResults( | |
| 56 const extensions::Extension* extension, | |
| 57 scoped_ptr<ErrorReporter> error_reporter, | |
| 58 const int query_id, | |
| 59 const std::vector<linked_ptr< | |
| 60 extensions::api::launcher_search_provider::SearchResult>>& results); | |
| 61 | |
| 62 // Returns true if there is a running query. | |
| 63 bool IsQueryRunning() const; | |
| 64 | |
| 65 // extensions::ExtensionRegistryObserver override. | |
| 66 void OnExtensionLoaded(content::BrowserContext* browser_context, | |
| 67 const extensions::Extension* extension) override; | |
| 68 void OnExtensionUnloaded( | |
| 69 content::BrowserContext* browser_context, | |
| 70 const extensions::Extension* extension, | |
| 71 extensions::UnloadedExtensionInfo::Reason reason) override; | |
| 72 | |
| 73 private: | |
| 74 // Cache listener extension ids and set them to | |
| 75 // |cached_listener_extension_ids_|. | |
| 76 void CacheListenerExtensionIds(); | |
| 77 | |
| 78 Profile* const profile_; | |
| 79 extensions::ExtensionRegistry* extension_registry_; | |
| 80 app_list::LauncherSearchProvider* provider_; | |
| 81 int query_id_; | |
| 82 bool is_query_running_; | |
| 83 scoped_ptr<std::set<extensions::ExtensionId>> cached_listener_extension_ids_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(Service); | |
| 86 }; | |
| 87 | |
| 88 } // namespace launcher_search_provider | |
| 89 } // namespace chromeos | |
| 90 | |
| 91 #endif // CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_ | |
| OLD | NEW |