Home | History | Annotate | Download | only in search
      1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_CHROME_SEARCH_RESULT_H_
      6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_CHROME_SEARCH_RESULT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "ui/app_list/search_result.h"
     12 
     13 namespace app_list {
     14 
     15 // The type of the search result. This is used for logging so do not change the
     16 // order of this enum.
     17 enum ChromeSearchResultType {
     18   // A result that forwards an omnibox search result.
     19   OMNIBOX_SEARCH_RESULT,
     20   // An app result.
     21   APP_SEARCH_RESULT,
     22   // A search result from the webstore.
     23   WEBSTORE_SEARCH_RESULT,
     24   // A result that opens a webstore search.
     25   SEARCH_WEBSTORE_SEARCH_RESULT,
     26   SEARCH_RESULT_TYPE_BOUNDARY
     27 };
     28 
     29 // Base class of all search results. It provides an additional interface
     30 // for SearchController to mix the results, duplicate a result from a
     31 // SearchProvider and pass it to UI and invoke actions on the results when
     32 // underlying  UI is activated.
     33 class ChromeSearchResult : public SearchResult {
     34  public:
     35   ChromeSearchResult() : relevance_(0.0) {}
     36   virtual ~ChromeSearchResult() {}
     37 
     38   // Opens the result.
     39   virtual void Open(int event_flags) = 0;
     40 
     41   // Invokes a custom action on the result.
     42   virtual void InvokeAction(int action_index, int event_flags) = 0;
     43 
     44   // Creates a copy of the result.
     45   virtual scoped_ptr<ChromeSearchResult> Duplicate() = 0;
     46 
     47   virtual ChromeSearchResultType GetType() = 0;
     48 
     49   const std::string& id() const { return id_; }
     50   double relevance() { return relevance_; }
     51 
     52  protected:
     53   void set_id(const std::string& id) { id_ = id; }
     54   void set_relevance(double relevance) { relevance_ = relevance; }
     55 
     56  private:
     57   std::string id_;
     58   double relevance_;
     59 
     60   DISALLOW_COPY_AND_ASSIGN(ChromeSearchResult);
     61 };
     62 
     63 }  // namespace app_list
     64 
     65 #endif  // CHROME_BROWSER_UI_APP_LIST_SEARCH_CHROME_SEARCH_RESULT_H_
     66