OLD | NEW |
---|---|
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/sync/glue/session_model_associator.h" | 5 #include "chrome/browser/sync/glue/session_model_associator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 tab.GetWindowId()); | 380 tab.GetWindowId()); |
381 int64 sync_id = tab_link->sync_id(); | 381 int64 sync_id = tab_link->sync_id(); |
382 GURL old_tab_url = tab_link->url(); | 382 GURL old_tab_url = tab_link->url(); |
383 | 383 |
384 // Load the last stored version of this tab so we can compare changes. If this | 384 // Load the last stored version of this tab so we can compare changes. If this |
385 // is a new tab, session_tab will be a blank/newly created SessionTab object. | 385 // is a new tab, session_tab will be a blank/newly created SessionTab object. |
386 SyncedSessionTab* session_tab = | 386 SyncedSessionTab* session_tab = |
387 synced_session_tracker_.GetTab(GetCurrentMachineTag(), | 387 synced_session_tracker_.GetTab(GetCurrentMachineTag(), |
388 tab.GetSessionId()); | 388 tab.GetSessionId()); |
389 | 389 |
390 // We build a clean session specifics directly from the tab data. | 390 // We build a clean session tab specifics directly from the tab data. |
391 sync_pb::SessionSpecifics session_s; | 391 sync_pb::SessionTab tab_s; |
rlarocque
2012/07/31 21:15:56
That's an unusual variable name, though I guess it
| |
392 session_s.set_session_tag(GetCurrentMachineTag()); | |
393 sync_pb::SessionTab* tab_s = session_s.mutable_tab(); | |
394 | 392 |
395 GURL new_url; | 393 GURL new_url; |
396 AssociateTabContents(window, tab, session_tab, tab_s, &new_url); | 394 AssociateTabContents(window, tab, session_tab, &tab_s, &new_url); |
397 | 395 |
398 // Trigger the favicon load if needed. We do this before opening the write | 396 // Trigger the favicon load if needed. We do this before opening the write |
399 // transaction to avoid jank. | 397 // transaction to avoid jank. |
400 tab_link->set_url(new_url); | 398 tab_link->set_url(new_url); |
401 if (new_url != old_tab_url) { | 399 if (new_url != old_tab_url) { |
402 LoadFaviconForTab(tab_link); | 400 LoadFaviconForTab(tab_link); |
403 } | 401 } |
404 | 402 |
405 // Update our last modified time. | 403 // Update our last modified time. |
406 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = | 404 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = |
407 base::Time::Now(); | 405 base::Time::Now(); |
408 | 406 |
409 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 407 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
410 syncer::WriteNode tab_node(&trans); | 408 syncer::WriteNode tab_node(&trans); |
411 if (tab_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { | 409 if (tab_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { |
412 if (error) { | 410 if (error) { |
413 *error = error_handler_->CreateAndUploadError( | 411 *error = error_handler_->CreateAndUploadError( |
414 FROM_HERE, | 412 FROM_HERE, |
415 "Failed to look up local tab node", | 413 "Failed to look up local tab node", |
416 model_type()); | 414 model_type()); |
417 } | 415 } |
418 return false; | 416 return false; |
419 } | 417 } |
420 | 418 |
419 sync_pb::SessionSpecifics specifics = tab_node.GetSessionSpecifics(); | |
421 if (new_url == old_tab_url) { | 420 if (new_url == old_tab_url) { |
422 // Load the old specifics and copy over the favicon data if needed. | 421 // Load the old specifics and copy over the favicon data if needed. |
423 // TODO(zea): store local favicons in the |synced_favicons_| map and use | 422 // TODO(zea): store local favicons in the |synced_favicons_| map and use |
424 // that instead of reading from sync. This will be necessary to switch to | 423 // that instead of reading from sync. This will be necessary to switch to |
425 // the new api. | 424 // the new api. |
426 const sync_pb::SessionSpecifics old_specifics = | 425 tab_s.set_favicon(specifics.tab().favicon()); |
427 tab_node.GetSessionSpecifics(); | 426 tab_s.set_favicon_source(specifics.tab().favicon_source()); |
428 tab_s->set_favicon(old_specifics.tab().favicon()); | 427 tab_s.set_favicon_type(specifics.tab().favicon_type()); |
429 tab_s->set_favicon_source(old_specifics.tab().favicon_source()); | |
430 tab_s->set_favicon_type(old_specifics.tab().favicon_type()); | |
431 } | 428 } |
432 | 429 // Retain the base SessionSpecifics data (tag, tab_node_id, etc.), and just |
433 // Note: we don't need to preserve unknown fields since we're the only ones | 430 // write the new SessionTabSpecifics. |
434 // who can write to this node (other clients can only delete). | 431 specifics.mutable_tab()->CopyFrom(tab_s); |
435 | 432 |
436 // Write into the actual sync model. | 433 // Write into the actual sync model. |
437 tab_node.SetSessionSpecifics(session_s); | 434 tab_node.SetSessionSpecifics(specifics); |
438 | 435 |
439 return true; | 436 return true; |
440 } | 437 } |
441 | 438 |
442 // Builds |sync_tab| by combining data from |prev_tab| and |new_tab|. Updates | 439 // Builds |sync_tab| by combining data from |prev_tab| and |new_tab|. Updates |
443 // |prev_tab| to reflect the newest version. | 440 // |prev_tab| to reflect the newest version. |
444 // Timestamps are chosen from either |prev_tab| or base::Time::Now() based on | 441 // Timestamps are chosen from either |prev_tab| or base::Time::Now() based on |
445 // the following rules: | 442 // the following rules: |
446 // 1. If a navigation exists in both |new_tab| and |prev_tab|, as determined | 443 // 1. If a navigation exists in both |new_tab| and |prev_tab|, as determined |
447 // by the unique id, and the navigation didn't just become the current | 444 // by the unique id, and the navigation didn't just become the current |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1596 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1593 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1597 // We only access the cryptographer while holding a transaction. | 1594 // We only access the cryptographer while holding a transaction. |
1598 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1595 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1599 const syncer::ModelTypeSet encrypted_types = | 1596 const syncer::ModelTypeSet encrypted_types = |
1600 syncer::GetEncryptedTypes(&trans); | 1597 syncer::GetEncryptedTypes(&trans); |
1601 return !encrypted_types.Has(SESSIONS) || | 1598 return !encrypted_types.Has(SESSIONS) || |
1602 sync_service_->IsCryptographerReady(&trans); | 1599 sync_service_->IsCryptographerReady(&trans); |
1603 } | 1600 } |
1604 | 1601 |
1605 } // namespace browser_sync | 1602 } // namespace browser_sync |
OLD | NEW |