OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // | 5 // |
6 // This file contains the Extension App autocomplete provider. The provider | 6 // This file contains the Extension App autocomplete provider. The provider |
7 // is responsible for keeping track of which Extension Apps are installed and | 7 // is responsible for keeping track of which Extension Apps are installed and |
8 // their URLs. An instance of it gets created and managed by the autocomplete | 8 // their URLs. An instance of it gets created and managed by the autocomplete |
9 // controller. | 9 // controller. |
10 // | 10 // |
11 // For more information on the autocomplete system in general, including how | 11 // For more information on the autocomplete system in general, including how |
12 // the autocomplete controller and autocomplete providers work, see | 12 // the autocomplete controller and autocomplete providers work, see |
13 // chrome/browser/autocomplete.h. | 13 // chrome/browser/autocomplete.h. |
14 | 14 |
15 #ifndef CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ | 15 #ifndef CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
16 #define CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ | 16 #define CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
17 #pragma once | 17 #pragma once |
18 | 18 |
19 #include <utility> | 19 #include <utility> |
20 #include <vector> | 20 #include <vector> |
21 | 21 |
22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
| 23 #include "base/gtest_prod_util.h" |
23 #include "chrome/browser/autocomplete/autocomplete.h" | 24 #include "chrome/browser/autocomplete/autocomplete.h" |
24 #include "chrome/browser/autocomplete/autocomplete_match.h" | 25 #include "chrome/browser/autocomplete/autocomplete_match.h" |
25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
27 | 28 |
28 class ExtensionAppProvider : public AutocompleteProvider, | 29 class ExtensionAppProvider : public AutocompleteProvider, |
29 public content::NotificationObserver { | 30 public content::NotificationObserver { |
30 public: | 31 public: |
31 ExtensionAppProvider(ACProviderListener* listener, Profile* profile); | 32 ExtensionAppProvider(ACProviderListener* listener, Profile* profile); |
32 | 33 |
33 // Only used for testing. | 34 // Only used for testing. |
34 void AddExtensionAppForTesting(const string16& app_name, | 35 void AddExtensionAppForTesting(const string16& app_name, |
35 const string16& url); | 36 const string16& url); |
36 | 37 |
37 // AutocompleteProvider implementation: | 38 // AutocompleteProvider implementation: |
38 virtual void Start(const AutocompleteInput& input, | 39 virtual void Start(const AutocompleteInput& input, |
39 bool minimal_changes) OVERRIDE; | 40 bool minimal_changes) OVERRIDE; |
40 | 41 |
41 private: | 42 private: |
42 // An ExtensionApp is a pair of Extension Name and the Launch URL. | 43 // An ExtensionApp is a pair of Extension Name and the Launch URL. |
43 typedef std::pair<string16, string16> ExtensionApp; | 44 typedef std::pair<string16, string16> ExtensionApp; |
44 typedef std::vector<ExtensionApp> ExtensionApps; | 45 typedef std::vector<ExtensionApp> ExtensionApps; |
45 | 46 |
46 virtual ~ExtensionAppProvider(); | 47 virtual ~ExtensionAppProvider(); |
47 | 48 |
| 49 // Construct a match for the specified parameters. |
| 50 AutocompleteMatch CreateAutocompleteMatch(const AutocompleteInput& input, |
| 51 const string16& name, |
| 52 const string16& url, |
| 53 size_t name_match_index, |
| 54 size_t url_match_index); |
| 55 |
48 // Fetch the current app list and cache it locally. | 56 // Fetch the current app list and cache it locally. |
49 void RefreshAppList(); | 57 void RefreshAppList(); |
50 | 58 |
51 // Register for install/uninstall notification so we can update our cache. | 59 // Register for install/uninstall notification so we can update our cache. |
52 void RegisterForNotifications(); | 60 void RegisterForNotifications(); |
53 | 61 |
54 // Calculate the relevance of the match. | 62 // Calculate the relevance of the match. |
55 int CalculateRelevance(AutocompleteInput::Type type, | 63 int CalculateRelevance(AutocompleteInput::Type type, |
56 int input_length, | 64 int input_length, |
57 int target_length, | 65 int target_length, |
58 const GURL& url); | 66 const GURL& url); |
59 | 67 |
60 // content::NotificationObserver implementation: | 68 // content::NotificationObserver implementation: |
61 virtual void Observe(int type, | 69 virtual void Observe(int type, |
62 const content::NotificationSource& source, | 70 const content::NotificationSource& source, |
63 const content::NotificationDetails& details) OVERRIDE; | 71 const content::NotificationDetails& details) OVERRIDE; |
64 | 72 |
65 content::NotificationRegistrar registrar_; | 73 content::NotificationRegistrar registrar_; |
66 | 74 |
67 // Our cache of ExtensionApp objects (name + url) representing the extension | 75 // Our cache of ExtensionApp objects (name + url) representing the extension |
68 // apps we know about. | 76 // apps we know about. |
69 ExtensionApps extension_apps_; | 77 ExtensionApps extension_apps_; |
70 | 78 |
| 79 FRIEND_TEST_ALL_PREFIXES(ExtensionAppProviderTest, CreateMatchSanitize); |
| 80 |
71 DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider); | 81 DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider); |
72 }; | 82 }; |
73 | 83 |
74 #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ | 84 #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
OLD | NEW |