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

Side by Side Diff: chrome/browser/sessions/session_types.h

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indent Created 8 years, 3 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_SESSIONS_SESSION_TYPES_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/stl_util.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/sessions/session_id.h" 14 #include "chrome/browser/sessions/session_id.h"
15 #include "content/public/common/page_transition_types.h" 15 #include "content/public/common/page_transition_types.h"
16 #include "content/public/common/referrer.h" 16 #include "content/public/common/referrer.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "sync/protocol/session_specifics.pb.h"
18 #include "ui/base/ui_base_types.h" 19 #include "ui/base/ui_base_types.h"
19 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
20 21
21 class Profile; 22 class Pickle;
23 class PickleIterator;
22 24
23 namespace content { 25 namespace content {
26 class BrowserContext;
24 class NavigationEntry; 27 class NavigationEntry;
25 } 28 }
26 29
27 // TabNavigation ------------------------------------------------------------- 30 // TabNavigation -------------------------------------------------------------
28 31
29 // TabNavigation corresponds to the parts of NavigationEntry needed to restore 32 // TabNavigation is a "freeze-dried" version of NavigationEntry. It
30 // the NavigationEntry during session restore and tab restore. 33 // contains the data needed to restore a NavigationEntry during
31 // 34 // session restore and tab restore, and it can also be pickled and
32 // TabNavigation is cheap and supports copy semantics. 35 // unpickled. It is also convertible to a sync protocol buffer for
36 // session syncing.
33 class TabNavigation { 37 class TabNavigation {
34 public: 38 public:
35 enum TypeMask { 39 // Creates an invalid (index < 0) TabNavigation.
36 HAS_POST_DATA = 1 40 TabNavigation();
37 }; 41 ~TabNavigation();
38 42
39 TabNavigation(); 43 // Default copy constructor and assignment operator welcome.
sky 2012/09/17 14:03:36 Move this back to class description.
akalin 2012/09/17 23:24:32 Done.
40 TabNavigation(int index,
41 const GURL& virtual_url,
42 const content::Referrer& referrer,
43 const string16& title,
44 const std::string& state,
45 content::PageTransition transition);
46 TabNavigation(const TabNavigation& tab);
47 virtual ~TabNavigation();
48 TabNavigation& operator=(const TabNavigation& tab);
49 44
50 // Converts this TabNavigation into a NavigationEntry with a page id of 45 // Construct a TabNavigation for a particular index from a
51 // |page_id|. The caller owns the returned NavigationEntry. 46 // NavigationEntry with the given timestamp.
52 content::NavigationEntry* ToNavigationEntry(int page_id, 47 //
53 Profile* profile) const; 48 // TODO(akalin): Add a timestamp field to
49 // navigation::NavigationEntry and use that instead of passing a
50 // separate timestamp.
51 static TabNavigation FromNavigationEntry(
52 int index,
53 const content::NavigationEntry& entry,
54 base::Time timestamp);
54 55
55 // Resets this TabNavigation from |entry|. 56 // Construct a TabNavigation for a particular index from a sync
56 void SetFromNavigationEntry(const content::NavigationEntry& entry); 57 // protocol buffer. Note that the sync protocol buffer doesn't
58 // contain all TabNavigation fields.
59 static TabNavigation FromSyncData(
60 int index,
61 const sync_pb::TabNavigation& specifics);
57 62
58 // Virtual URL of the page. See NavigationEntry::GetVirtualURL() for details. 63 // Note that not all TabNavigation fields are preserved.
59 void set_virtual_url(const GURL& url) { virtual_url_ = url; } 64 void WriteToPickle(Pickle* pickle) const;
65 bool ReadFromPickle(PickleIterator* iterator);
66
67 // Convert this TabNavigation into a NavigationEntry with the given
68 // page ID and context. The NavigationEntry will have a transition
69 // type of PAGE_TRANSITION_RELOAD and a new unique ID.
70 scoped_ptr<content::NavigationEntry> ToNavigationEntry(
71 int page_id,
72 content::BrowserContext* browser_context) const;
73
74 // Convert this navigation into its sync protocol buffer equivalent.
75 // Note that the protocol buffer doesn't contain all TabNavigation
76 // fields.
77 sync_pb::TabNavigation ToSyncData() const;
78
79 // The index in the NavigationController. This TabNavigation is
80 // valid only when the index is non-negative.
81 //
82 // This is used when determining the selected TabNavigation and only
83 // used by SessionService.
84 int index() const { return index_; }
85 void set_index(int index) { index_ = index; }
86
87 // Accessors for some fields taken from NavigationEntry.
88 int unique_id() const { return unique_id_; }
60 const GURL& virtual_url() const { return virtual_url_; } 89 const GURL& virtual_url() const { return virtual_url_; }
90 const string16& title() const { return title_; }
91 const std::string& content_state() const { return content_state_; }
61 92
62 // The referrer. 93 // Timestamp this navigation occurred.
63 const content::Referrer& referrer() const { return referrer_; } 94 base::Time timestamp() const { return timestamp_; }
64 95
65 // The title of the page. 96 // Converts a set of TabNavigations into a list of NavigationEntrys
66 void set_title(const string16& title) { title_ = title; } 97 // with sequential page IDs and the given context. The caller owns
67 const string16& title() const { return title_; } 98 // the returned NavigationEntrys.
99 static std::vector<content::NavigationEntry*>
100 CreateNavigationEntriesFromTabNavigations(
101 const std::vector<TabNavigation>& navigations,
102 content::BrowserContext* browser_context);
68 103
69 // State bits. 104 // Functions for testing.
sky 2012/09/17 14:03:36 I don't like all the for test foo. They clutter up
akalin 2012/09/17 23:24:32 Done, moved to SessionTypesTestHelper.
70 const std::string& state() const { return state_; }
71 105
72 // Transition type. 106 static TabNavigation CreateForTest(const std::string& virtual_url,
73 void set_transition(content::PageTransition transition) { 107 const std::string& title);
74 transition_ = transition;
75 }
76 content::PageTransition transition() const { return transition_; }
77 108
78 // A mask used for arbitrary boolean values needed to represent a 109 const content::Referrer& GetReferrerForTest() const;
79 // NavigationEntry. Currently only contains HAS_POST_DATA or 0.
80 void set_type_mask(int type_mask) { type_mask_ = type_mask; }
81 int type_mask() const { return type_mask_; }
82 110
83 // The index in the NavigationController. If this is -1, it means this 111 content::PageTransition GetTransitionTypeForTest() const;
84 // TabNavigation is bogus.
85 //
86 // This is used when determining the selected TabNavigation and only useful
87 // by BaseSessionService and SessionService.
88 void set_index(int index) { index_ = index; }
89 int index() const { return index_; }
90 112
91 // The URL that initially spawned the NavigationEntry. 113 bool GetHasPostDataForTest() const;
92 const GURL& original_request_url() const { return original_request_url_; }
93 void set_original_request_url(const GURL& url) {
94 original_request_url_ = url;
95 }
96 114
97 // Whether or not we're overriding the standard user agent. 115 int64 GetPostIdForTest() const;
98 bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
99 void set_is_overriding_user_agent(bool state) {
100 is_overriding_user_agent_ = state;
101 }
102 116
103 // Converts a set of TabNavigations into a set of NavigationEntrys. The 117 const GURL& GetOriginalRequestURLForTest() const;
104 // caller owns the NavigationEntrys. 118
105 static void CreateNavigationEntriesFromTabNavigations( 119 bool GetIsOverridingUserAgentForTest() const;
106 Profile* profile, 120
107 const std::vector<TabNavigation>& navigations, 121 void SetContentStateForTest(const std::string& content_state);
108 std::vector<content::NavigationEntry*>* entries); 122
123 void SetTransitionTypeForTest(content::PageTransition transition_type);
124
125 void SetHasPostDataForTest(bool has_post_data);
126
127 void SetOriginalRequestURLForTest(const GURL& original_request_url);
128
129 void SetIsOverridingUserAgentForTest(bool is_overriding_user_agent);
109 130
110 private: 131 private:
111 friend class BaseSessionService; 132 friend struct SessionTypesTestHelper;
112 133
134 // Index in the NavigationController.
135 int index_;
136
137 // Member variables corresponding to NavigationEntry fields.
138 int unique_id_;
sky 2012/09/17 14:03:36 Why do we now need the unique id?
akalin 2012/09/17 23:24:32 Sync needs it to disambiguate navigations (even wh
139 content::Referrer referrer_;
113 GURL virtual_url_; 140 GURL virtual_url_;
114 content::Referrer referrer_;
115 string16 title_; 141 string16 title_;
116 std::string state_; 142 std::string content_state_;
117 content::PageTransition transition_; 143 content::PageTransition transition_type_;
118 int type_mask_; 144 bool has_post_data_;
119 int64 post_id_; 145 int64 post_id_;
120
121 int index_;
122 GURL original_request_url_; 146 GURL original_request_url_;
123 bool is_overriding_user_agent_; 147 bool is_overriding_user_agent_;
148
149 // Timestamp when the navigation occurred.
150 //
151 // TODO(akalin): Add a timestamp field to NavigationEntry.
152 base::Time timestamp_;
sky 2012/09/17 14:03:36 Can we add the two at the same time?
akalin 2012/09/17 23:24:32 NavigationEntry already has a unique ID field (alt
124 }; 153 };
125 154
126 // SessionTab ---------------------------------------------------------------- 155 // SessionTab ----------------------------------------------------------------
127 156
128 // SessionTab corresponds to a NavigationController. 157 // SessionTab corresponds to a NavigationController.
129 struct SessionTab { 158 struct SessionTab {
130 SessionTab(); 159 SessionTab();
131 virtual ~SessionTab(); 160 virtual ~SessionTab();
132 161
133 // Since the current_navigation_index can be larger than the index for number 162 // Since the current_navigation_index can be larger than the index for number
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // Is the window maximized, minimized, or normal? 258 // Is the window maximized, minimized, or normal?
230 ui::WindowShowState show_state; 259 ui::WindowShowState show_state;
231 260
232 std::string app_name; 261 std::string app_name;
233 262
234 private: 263 private:
235 DISALLOW_COPY_AND_ASSIGN(SessionWindow); 264 DISALLOW_COPY_AND_ASSIGN(SessionWindow);
236 }; 265 };
237 266
238 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 267 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698