summaryrefslogtreecommitdiffstats
path: root/components/ntp_snippets/ntp_snippet.h
blob: 8767a7bd9ba3f1ef451ab0f22d42a11cc056225c (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
// Copyright 2015 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 COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_
#define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_

#include <memory>
#include <string>

#include "base/macros.h"
#include "base/time/time.h"
#include "url/gurl.h"

namespace base {
class DictionaryValue;
}

namespace ntp_snippets {

// Stores and vend fresh content data for the NTP. This is a dumb class with no
// smarts at all, all the logic is in the service.
class NTPSnippet {
 public:
  // Creates a new snippet with the given URL. URL must be valid.
  NTPSnippet(const GURL& url);

  ~NTPSnippet();

  // Creates an NTPSnippet from a dictionary. Returns a null pointer if the
  // dictionary doesn't contain at least a url.
  static std::unique_ptr<NTPSnippet> NTPSnippetFromDictionary(
      const base::DictionaryValue& dict);

  // URL of the page described by this snippet.
  const GURL& url() const { return url_; }

  // Subtitle to identify the site the snippet is from.
  const std::string& site_title() const { return site_title_; }
  void set_site_title(const std::string& site_title) {
    site_title_ = site_title;
  }

  // Favicon for the site. Do not use to directly retrieve the favicon.
  const GURL& favicon_url() const { return favicon_url_; }
  void set_favicon_url(const GURL& favicon_url) { favicon_url_ = favicon_url; }

  // Title of the snippet.
  const std::string& title() const { return title_; }
  void set_title(const std::string& title) { title_ = title; }

  // Summary or relevant extract from the content.
  const std::string& snippet() const { return snippet_; }
  void set_snippet(const std::string& snippet) { snippet_ = snippet; }

  // Link to an image representative of the content. Do not fetch this image
  // directly.
  const GURL& salient_image_url() const { return salient_image_url_; }
  void set_salient_image_url(const GURL& salient_image_url) {
    salient_image_url_ = salient_image_url;
  }

  // When the page pointed by this snippet was published.
  const base::Time& publish_date() const { return publish_date_; }
  void set_publish_date(const base::Time& publish_date) {
    publish_date_ = publish_date;
  }

  // After this expiration date this snippet should no longer be presented to
  // the user.
  const base::Time& expiry_date() const { return expiry_date_; }
  void set_expiry_date(const base::Time& expiry_date) {
    expiry_date_ = expiry_date;
  }

 private:
  const GURL url_;
  std::string site_title_;
  std::string title_;
  GURL favicon_url_;
  GURL salient_image_url_;
  std::string snippet_;
  base::Time publish_date_;
  base::Time expiry_date_;

  DISALLOW_COPY_AND_ASSIGN(NTPSnippet);
};

}  // namespace ntp_snippets

#endif  // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPET_H_