Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/chromeos/launcher_search_provider/service.h

Issue 1137603005: Cache listener extension ids. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/launcher_search_provider/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h" 9 #include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/api/launcher_search_provider.h" 11 #include "chrome/common/extensions/api/launcher_search_provider.h"
12 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 #include "extensions/browser/event_router.h" 14 #include "extensions/browser/event_router.h"
15 #include "extensions/browser/extension_registry_observer.h"
15 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
16 17
17 namespace app_list { 18 namespace app_list {
18 class LauncherSearchProvider; 19 class LauncherSearchProvider;
19 } // namespace app_list 20 } // namespace app_list
20 21
21 namespace chromeos { 22 namespace chromeos {
22 namespace launcher_search_provider { 23 namespace launcher_search_provider {
23 24
24 // Relevance score should be provided in a range from 0 to 4. 0 is the lowest 25 // Relevance score should be provided in a range from 0 to 4. 0 is the lowest
25 // relevance, 4 is the highest. 26 // relevance, 4 is the highest.
26 const int kMaxSearchResultScore = 4; 27 const int kMaxSearchResultScore = 4;
27 28
28 // Manages listener extensions and routes events. Listener extensions are 29 // Manages listener extensions and routes events. Listener extensions are
29 // extensions which are allowed to use this API. When this API becomes public, 30 // extensions which are allowed to use this API. When this API becomes public,
30 // this API is white listed for file manager, and opt-in for other extensions. 31 // this API is white listed for file manager, and opt-in for other extensions.
31 // This service provides access control for it. 32 // This service provides access control for it.
32 // 33 //
33 // TODO(yawano): Implement opt-in control (crbug.com/440649). 34 // TODO(yawano): Implement opt-in control (crbug.com/440649).
34 class Service : public KeyedService { 35 class Service : public KeyedService,
36 public extensions::ExtensionRegistryObserver {
35 public: 37 public:
36 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); 38 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry);
37 ~Service() override; 39 ~Service() override;
38 static Service* Get(content::BrowserContext* context); 40 static Service* Get(content::BrowserContext* context);
39 41
40 // Dispatches onQueryStarted events to listener extensions. 42 // Dispatches onQueryStarted events to listener extensions.
41 void OnQueryStarted(app_list::LauncherSearchProvider* provider, 43 void OnQueryStarted(app_list::LauncherSearchProvider* provider,
42 const std::string& query, 44 const std::string& query,
43 const int max_result); 45 const int max_result);
44 46
45 // Dispatches onQueryEnded events to listener extensions. 47 // Dispatches onQueryEnded events to listener extensions.
46 void OnQueryEnded(); 48 void OnQueryEnded();
47 49
48 // Dispatches onOpenResult event of |item_id| to |extension_id|. 50 // Dispatches onOpenResult event of |item_id| to |extension_id|.
49 void OnOpenResult(const extensions::ExtensionId& extension_id, 51 void OnOpenResult(const extensions::ExtensionId& extension_id,
50 const std::string& item_id); 52 const std::string& item_id);
51 53
52 // Sets search results of a listener extension. 54 // Sets search results of a listener extension.
53 void SetSearchResults( 55 void SetSearchResults(
54 const extensions::Extension* extension, 56 const extensions::Extension* extension,
55 scoped_ptr<ErrorReporter> error_reporter, 57 scoped_ptr<ErrorReporter> error_reporter,
56 const int query_id, 58 const int query_id,
57 const std::vector<linked_ptr< 59 const std::vector<linked_ptr<
58 extensions::api::launcher_search_provider::SearchResult>>& results); 60 extensions::api::launcher_search_provider::SearchResult>>& results);
59 61
60 // Returns true if there is a running query. 62 // Returns true if there is a running query.
61 bool IsQueryRunning() const; 63 bool IsQueryRunning() const;
62 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
63 private: 73 private:
64 // Returns extension ids of listener extensions. 74 // Cache listener extension ids and set them to
65 std::set<extensions::ExtensionId> GetListenerExtensionIds(); 75 // |cached_listener_extension_ids_|.
76 void CacheListenerExtensionIds();
66 77
67 Profile* const profile_; 78 Profile* const profile_;
68 extensions::ExtensionRegistry* extension_registry_; 79 extensions::ExtensionRegistry* extension_registry_;
69 app_list::LauncherSearchProvider* provider_; 80 app_list::LauncherSearchProvider* provider_;
70 int query_id_; 81 int query_id_;
71 bool is_query_running_; 82 bool is_query_running_;
83 scoped_ptr<std::set<extensions::ExtensionId>> cached_listener_extension_ids_;
72 84
73 DISALLOW_COPY_AND_ASSIGN(Service); 85 DISALLOW_COPY_AND_ASSIGN(Service);
74 }; 86 };
75 87
76 } // namespace launcher_search_provider 88 } // namespace launcher_search_provider
77 } // namespace chromeos 89 } // namespace chromeos
78 90
79 #endif // CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_ 91 #endif // CHROME_BROWSER_CHROMEOS_LAUNCHER_SEARCH_PROVIDER_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/launcher_search_provider/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698