Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: chrome/browser/media/router/issue.h

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/optional.h"
dcheng 2016/12/07 18:58:02 Nit: remove this header, since it's not actually u
imcheng 2016/12/09 23:19:53 Done.
12 #include "chrome/browser/media/router/media_route.h" 13 #include "chrome/browser/media/router/media_route.h"
13 14
14 namespace media_router { 15 namespace media_router {
15 16
16 // The text that corresponds with an action a user can take for a Issue. 17 // Contains the information relevant to an issue.
17 class IssueAction { 18 struct IssueInfo {
18 public: 19 public:
19 enum Type { 20 // Possible actions for an issue.
20 TYPE_DISMISS, 21 enum class Action {
21 TYPE_LEARN_MORE, 22 DISMISS,
22 TYPE_MAX /* Denotes enum value boundary. */ 23 // NOTE: If LEARN_MORE is set as a possible action for an issue, then its
24 // |help_page_id_| must also be set to a valid value.
25 LEARN_MORE,
26
27 // Denotes enum value boundary. New values should be added above.
28 NUM_VALUES
23 }; 29 };
24 30
25 explicit IssueAction(const Type type); 31 // Severity type of an issue. A FATAL issue is considered blocking. Although
26 ~IssueAction(); 32 // issues of other severity levels may also be blocking.
33 enum class Severity { FATAL, WARNING, NOTIFICATION };
27 34
28 Type type() const { return type_; } 35 static const int kUnknownHelpPageId = 0;
29 36
30 bool Equals(const IssueAction& other) const { return type_ == other.type_; } 37 // Used by Mojo only.
38 IssueInfo();
39
40 // |title|: The title for the issue.
41 // |default_action|: Default action user can take to resolve the issue.
42 // |severity|: The severity of the issue. If FATAL, then |is_blocking| is set
43 // to |true|.
44 IssueInfo(const std::string& title,
45 const Action& default_action,
dcheng 2016/12/07 18:58:02 Nit: pass by value is (usually) more efficient her
imcheng 2016/12/09 23:19:53 Done.
46 Severity severity);
47 IssueInfo(const IssueInfo& other);
48 ~IssueInfo();
49
50 IssueInfo& operator=(const IssueInfo& other);
51 bool operator==(const IssueInfo& other) const;
52
53 // Fields set with values provided to the constructor.
54 std::string title;
55 Action default_action;
56 Severity severity;
57
58 // Description message for the issue. Defaults to empty string.
59 std::string message;
60
61 // Options the user can take to resolve the issue in addition to the
62 // default action. Can be empty. If non-empty, currently only one secondary
63 // action is supported.
64 std::vector<Action> secondary_actions;
65
66 // ID of route associated with the Issue, or empty if no route is associated
67 // with it.
68 std::string route_id;
69
70 // |true| if the issue needs to be resolved before continuing. Note that an
71 // Issue is considered blocking if its severity is FATAL, even if
72 // |is_blocking_| is |false|. Defaults to |false|.
73 bool is_blocking;
dcheng 2016/12/07 18:58:02 Why set this as a separate field? Shouldn't this j
imcheng 2016/12/09 23:19:53 We allow supporting blocking non-fatal issues by s
74
75 // ID of help page to link to, if one of the actions is LEARN_MORE.
76 // Defaults to |kUnknownHelpPageId|.
77 int help_page_id;
78 };
79
80 // An issue that is associated with a globally unique ID. Created by
81 // IssueManager when an IssueInfo is added to it.
82 class Issue {
83 public:
84 using Id = int;
85 // ID is generated during construction.
86 explicit Issue(const IssueInfo& info);
87 Issue(const Issue& other) = default;
88 Issue& operator=(const Issue& other) = default;
89 ~Issue();
90
91 const Id& id() const { return id_; }
92 const IssueInfo& info() const { return info_; }
31 93
32 private: 94 private:
33 Type type_; 95 Id id_;
34 }; 96 IssueInfo info_;
35
36 // Contains the information relevant to an issue.
37 class Issue {
38 public:
39 using Id = std::string;
40
41 enum Severity { FATAL, WARNING, NOTIFICATION };
42
43 // Creates a custom issue.
44 // |title|: The title for the issue.
45 // |message|: The optional description message for the issue.
46 // |default_action|: Default action user can take to resolve the issue.
47 // |secondary_actions|: Array of options user can take to resolve the
48 // issue. Can be empty. Currently only one secondary
49 // action is supported.
50 // |route_id|: The route id, or empty if global.
51 // |severity|: The severity of the issue.
52 // |is_blocking|: True if the issue needs to be resolved before continuing.
53 // |help_page_id|: Required if one of the actions is learn-more. Passes in -1
54 // if the issue is not associated with a help page.
55 Issue(const std::string& title,
56 const std::string& message,
57 const IssueAction& default_action,
58 const std::vector<IssueAction>& secondary_actions,
59 const MediaRoute::Id& route_id,
60 const Severity severity,
61 bool is_blocking,
62 int help_page_id);
63
64 Issue(const Issue& other);
65
66 ~Issue();
67
68 // See constructor comments for more information about these fields.
69 const std::string& title() const { return title_; }
70 const std::string& message() const { return message_; }
71 IssueAction default_action() const { return default_action_; }
72 const std::vector<IssueAction>& secondary_actions() const {
73 return secondary_actions_;
74 }
75 MediaRoute::Id route_id() const { return route_id_; }
76 Severity severity() const { return severity_; }
77 const Issue::Id& id() const { return id_; }
78 bool is_blocking() const { return is_blocking_; }
79 bool is_global() const { return route_id_.empty(); }
80 int help_page_id() const { return help_page_id_; }
81
82 bool Equals(const Issue& other) const;
83
84 private:
85 std::string title_;
86 std::string message_;
87 IssueAction default_action_;
88 std::vector<IssueAction> secondary_actions_;
89 std::string route_id_;
90 Severity severity_;
91 Issue::Id id_;
92 bool is_blocking_;
93 int help_page_id_;
94 }; 97 };
95 98
96 } // namespace media_router 99 } // namespace media_router
97 100
98 #endif // CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_ 101 #endif // CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/router/issue.cc » ('j') | chrome/browser/media/router/issue_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698