summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/ntp/suggestions_source.h
blob: 10ef8d827c44c5398075d82f9284edcf7e31fcca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_H_
#pragma once

#include "base/basictypes.h"

class Profile;
class SuggestionsCombiner;

namespace base {
class DictionaryValue;
}

// Interface for a source of suggested pages. The various sources will be
// combined by the SuggestionsCombiner.
class SuggestionsSource {

 public:
  virtual ~SuggestionsSource() {}

 protected:
  SuggestionsSource() {}

  friend class SuggestionsCombiner;

  // Enables or disables debug mode for the current source. The source is
  // expected to provide additional data when debug mode is enabled.
  virtual void SetDebug(bool enable) = 0;

  // The source's weight indicates how many items from this source will be
  // selected by the combiner. If a source weight is x and the total weight of
  // all the sources is y, then the combiner will select x/y items from it.
  virtual int GetWeight() = 0;

  // Returns the number of items this source can produce.
  virtual int GetItemCount() = 0;

  // Removes the most important item from this source and returns it. The
  // returned item must be in the right format to be sent to the javascript,
  // which you typically get by calling NewTabUI::SetURLTitleAndDirection. If
  // the source is empty this method returns null.
  // The caller takes ownership of the returned item.
  virtual base::DictionaryValue* PopItem() = 0;

  // Requests that the source fetch its items. If the source is already fetching
  // it does not have to reset and can continue fetching.
  virtual void FetchItems(Profile* profile) = 0;

  // Sets the combiner holding this suggestion source. This method can only
  // be called once.
  virtual void SetCombiner(SuggestionsCombiner* combiner) = 0;

 private:
  DISALLOW_COPY_AND_ASSIGN(SuggestionsSource);
};

#endif  // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_H_