blob: f7fce2ea277a061c5973474f9159f0f68b47bfae [file] [log] [blame]
[email protected]ffc44872011-04-06 12:01:431// 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]ffc44872011-04-06 12:01:4319#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]ffc44872011-04-06 12:01:4328class ExtensionAppProvider : public AutocompleteProvider,
29 public NotificationObserver {
30 public:
31 ExtensionAppProvider(ACProviderListener* listener, Profile* profile);
32
[email protected]7d70f4e2011-04-07 09:43:3933 // Only used for testing.
[email protected]24d692aa2011-05-25 23:07:5834 void AddExtensionAppForTesting(const string16& app_name,
35 const string16& url);
[email protected]7d70f4e2011-04-07 09:43:3936
[email protected]ffc44872011-04-06 12:01:4337 // 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]24d692aa2011-05-25 23:07:5843 typedef std::pair<string16, string16> ExtensionApp;
[email protected]ffc44872011-04-06 12:01:4344 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]ffc44872011-04-06 12:01:4354 // 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]432115822011-07-10 15:52:2761 virtual void Observe(int type,
[email protected]ffc44872011-04-06 12:01:4362 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_