| OLD | NEW |
| 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 "chrome/browser/media/router/media_route.h" | 12 #include "chrome/browser/media/router/media_route.h" |
| 13 | 13 |
| 14 namespace media_router { | 14 namespace media_router { |
| 15 | 15 |
| 16 // The text that corresponds with an action a user can take for a Issue. | 16 // Contains the information relevant to an issue. |
| 17 class IssueAction { | 17 struct IssueInfo { |
| 18 public: | 18 public: |
| 19 enum Type { | 19 // Possible actions for an issue. |
| 20 TYPE_DISMISS, | 20 enum class Action { |
| 21 TYPE_LEARN_MORE, | 21 DISMISS, |
| 22 TYPE_MAX /* Denotes enum value boundary. */ | 22 // NOTE: If LEARN_MORE is set as a possible action for an issue, then its |
| 23 // |help_page_id_| must also be set to a valid value. |
| 24 LEARN_MORE, |
| 25 |
| 26 // Denotes enum value boundary. New values should be added above. |
| 27 NUM_VALUES = LEARN_MORE |
| 23 }; | 28 }; |
| 24 | 29 |
| 25 explicit IssueAction(const Type type); | 30 // Severity type of an issue. A FATAL issue is considered blocking. Although |
| 26 ~IssueAction(); | 31 // issues of other severity levels may also be blocking. |
| 32 enum class Severity { FATAL, WARNING, NOTIFICATION }; |
| 27 | 33 |
| 28 Type type() const { return type_; } | 34 static const int kUnknownHelpPageId = 0; |
| 29 | 35 |
| 30 bool Equals(const IssueAction& other) const { return type_ == other.type_; } | 36 // Used by Mojo and testing only. |
| 37 IssueInfo(); |
| 38 |
| 39 // |title|: The title for the issue. |
| 40 // |default_action|: Default action user can take to resolve the issue. |
| 41 // |severity|: The severity of the issue. If FATAL, then |is_blocking| is set |
| 42 // to |true|. |
| 43 IssueInfo(const std::string& title, Action default_action, Severity severity); |
| 44 IssueInfo(const IssueInfo& other); |
| 45 ~IssueInfo(); |
| 46 |
| 47 IssueInfo& operator=(const IssueInfo& other); |
| 48 bool operator==(const IssueInfo& other) const; |
| 49 |
| 50 // Fields set with values provided to the constructor. |
| 51 std::string title; |
| 52 Action default_action; |
| 53 Severity severity; |
| 54 |
| 55 // Description message for the issue. |
| 56 std::string message; |
| 57 |
| 58 // Options the user can take to resolve the issue in addition to the |
| 59 // default action. Can be empty. If non-empty, currently only one secondary |
| 60 // action is supported. |
| 61 std::vector<Action> secondary_actions; |
| 62 |
| 63 // ID of route associated with the Issue, or empty if no route is associated |
| 64 // with it. |
| 65 std::string route_id; |
| 66 |
| 67 // |true| if the issue needs to be resolved before continuing. Note that a |
| 68 // Issue of severity FATAL is considered blocking by default. |
| 69 bool is_blocking; |
| 70 |
| 71 // ID of help page to link to, if one of the actions is LEARN_MORE. |
| 72 // Defaults to |kUnknownHelpPageId|. |
| 73 int help_page_id; |
| 74 }; |
| 75 |
| 76 // An issue that is associated with a globally unique ID. Created by |
| 77 // IssueManager when an IssueInfo is added to it. |
| 78 class Issue { |
| 79 public: |
| 80 using Id = int; |
| 81 // ID is generated during construction. |
| 82 explicit Issue(const IssueInfo& info); |
| 83 Issue(const Issue& other) = default; |
| 84 Issue& operator=(const Issue& other) = default; |
| 85 ~Issue(); |
| 86 |
| 87 const Id& id() const { return id_; } |
| 88 const IssueInfo& info() const { return info_; } |
| 31 | 89 |
| 32 private: | 90 private: |
| 33 Type type_; | 91 Id id_; |
| 34 }; | 92 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 }; | 93 }; |
| 95 | 94 |
| 96 } // namespace media_router | 95 } // namespace media_router |
| 97 | 96 |
| 98 #endif // CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_ | 97 #endif // CHROME_BROWSER_MEDIA_ROUTER_ISSUE_H_ |
| OLD | NEW |