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

Side by Side Diff: chrome/browser/sessions/base_session_service.cc

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac 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 #include "chrome/browser/sessions/base_session_service.h" 5 #include "chrome/browser/sessions/base_session_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sessions/session_backend.h" 14 #include "chrome/browser/sessions/session_backend.h"
15 #include "chrome/browser/sessions/session_types.h" 15 #include "chrome/browser/sessions/session_types.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/common/referrer.h" 20 #include "content/public/common/referrer.h"
21 #include "webkit/glue/webkit_glue.h" 21 #include "webkit/glue/webkit_glue.h"
22 22
23 using WebKit::WebReferrerPolicy;
24 using content::BrowserThread; 23 using content::BrowserThread;
25 using content::NavigationEntry; 24 using content::NavigationEntry;
26 25
27 // InternalGetCommandsRequest ------------------------------------------------- 26 // InternalGetCommandsRequest -------------------------------------------------
28 27
29 BaseSessionService::InternalGetCommandsRequest::InternalGetCommandsRequest( 28 BaseSessionService::InternalGetCommandsRequest::InternalGetCommandsRequest(
30 const CallbackType& callback) 29 const CallbackType& callback)
31 : CancelableRequest<InternalGetCommandsCallback>(callback) { 30 : CancelableRequest<InternalGetCommandsCallback>(callback) {
32 } 31 }
33 32
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 142
144 if (pending_reset_) { 143 if (pending_reset_) {
145 commands_since_reset_ = 0; 144 commands_since_reset_ = 0;
146 pending_reset_ = false; 145 pending_reset_ = false;
147 } 146 }
148 } 147 }
149 148
150 SessionCommand* BaseSessionService::CreateUpdateTabNavigationCommand( 149 SessionCommand* BaseSessionService::CreateUpdateTabNavigationCommand(
151 SessionID::id_type command_id, 150 SessionID::id_type command_id,
152 SessionID::id_type tab_id, 151 SessionID::id_type tab_id,
153 int index, 152 const TabNavigation& navigation) {
154 const NavigationEntry& entry) {
155 // Use pickle to handle marshalling. 153 // Use pickle to handle marshalling.
156 Pickle pickle; 154 Pickle pickle;
157 pickle.WriteInt(tab_id); 155 pickle.WriteInt(tab_id);
158 pickle.WriteInt(index); 156 navigation.WriteToPickle(&pickle);
159
160 // We only allow navigations up to 63k (which should be completely
161 // reasonable). On the off chance we get one that is too big, try to
162 // keep the url.
163
164 // Bound the string data (which is variable length) to
165 // |max_state_size bytes| bytes.
166 static const SessionCommand::size_type max_state_size =
167 std::numeric_limits<SessionCommand::size_type>::max() - 1024;
168
169 int bytes_written = 0;
170
171 WriteStringToPickle(pickle, &bytes_written, max_state_size,
172 entry.GetVirtualURL().spec());
173
174 WriteString16ToPickle(pickle, &bytes_written, max_state_size,
175 entry.GetTitle());
176
177 std::string content_state = entry.GetContentState();
178 if (entry.GetHasPostData()) {
179 content_state =
180 webkit_glue::RemovePasswordDataFromHistoryState(content_state);
181 }
182 WriteStringToPickle(pickle, &bytes_written, max_state_size, content_state);
183
184 pickle.WriteInt(entry.GetTransitionType());
185 int type_mask = entry.GetHasPostData() ? TabNavigation::HAS_POST_DATA : 0;
186 pickle.WriteInt(type_mask);
187
188 WriteStringToPickle(pickle, &bytes_written, max_state_size,
189 entry.GetReferrer().url.is_valid() ?
190 entry.GetReferrer().url.spec() : std::string());
191 pickle.WriteInt(entry.GetReferrer().policy);
192
193 // Save info required to override the user agent.
194 WriteStringToPickle(pickle, &bytes_written, max_state_size,
195 entry.GetOriginalRequestURL().is_valid() ?
196 entry.GetOriginalRequestURL().spec() : std::string());
197 pickle.WriteBool(entry.GetIsOverridingUserAgent());
198
199 return new SessionCommand(command_id, pickle); 157 return new SessionCommand(command_id, pickle);
200 } 158 }
201 159
202 SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand( 160 SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand(
203 SessionID::id_type command_id, 161 SessionID::id_type command_id,
204 SessionID::id_type tab_id, 162 SessionID::id_type tab_id,
205 const std::string& extension_id) { 163 const std::string& extension_id) {
206 // Use pickle to handle marshalling. 164 // Use pickle to handle marshalling.
207 Pickle pickle; 165 Pickle pickle;
208 pickle.WriteInt(tab_id); 166 pickle.WriteInt(tab_id);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 217 }
260 218
261 bool BaseSessionService::RestoreUpdateTabNavigationCommand( 219 bool BaseSessionService::RestoreUpdateTabNavigationCommand(
262 const SessionCommand& command, 220 const SessionCommand& command,
263 TabNavigation* navigation, 221 TabNavigation* navigation,
264 SessionID::id_type* tab_id) { 222 SessionID::id_type* tab_id) {
265 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); 223 scoped_ptr<Pickle> pickle(command.PayloadAsPickle());
266 if (!pickle.get()) 224 if (!pickle.get())
267 return false; 225 return false;
268 PickleIterator iterator(*pickle); 226 PickleIterator iterator(*pickle);
269 std::string url_spec; 227 return
270 if (!pickle->ReadInt(&iterator, tab_id) || 228 pickle->ReadInt(&iterator, tab_id) &&
271 !pickle->ReadInt(&iterator, &(navigation->index_)) || 229 navigation->ReadFromPickle(&iterator);
272 !pickle->ReadString(&iterator, &url_spec) ||
273 !pickle->ReadString16(&iterator, &(navigation->title_)) ||
274 !pickle->ReadString(&iterator, &(navigation->state_)) ||
275 !pickle->ReadInt(&iterator,
276 reinterpret_cast<int*>(&(navigation->transition_))))
277 return false;
278 // type_mask did not always exist in the written stream. As such, we
279 // don't fail if it can't be read.
280 bool has_type_mask = pickle->ReadInt(&iterator, &(navigation->type_mask_));
281
282 if (has_type_mask) {
283 // the "referrer" property was added after type_mask to the written
284 // stream. As such, we don't fail if it can't be read.
285 std::string referrer_spec;
286 pickle->ReadString(&iterator, &referrer_spec);
287 // The "referrer policy" property was added even later, so we fall back to
288 // the default policy if the property is not present.
289 int policy_int;
290 WebReferrerPolicy policy;
291 if (pickle->ReadInt(&iterator, &policy_int))
292 policy = static_cast<WebReferrerPolicy>(policy_int);
293 else
294 policy = WebKit::WebReferrerPolicyDefault;
295 navigation->referrer_ = content::Referrer(
296 referrer_spec.empty() ? GURL() : GURL(referrer_spec),
297 policy);
298
299 // If the original URL can't be found, leave it empty.
300 std::string url_spec;
301 if (!pickle->ReadString(&iterator, &url_spec))
302 url_spec = std::string();
303 navigation->set_original_request_url(GURL(url_spec));
304
305 // Default to not overriding the user agent if we don't have info.
306 bool override_user_agent;
307 if (!pickle->ReadBool(&iterator, &override_user_agent))
308 override_user_agent = false;
309 navigation->set_is_overriding_user_agent(override_user_agent);
310 }
311
312 navigation->virtual_url_ = GURL(url_spec);
313 return true;
314 } 230 }
315 231
316 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( 232 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand(
317 const SessionCommand& command, 233 const SessionCommand& command,
318 SessionID::id_type* tab_id, 234 SessionID::id_type* tab_id,
319 std::string* extension_app_id) { 235 std::string* extension_app_id) {
320 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); 236 scoped_ptr<Pickle> pickle(command.PayloadAsPickle());
321 if (!pickle.get()) 237 if (!pickle.get())
322 return false; 238 return false;
323 239
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // has gone away (around shutdown time) or if we're running as 296 // has gone away (around shutdown time) or if we're running as
381 // part of a unit test that does not set profile_. 297 // part of a unit test that does not set profile_.
382 task.Run(); 298 task.Run();
383 return true; 299 return true;
384 } 300 }
385 } 301 }
386 302
387 bool BaseSessionService::RunningInProduction() const { 303 bool BaseSessionService::RunningInProduction() const {
388 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE); 304 return profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE);
389 } 305 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/base_session_service.h ('k') | chrome/browser/sessions/session_restore.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698