1 // Copyright (c) 2012 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_WEBUI_NTP_SUGGESTIONS_SOURCE_H_ 6 #define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_H_ 7 8 #include "base/basictypes.h" 9 10 class Profile; 11 class SuggestionsCombiner; 12 13 namespace base { 14 class DictionaryValue; 15 } 16 17 // Interface for a source of suggested pages. The various sources will be 18 // combined by the SuggestionsCombiner. 19 class SuggestionsSource { 20 21 public: 22 virtual ~SuggestionsSource() {} 23 24 protected: 25 SuggestionsSource() {} 26 27 friend class SuggestionsCombiner; 28 29 // Enables or disables debug mode for the current source. The source is 30 // expected to provide additional data when debug mode is enabled. 31 virtual void SetDebug(bool enable) = 0; 32 33 // The source's weight indicates how many items from this source will be 34 // selected by the combiner. If a source weight is x and the total weight of 35 // all the sources is y, then the combiner will select x/y items from it. 36 virtual int GetWeight() = 0; 37 38 // Returns the number of items this source can produce. 39 virtual int GetItemCount() = 0; 40 41 // Removes the most important item from this source and returns it. The 42 // returned item must be in the right format to be sent to the javascript, 43 // which you typically get by calling NewTabUI::SetUrlTitleAndDirection. If 44 // the source is empty this method returns null. 45 // The caller takes ownership of the returned item. 46 virtual base::DictionaryValue* PopItem() = 0; 47 48 // Requests that the source fetch its items. If the source is already fetching 49 // it does not have to reset and can continue fetching. 50 virtual void FetchItems(Profile* profile) = 0; 51 52 // Sets the combiner holding this suggestion source. This method can only 53 // be called once. 54 virtual void SetCombiner(SuggestionsCombiner* combiner) = 0; 55 56 private: 57 DISALLOW_COPY_AND_ASSIGN(SuggestionsSource); 58 }; 59 60 #endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_H_ 61