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