summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h
blob: d59ba5b8e7883f70628a14e6699a311607e9043f (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
62
63
64
65
// 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_TOP_SITES_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_TOP_SITES_H_
#pragma once

#include <deque>

#include "base/basictypes.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/visit_filter.h"
#include "chrome/browser/ui/webui/ntp/suggestions_source.h"

class SuggestionsCombiner;
class Profile;

namespace base {
class DictionaryValue;
}

// A SuggestionsSource that uses the local TopSites database to provide
// suggestions.
class SuggestionsSourceTopSites : public SuggestionsSource {
 public:
  SuggestionsSourceTopSites();
  virtual ~SuggestionsSourceTopSites();

 protected:
  // SuggestionsSource overrides:
  virtual int GetWeight() OVERRIDE;
  virtual int GetItemCount() OVERRIDE;
  virtual base::DictionaryValue* PopItem() OVERRIDE;
  virtual void FetchItems(Profile* profile) OVERRIDE;
  virtual void SetCombiner(SuggestionsCombiner* combiner) OVERRIDE;

  void OnSuggestionsURLsAvailable(
      CancelableRequestProvider::Handle handle,
      const history::FilteredURLList& data);

 private:

  // Gets the sorting order from the command-line arguments. Defaults to
  // |ORDER_BY_RECENCY| if there are no command-line argument specifying a
  // sorting order.
  static history::VisitFilter::SortingOrder GetSortingOrder();

  // Gets the filter width from the command-line arguments. Defaults to one
  // hour if there are no command-line argument setting the filter width.
  static base::TimeDelta GetFilterWidth();

  // Our combiner.
  SuggestionsCombiner* combiner_;

  // Keep the results of the db query here.
  std::deque<base::DictionaryValue*> items_;

  CancelableRequestConsumer history_consumer_;

  DISALLOW_COPY_AND_ASSIGN(SuggestionsSourceTopSites);
};

#endif  // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_SOURCE_TOP_SITES_H_