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

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

Issue 11415292: [Search] No longer reverting omnibox text on instant search (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: indent Created 8 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 (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/session_types.h" 5 #include "chrome/browser/sessions/session_types.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 30 matching lines...) Expand all
41 navigation.referrer_ = entry.GetReferrer(); 41 navigation.referrer_ = entry.GetReferrer();
42 navigation.virtual_url_ = entry.GetVirtualURL(); 42 navigation.virtual_url_ = entry.GetVirtualURL();
43 navigation.title_ = entry.GetTitle(); 43 navigation.title_ = entry.GetTitle();
44 navigation.content_state_ = entry.GetContentState(); 44 navigation.content_state_ = entry.GetContentState();
45 navigation.transition_type_ = entry.GetTransitionType(); 45 navigation.transition_type_ = entry.GetTransitionType();
46 navigation.has_post_data_ = entry.GetHasPostData(); 46 navigation.has_post_data_ = entry.GetHasPostData();
47 navigation.post_id_ = entry.GetPostID(); 47 navigation.post_id_ = entry.GetPostID();
48 navigation.original_request_url_ = entry.GetOriginalRequestURL(); 48 navigation.original_request_url_ = entry.GetOriginalRequestURL();
49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); 49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent();
50 navigation.timestamp_ = entry.GetTimestamp(); 50 navigation.timestamp_ = entry.GetTimestamp();
51 navigation.search_terms_ = entry.GetSearchTerms();
51 return navigation; 52 return navigation;
52 } 53 }
53 54
54 TabNavigation TabNavigation::FromSyncData( 55 TabNavigation TabNavigation::FromSyncData(
55 int index, 56 int index,
56 const sync_pb::TabNavigation& sync_data) { 57 const sync_pb::TabNavigation& sync_data) {
57 TabNavigation navigation; 58 TabNavigation navigation;
58 navigation.index_ = index; 59 navigation.index_ = index;
59 navigation.unique_id_ = sync_data.unique_id(); 60 navigation.unique_id_ = sync_data.unique_id();
60 navigation.referrer_ = 61 navigation.referrer_ =
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (sync_data.navigation_chain_start()) 127 if (sync_data.navigation_chain_start())
127 transition |= content::PAGE_TRANSITION_CHAIN_START; 128 transition |= content::PAGE_TRANSITION_CHAIN_START;
128 if (sync_data.navigation_chain_end()) 129 if (sync_data.navigation_chain_end())
129 transition |= content::PAGE_TRANSITION_CHAIN_END; 130 transition |= content::PAGE_TRANSITION_CHAIN_END;
130 131
131 navigation.transition_type_ = 132 navigation.transition_type_ =
132 static_cast<content::PageTransition>(transition); 133 static_cast<content::PageTransition>(transition);
133 134
134 navigation.timestamp_ = base::Time(); 135 navigation.timestamp_ = base::Time();
135 136
137 navigation.search_terms_ = UTF8ToUTF16(sync_data.search_terms());
138
136 return navigation; 139 return navigation;
137 } 140 }
138 141
139 namespace { 142 namespace {
140 143
141 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to 144 // Helper used by TabNavigation::WriteToPickle(). It writes |str| to
142 // |pickle|, if and only if |str| fits within (|max_bytes| - 145 // |pickle|, if and only if |str| fits within (|max_bytes| -
143 // |*bytes_written|). |bytes_written| is incremented to reflect the 146 // |*bytes_written|). |bytes_written| is incremented to reflect the
144 // data written. 147 // data written.
145 // 148 //
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // content_state_ 197 // content_state_
195 // transition_type_ 198 // transition_type_
196 // 199 //
197 // Added on later: 200 // Added on later:
198 // 201 //
199 // type_mask (has_post_data_) 202 // type_mask (has_post_data_)
200 // referrer_ 203 // referrer_
201 // original_request_url_ 204 // original_request_url_
202 // is_overriding_user_agent_ 205 // is_overriding_user_agent_
203 // timestamp_ 206 // timestamp_
207 // search_terms_
204 208
205 void TabNavigation::WriteToPickle(Pickle* pickle) const { 209 void TabNavigation::WriteToPickle(Pickle* pickle) const {
206 pickle->WriteInt(index_); 210 pickle->WriteInt(index_);
207 211
208 // We only allow navigations up to 63k (which should be completely 212 // We only allow navigations up to 63k (which should be completely
209 // reasonable). On the off chance we get one that is too big, try to 213 // reasonable). On the off chance we get one that is too big, try to
210 // keep the url. 214 // keep the url.
211 215
212 // Bound the string data (which is variable length) to 216 // Bound the string data (which is variable length) to
213 // |max_state_size bytes| bytes. 217 // |max_state_size bytes| bytes.
(...skipping 24 matching lines...) Expand all
238 242
239 pickle->WriteInt(referrer_.policy); 243 pickle->WriteInt(referrer_.policy);
240 244
241 // Save info required to override the user agent. 245 // Save info required to override the user agent.
242 WriteStringToPickle( 246 WriteStringToPickle(
243 pickle, &bytes_written, max_state_size, 247 pickle, &bytes_written, max_state_size,
244 original_request_url_.is_valid() ? 248 original_request_url_.is_valid() ?
245 original_request_url_.spec() : std::string()); 249 original_request_url_.spec() : std::string());
246 pickle->WriteBool(is_overriding_user_agent_); 250 pickle->WriteBool(is_overriding_user_agent_);
247 pickle->WriteInt64(timestamp_.ToInternalValue()); 251 pickle->WriteInt64(timestamp_.ToInternalValue());
252
253 WriteString16ToPickle(pickle, &bytes_written, max_state_size, search_terms_);
248 } 254 }
249 255
250 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) { 256 bool TabNavigation::ReadFromPickle(PickleIterator* iterator) {
251 *this = TabNavigation(); 257 *this = TabNavigation();
252 std::string virtual_url_spec; 258 std::string virtual_url_spec;
253 int transition_type_int = 0; 259 int transition_type_int = 0;
254 if (!iterator->ReadInt(&index_) || 260 if (!iterator->ReadInt(&index_) ||
255 !iterator->ReadString(&virtual_url_spec) || 261 !iterator->ReadString(&virtual_url_spec) ||
256 !iterator->ReadString16(&title_) || 262 !iterator->ReadString16(&title_) ||
257 !iterator->ReadString(&content_state_) || 263 !iterator->ReadString(&content_state_) ||
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // Default to not overriding the user agent if we don't have info. 297 // Default to not overriding the user agent if we don't have info.
292 if (!iterator->ReadBool(&is_overriding_user_agent_)) 298 if (!iterator->ReadBool(&is_overriding_user_agent_))
293 is_overriding_user_agent_ = false; 299 is_overriding_user_agent_ = false;
294 300
295 int64 timestamp_internal_value = 0; 301 int64 timestamp_internal_value = 0;
296 if (iterator->ReadInt64(&timestamp_internal_value)) { 302 if (iterator->ReadInt64(&timestamp_internal_value)) {
297 timestamp_ = base::Time::FromInternalValue(timestamp_internal_value); 303 timestamp_ = base::Time::FromInternalValue(timestamp_internal_value);
298 } else { 304 } else {
299 timestamp_ = base::Time(); 305 timestamp_ = base::Time();
300 } 306 }
307
308 // If the search terms field can't be found, leave it empty.
309 if (!iterator->ReadString16(&search_terms_)) {
sky 2012/12/12 22:41:57 no {}
Mathieu 2012/12/12 23:37:24 Done.
310 search_terms_ = string16();
311 }
301 } 312 }
302 313
303 return true; 314 return true;
304 } 315 }
305 316
306 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry( 317 scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry(
307 int page_id, 318 int page_id,
308 content::BrowserContext* browser_context) const { 319 content::BrowserContext* browser_context) const {
309 scoped_ptr<NavigationEntry> entry( 320 scoped_ptr<NavigationEntry> entry(
310 content::NavigationController::CreateNavigationEntry( 321 content::NavigationController::CreateNavigationEntry(
311 virtual_url_, 322 virtual_url_,
312 referrer_, 323 referrer_,
313 // Use a transition type of reload so that we don't incorrectly 324 // Use a transition type of reload so that we don't incorrectly
314 // increase the typed count. 325 // increase the typed count.
315 content::PAGE_TRANSITION_RELOAD, 326 content::PAGE_TRANSITION_RELOAD,
316 false, 327 false,
317 // The extra headers are not sync'ed across sessions. 328 // The extra headers are not sync'ed across sessions.
318 std::string(), 329 std::string(),
319 browser_context)); 330 browser_context));
320 331
321 entry->SetTitle(title_); 332 entry->SetTitle(title_);
322 entry->SetContentState(content_state_); 333 entry->SetContentState(content_state_);
323 entry->SetPageID(page_id); 334 entry->SetPageID(page_id);
324 entry->SetHasPostData(has_post_data_); 335 entry->SetHasPostData(has_post_data_);
325 entry->SetPostID(post_id_); 336 entry->SetPostID(post_id_);
326 entry->SetOriginalRequestURL(original_request_url_); 337 entry->SetOriginalRequestURL(original_request_url_);
327 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); 338 entry->SetIsOverridingUserAgent(is_overriding_user_agent_);
328 entry->SetTimestamp(timestamp_); 339 entry->SetTimestamp(timestamp_);
340 entry->SetSearchTerms(search_terms_);
329 341
330 return entry.Pass(); 342 return entry.Pass();
331 } 343 }
332 344
333 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? 345 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well?
334 // See http://crbug.com/67068. 346 // See http://crbug.com/67068.
335 sync_pb::TabNavigation TabNavigation::ToSyncData() const { 347 sync_pb::TabNavigation TabNavigation::ToSyncData() const {
336 sync_pb::TabNavigation sync_data; 348 sync_pb::TabNavigation sync_data;
337 sync_data.set_virtual_url(virtual_url_.spec()); 349 sync_data.set_virtual_url(virtual_url_.spec());
338 // FIXME(zea): Support referrer policy? 350 // FIXME(zea): Support referrer policy?
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 sync_data.set_navigation_chain_start( 423 sync_data.set_navigation_chain_start(
412 (transition_type_ & content::PAGE_TRANSITION_CHAIN_START) != 0); 424 (transition_type_ & content::PAGE_TRANSITION_CHAIN_START) != 0);
413 sync_data.set_navigation_chain_end( 425 sync_data.set_navigation_chain_end(
414 (transition_type_ & content::PAGE_TRANSITION_CHAIN_END) != 0); 426 (transition_type_ & content::PAGE_TRANSITION_CHAIN_END) != 0);
415 427
416 sync_data.set_unique_id(unique_id_); 428 sync_data.set_unique_id(unique_id_);
417 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_)); 429 sync_data.set_timestamp(syncer::TimeToProtoTime(timestamp_));
418 // The full-resolution timestamp works as a global ID. 430 // The full-resolution timestamp works as a global ID.
419 sync_data.set_global_id(timestamp_.ToInternalValue()); 431 sync_data.set_global_id(timestamp_.ToInternalValue());
420 432
433 sync_data.set_search_terms(UTF16ToUTF8(search_terms_));
434
421 return sync_data; 435 return sync_data;
422 } 436 }
423 437
424 // static 438 // static
425 std::vector<NavigationEntry*> 439 std::vector<NavigationEntry*>
426 TabNavigation::CreateNavigationEntriesFromTabNavigations( 440 TabNavigation::CreateNavigationEntriesFromTabNavigations(
427 const std::vector<TabNavigation>& navigations, 441 const std::vector<TabNavigation>& navigations,
428 content::BrowserContext* browser_context) { 442 content::BrowserContext* browser_context) {
429 int page_id = 0; 443 int page_id = 0;
430 std::vector<NavigationEntry*> entries; 444 std::vector<NavigationEntry*> entries;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 SessionWindow::SessionWindow() 500 SessionWindow::SessionWindow()
487 : selected_tab_index(-1), 501 : selected_tab_index(-1),
488 type(Browser::TYPE_TABBED), 502 type(Browser::TYPE_TABBED),
489 is_constrained(true), 503 is_constrained(true),
490 show_state(ui::SHOW_STATE_DEFAULT) { 504 show_state(ui::SHOW_STATE_DEFAULT) {
491 } 505 }
492 506
493 SessionWindow::~SessionWindow() { 507 SessionWindow::~SessionWindow() {
494 STLDeleteElements(&tabs); 508 STLDeleteElements(&tabs);
495 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698