[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 5 | // |
| 6 | // This file contains the Extension App autocomplete provider. The provider |
| 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 |
| 9 | // controller. |
| 10 | // |
| 11 | // For more information on the autocomplete system in general, including how |
| 12 | // the autocomplete controller and autocomplete providers work, see |
| 13 | // chrome/browser/autocomplete.h. |
| 14 | |
| 15 | #ifndef CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
| 16 | #define CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |
| 17 | #pragma once |
| 18 | |
[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 19 | #include <utility> |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "base/compiler_specific.h" |
| 23 | #include "chrome/browser/autocomplete/autocomplete.h" |
| 24 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 25 | #include "content/common/notification_observer.h" |
| 26 | #include "content/common/notification_registrar.h" |
| 27 | |
[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 28 | class ExtensionAppProvider : public AutocompleteProvider, |
| 29 | public NotificationObserver { |
| 30 | public: |
| 31 | ExtensionAppProvider(ACProviderListener* listener, Profile* profile); |
| 32 | |
[email protected] | 7d70f4e | 2011-04-07 09:43:39 | [diff] [blame] | 33 | // Only used for testing. |
[email protected] | 24d692aa | 2011-05-25 23:07:58 | [diff] [blame] | 34 | void AddExtensionAppForTesting(const string16& app_name, |
| 35 | const string16& url); |
[email protected] | 7d70f4e | 2011-04-07 09:43:39 | [diff] [blame] | 36 | |
[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 37 | // AutocompleteProvider implementation: |
| 38 | virtual void Start(const AutocompleteInput& input, |
| 39 | bool minimal_changes) OVERRIDE; |
| 40 | |
| 41 | private: |
| 42 | // An ExtensionApp is a pair of Extension Name and the Launch URL. |
[email protected] | 24d692aa | 2011-05-25 23:07:58 | [diff] [blame] | 43 | typedef std::pair<string16, string16> ExtensionApp; |
[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 44 | typedef std::vector<ExtensionApp> ExtensionApps; |
| 45 | |
| 46 | virtual ~ExtensionAppProvider(); |
| 47 | |
| 48 | // Fetch the current app list and cache it locally. |
| 49 | void RefreshAppList(); |
| 50 | |
| 51 | // Register for install/uninstall notification so we can update our cache. |
| 52 | void RegisterForNotifications(); |
| 53 | |
[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 54 | // Calculate the relevance of the match. |
| 55 | int CalculateRelevance(AutocompleteInput::Type type, |
| 56 | int input_length, |
| 57 | int target_length, |
| 58 | const GURL& url); |
| 59 | |
| 60 | // NotificationObserver implementation: |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 61 | virtual void Observe(int type, |
[email protected] | ffc4487 | 2011-04-06 12:01:43 | [diff] [blame] | 62 | const NotificationSource& source, |
| 63 | const NotificationDetails& details) OVERRIDE; |
| 64 | |
| 65 | NotificationRegistrar registrar_; |
| 66 | |
| 67 | // Our cache of ExtensionApp objects (name + url) representing the extension |
| 68 | // apps we know about. |
| 69 | ExtensionApps extension_apps_; |
| 70 | |
| 71 | DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider); |
| 72 | }; |
| 73 | |
| 74 | #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_ |