OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_COMMON_PAGE_TRANSITION_TYPES_H__ | 5 #ifndef CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ |
6 #define CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ | 6 #define CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/logging.h" | |
10 | 9 |
11 // This class is for scoping only. | 10 // This class is for scoping only. |
12 class PageTransition { | 11 class PageTransition { |
13 public: | 12 public: |
14 // Types of transitions between pages. These are stored in the history | 13 // Types of transitions between pages. These are stored in the history |
15 // database to separate visits, and are reported by the renderer for page | 14 // database to separate visits, and are reported by the renderer for page |
16 // navigations. | 15 // navigations. |
17 // | 16 // |
18 // WARNING: don't change these numbers. They are written directly into the | 17 // WARNING: don't change these numbers. They are written directly into the |
19 // history database, so future versions will need the same values to match | 18 // history database, so future versions will need the same values to match |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 }; | 123 }; |
125 | 124 |
126 // The type used for the bitfield. | 125 // The type used for the bitfield. |
127 typedef unsigned int Type; | 126 typedef unsigned int Type; |
128 | 127 |
129 static bool ValidType(int32 type) { | 128 static bool ValidType(int32 type) { |
130 Type t = StripQualifier(static_cast<Type>(type)); | 129 Type t = StripQualifier(static_cast<Type>(type)); |
131 return (t <= LAST_CORE); | 130 return (t <= LAST_CORE); |
132 } | 131 } |
133 | 132 |
134 static Type FromInt(int32 type) { | 133 static Type FromInt(int32 type); |
135 if (!ValidType(type)) { | |
136 NOTREACHED() << "Invalid transition type " << type; | |
137 | |
138 // Return a safe default so we don't have corrupt data in release mode. | |
139 return LINK; | |
140 } | |
141 return static_cast<Type>(type); | |
142 } | |
143 | 134 |
144 // Returns true if the given transition is a top-level frame transition, or | 135 // Returns true if the given transition is a top-level frame transition, or |
145 // false if the transition was for a subframe. | 136 // false if the transition was for a subframe. |
146 static bool IsMainFrame(Type type) { | 137 static bool IsMainFrame(Type type) { |
147 int32 t = StripQualifier(type); | 138 int32 t = StripQualifier(type); |
148 return (t != AUTO_SUBFRAME && t != MANUAL_SUBFRAME); | 139 return (t != AUTO_SUBFRAME && t != MANUAL_SUBFRAME); |
149 } | 140 } |
150 | 141 |
151 // Returns whether a transition involves a redirection | 142 // Returns whether a transition involves a redirection |
152 static bool IsRedirect(Type type) { | 143 static bool IsRedirect(Type type) { |
153 return (type & IS_REDIRECT_MASK) != 0; | 144 return (type & IS_REDIRECT_MASK) != 0; |
154 } | 145 } |
155 | 146 |
156 // Simplifies the provided transition by removing any qualifier | 147 // Simplifies the provided transition by removing any qualifier |
157 static Type StripQualifier(Type type) { | 148 static Type StripQualifier(Type type) { |
158 return static_cast<Type>(type & ~QUALIFIER_MASK); | 149 return static_cast<Type>(type & ~QUALIFIER_MASK); |
159 } | 150 } |
160 | 151 |
161 // Return the qualifier | 152 // Return the qualifier |
162 static int32 GetQualifier(Type type) { | 153 static int32 GetQualifier(Type type) { |
163 return type & QUALIFIER_MASK; | 154 return type & QUALIFIER_MASK; |
164 } | 155 } |
165 | 156 |
166 // Return a string version of the core type values. | 157 // Return a string version of the core type values. |
167 static const char* CoreTransitionString(Type type); | 158 static const char* CoreTransitionString(Type type); |
168 }; | 159 }; |
169 | 160 |
170 #endif // CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ | 161 #endif // CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ |
OLD | NEW |