summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/page_usage_data.h
blob: b4e62fea18697d4f6d947b5a0431d4f10ca866c3 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) 2006-2008 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_HISTORY_PAGE_USAGE_DATA_H__
#define CHROME_BROWSER_HISTORY_PAGE_USAGE_DATA_H__

#include "SkBitmap.h"

#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_types.h"
#include "googleurl/src/gurl.h"

/////////////////////////////////////////////////////////////////////////////
//
// PageUsageData
//
// A per domain usage data structure to compute and manage most visited
// pages.
//
// See History::QueryPageUsageSince()
//
/////////////////////////////////////////////////////////////////////////////
class PageUsageData {
 public:
  PageUsageData(history::URLID id)
      : id_(id),
        thumbnail_(NULL),
        thumbnail_set_(false),
        thumbnail_pending_(false),
        favicon_(NULL),
        favicon_set_(false),
        favicon_pending_(false),
        score_(0.0) {
  }

  virtual ~PageUsageData() {
    delete thumbnail_;
    delete favicon_;
  }

  // Return the url ID
  history::URLID GetID() const {
    return id_;
  }

  void SetURL(const GURL& url) {
    url_ = url;
  }

  const GURL& GetURL() const {
    return url_;
  }

  void SetTitle(const std::wstring& s) {
    title_ = s;
  }

  const std::wstring& GetTitle() const {
    return title_;
  }

  void SetScore(double v) {
    score_ = v;
  }

  double GetScore() const {
    return score_;
  }

  void SetThumbnailMissing() {
    thumbnail_set_ = true;
  }

  void SetThumbnail(SkBitmap* img) {
    if (thumbnail_ && thumbnail_ != img)
      delete thumbnail_;

    thumbnail_ = img;
    thumbnail_set_ = true;
  }

  bool HasThumbnail() const {
    return thumbnail_set_;
  }

  const SkBitmap* GetThumbnail() const {
    return thumbnail_;
  }

  bool thumbnail_pending() const {
    return thumbnail_pending_;
  }

  void set_thumbnail_pending(bool pending) {
    thumbnail_pending_ = pending;
  }

  void SetFavIconMissing() {
    favicon_set_ = true;
  }

  void SetFavIcon(SkBitmap* img) {
    if (favicon_ && favicon_ != img)
      delete favicon_;
    favicon_ = img;
    favicon_set_ = true;
  }

  bool HasFavIcon() const {
    return favicon_set_;
  }

  bool favicon_pending() const {
    return favicon_pending_;
  }

  void set_favicon_pending(bool pending) {
    favicon_pending_ = pending;
  }

  const SkBitmap* GetFavIcon() const {
    return favicon_;
  }

  // Sort predicate to sort instances by score (high to low)
  static bool Predicate(const PageUsageData* dud1,
                        const PageUsageData* dud2);

 private:
  history::URLID id_;
  GURL url_;
  std::wstring title_;

  SkBitmap* thumbnail_;
  bool thumbnail_set_;
  // Whether we have an outstanding request for the thumbnail.
  bool thumbnail_pending_;

  SkBitmap* favicon_;
  bool favicon_set_;
  // Whether we have an outstanding request for the favicon.
  bool favicon_pending_;

  double score_;
};

#endif  // CHROME_BROWSER_HISTORY_PAGE_USAGE_DATA_H__