File: category.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (107 lines) | stat: -rw-r--r-- 3,625 bytes parent folder | download
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
// Copyright 2016 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_CATEGORY_H_
#define COMPONENTS_NTP_SNIPPETS_CATEGORY_H_

#include <ostream>

namespace ntp_snippets {

// These are the categories that the client knows about.
// The values before LOCAL_CATEGORIES_COUNT are the categories that are provided
// locally on the device. Categories provided by the server (IDs strictly larger
// than REMOTE_CATEGORIES_OFFSET) only need to be hard-coded here if they need
// to be recognized by the client implementation.
// NOTE: These are persisted, so don't reorder or remove values, and insert new
// values only in the appropriate places marked below.
// On Android builds, a Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets
enum class KnownCategories {
  // Pages recently downloaded during normal navigation.
  RECENT_TABS,

  // Pages downloaded by the user for offline consumption.
  DOWNLOADS,

  // Recently used bookmarks.
  BOOKMARKS,

  // Physical Web page available in the vicinity.
  PHYSICAL_WEB_PAGES,

  // Pages recently browsed to on other devices.
  FOREIGN_TABS,
  // INSERT NEW LOCAL CATEGORIES HERE!

  // Follows the last local category.
  LOCAL_CATEGORIES_COUNT,

  // Remote categories come after this.
  REMOTE_CATEGORIES_OFFSET = 10000,

  // Articles for you.
  ARTICLES,
  // INSERT NEW REMOTE CATEGORIES HERE!

  // Tracks the last known remote category
  LAST_KNOWN_REMOTE_CATEGORY = ARTICLES,
};

// A category groups ContentSuggestions which belong together. Use the
// CategoryFactory to obtain instances.
class Category {
 public:
  // An arbitrary but consistent ordering. Can be used to look up categories in
  // a std::map, but should not be used to order categories for other purposes.
  struct CompareByID;

  // Creates a category from a KnownCategory value. The passed |known_category|
  // must not be one of the special values (LOCAL_CATEGORIES_COUNT or
  // REMOTE_CATEGORIES_OFFSET).
  static Category FromKnownCategory(KnownCategories known_category);

  // Creates a category from a category identifier delivered by the server.
  // |remote_category| must be positive.
  static Category FromRemoteCategory(int remote_category);

  // Creates a category from an ID as returned by |id()|. |id| must be a
  // non-negative value. Callers should make sure this is a valid id (if in
  // doubt, call IsValidIDValue()).
  static Category FromIDValue(int id);

  // Verifies if |id| is a valid ID value. Only checks that the value is within
  // a valid range -- not that the system actually knows about the corresponding
  // category.
  static bool IsValidIDValue(int id);

  // Returns a non-negative identifier that is unique for the category and can
  // be converted back to a Category instance using
  // |CategoryFactory::FromIDValue(id)|.
  int id() const { return id_; }

  // Returns whether this category matches the given |known_category|.
  bool IsKnownCategory(KnownCategories known_category) const;

 private:
  explicit Category(int id);

  int id_;

  // Allow copy and assignment.
};

bool operator==(const Category& left, const Category& right);

bool operator!=(const Category& left, const Category& right);

struct Category::CompareByID {
  bool operator()(const Category& left, const Category& right) const;
};

std::ostream& operator<<(std::ostream& os, const Category& obj);

}  // namespace ntp_snippets

#endif  // COMPONENTS_NTP_SNIPPETS_CATEGORY_H_