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 <string> | |
20 #include <utility> | 19 #include <utility> |
21 #include <vector> | 20 #include <vector> |
22 | 21 |
23 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
24 #include "chrome/browser/autocomplete/autocomplete.h" | 23 #include "chrome/browser/autocomplete/autocomplete.h" |
25 #include "chrome/browser/autocomplete/autocomplete_match.h" | 24 #include "chrome/browser/autocomplete/autocomplete_match.h" |
26 #include "content/common/notification_observer.h" | 25 #include "content/common/notification_observer.h" |
27 #include "content/common/notification_registrar.h" | 26 #include "content/common/notification_registrar.h" |
28 | 27 |
29 class TemplateURLModel; | 28 class TemplateURLModel; |
30 | 29 |
31 class ExtensionAppProvider : public AutocompleteProvider, | 30 class ExtensionAppProvider : public AutocompleteProvider, |
32 public NotificationObserver { | 31 public NotificationObserver { |
33 public: | 32 public: |
34 ExtensionAppProvider(ACProviderListener* listener, Profile* profile); | 33 ExtensionAppProvider(ACProviderListener* listener, Profile* profile); |
35 | 34 |
36 // Only used for testing. | 35 // Only used for testing. |
37 void AddExtensionAppForTesting(const std::string& app_name, | 36 void AddExtensionAppForTesting(const string16& app_name, |
38 const std::string url); | 37 const string16& url); |
39 | 38 |
40 // AutocompleteProvider implementation: | 39 // AutocompleteProvider implementation: |
41 virtual void Start(const AutocompleteInput& input, | 40 virtual void Start(const AutocompleteInput& input, |
42 bool minimal_changes) OVERRIDE; | 41 bool minimal_changes) OVERRIDE; |
43 | 42 |
44 private: | 43 private: |
45 // An ExtensionApp is a pair of Extension Name and the Launch URL. | 44 // An ExtensionApp is a pair of Extension Name and the Launch URL. |
46 typedef std::pair<std::string, std::string> ExtensionApp; | 45 typedef std::pair<string16, string16> ExtensionApp; |
47 typedef std::vector<ExtensionApp> ExtensionApps; | 46 typedef std::vector<ExtensionApp> ExtensionApps; |
48 | 47 |
49 virtual ~ExtensionAppProvider(); | 48 virtual ~ExtensionAppProvider(); |
50 | 49 |
51 // Fetch the current app list and cache it locally. | 50 // Fetch the current app list and cache it locally. |
52 void RefreshAppList(); | 51 void RefreshAppList(); |
53 | 52 |
54 // Register for install/uninstall notification so we can update our cache. | 53 // Register for install/uninstall notification so we can update our cache. |
55 void RegisterForNotifications(); | 54 void RegisterForNotifications(); |
56 | 55 |
57 // Highlights a certain part of a match string within a certain match class. | |
58 // |input| is the input we got from the user, |match_class| is the | |
59 // AutoComplete match classification that keeps track of the highlighting | |
60 // values, and |iter| is the location of the user input found within | |
61 // |match_string|. | |
62 void HighlightMatch(const AutocompleteInput& input, | |
63 ACMatchClassifications* match_class, | |
64 std::string::const_iterator iter, | |
65 const std::string& match_string); | |
66 | |
67 // Calculate the relevance of the match. | 56 // Calculate the relevance of the match. |
68 int CalculateRelevance(AutocompleteInput::Type type, | 57 int CalculateRelevance(AutocompleteInput::Type type, |
69 int input_length, | 58 int input_length, |
70 int target_length, | 59 int target_length, |
71 const GURL& url); | 60 const GURL& url); |
72 | 61 |
73 // NotificationObserver implementation: | 62 // NotificationObserver implementation: |
74 virtual void Observe(NotificationType type, | 63 virtual void Observe(NotificationType type, |
75 const NotificationSource& source, | 64 const NotificationSource& source, |
76 const NotificationDetails& details) OVERRIDE; | 65 const NotificationDetails& details) OVERRIDE; |
77 | 66 |
78 NotificationRegistrar registrar_; | 67 NotificationRegistrar registrar_; |
79 | 68 |
80 // Our cache of ExtensionApp objects (name + url) representing the extension | 69 // Our cache of ExtensionApp objects (name + url) representing the extension |
81 // apps we know about. | 70 // apps we know about. |
82 ExtensionApps extension_apps_; | 71 ExtensionApps extension_apps_; |
83 | 72 |
84 DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider); | 73 DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider); |
85 }; | 74 }; |
86 | 75 |
87 #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ | 76 #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
OLD | NEW |