File: category.h

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (125 lines) | stat: -rw-r--r-- 4,253 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// 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_DEPRECATED,

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

  // Recently used bookmarks.
  BOOKMARKS,

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

  // Pages recently browsed to on other devices.
  FOREIGN_TABS,

  // Pages from the user reading list.
  READING_LIST,

  // Contextual suggestion.
  CONTEXTUAL,

  // ****************** INSERT NEW LOCAL CATEGORIES HERE! ******************
  // Existing categories are persisted and they must never be removed. This may
  // happen implicitly, e.g. when an older version without some local category
  // is installed.

  // Follows the last local category.
  LOCAL_CATEGORIES_COUNT,

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

  // Articles for you.
  ARTICLES = 10001,

  // Categories 10002-10008 are defined on the server.

  // ****************** INSERT NEW REMOTE CATEGORIES HERE! ******************
  // Update the list on the server first. Here specify the ID explicitly.

  // 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 a remote category identifier. Do not call for non-remote
  // categories.
  int remote_id() const;

  // 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_