| 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 30 matching lines...) Expand all Loading... |
| 41 #include "sync/protocol/session_specifics.pb.h" | 41 #include "sync/protocol/session_specifics.pb.h" |
| 42 #include "sync/syncable/directory.h" | 42 #include "sync/syncable/directory.h" |
| 43 #include "sync/syncable/read_transaction.h" | 43 #include "sync/syncable/read_transaction.h" |
| 44 #include "sync/syncable/write_transaction.h" | 44 #include "sync/syncable/write_transaction.h" |
| 45 #include "sync/util/get_session_name.h" | 45 #include "sync/util/get_session_name.h" |
| 46 #include "ui/gfx/favicon_size.h" | 46 #include "ui/gfx/favicon_size.h" |
| 47 #if defined(OS_LINUX) | 47 #if defined(OS_LINUX) |
| 48 #include "base/linux_util.h" | 48 #include "base/linux_util.h" |
| 49 #elif defined(OS_WIN) | 49 #elif defined(OS_WIN) |
| 50 #include <windows.h> | 50 #include <windows.h> |
| 51 #elif defined(OS_ANDROID) | |
| 52 #include "sync/util/session_utils_android.h" | |
| 53 #endif | 51 #endif |
| 54 | 52 |
| 55 using content::BrowserThread; | 53 using content::BrowserThread; |
| 56 using content::NavigationEntry; | 54 using content::NavigationEntry; |
| 57 using prefs::kSyncSessionsGUID; | 55 using prefs::kSyncSessionsGUID; |
| 58 using syncer::SESSIONS; | 56 using syncer::SESSIONS; |
| 59 | 57 |
| 58 namespace { |
| 59 // Given a transaction, returns the GUID-based string that should be used for |
| 60 // |current_machine_tag_|. |
| 61 std::string GetMachineTagFromTransaction( |
| 62 syncer::WriteTransaction* trans) { |
| 63 syncer::syncable::Directory* dir = trans->GetWrappedWriteTrans()->directory(); |
| 64 std::string machine_tag = "session_sync"; |
| 65 machine_tag.append(dir->cache_guid()); |
| 66 return machine_tag; |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
| 60 namespace browser_sync { | 71 namespace browser_sync { |
| 61 | 72 |
| 62 namespace { | 73 namespace { |
| 63 static const char kNoSessionsFolderError[] = | 74 static const char kNoSessionsFolderError[] = |
| 64 "Server did not create the top-level sessions node. We " | 75 "Server did not create the top-level sessions node. We " |
| 65 "might be running against an out-of-date server."; | 76 "might be running against an out-of-date server."; |
| 66 | 77 |
| 67 // The maximum number of navigations in each direction we care to sync. | 78 // The maximum number of navigations in each direction we care to sync. |
| 68 static const int kMaxSyncNavigationCount = 6; | 79 static const int kMaxSyncNavigationCount = 6; |
| 69 | 80 |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); | 647 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); |
| 637 sync_pb::SessionSpecifics base_specifics; | 648 sync_pb::SessionSpecifics base_specifics; |
| 638 base_specifics.set_session_tag(current_machine_tag_); | 649 base_specifics.set_session_tag(current_machine_tag_); |
| 639 sync_pb::SessionHeader* header_s = base_specifics.mutable_header(); | 650 sync_pb::SessionHeader* header_s = base_specifics.mutable_header(); |
| 640 header_s->set_client_name(current_session_name_); | 651 header_s->set_client_name(current_session_name_); |
| 641 header_s->set_device_type(DeviceInfo::GetLocalDeviceType()); | 652 header_s->set_device_type(DeviceInfo::GetLocalDeviceType()); |
| 642 write_node.SetSessionSpecifics(base_specifics); | 653 write_node.SetSessionSpecifics(base_specifics); |
| 643 | 654 |
| 644 local_session_syncid_ = write_node.GetId(); | 655 local_session_syncid_ = write_node.GetId(); |
| 645 } | 656 } |
| 657 #if defined(OS_ANDROID) |
| 658 std::string transaction_tag = GetMachineTagFromTransaction(&trans); |
| 659 if (current_machine_tag_.compare(transaction_tag) != 0) |
| 660 DeleteForeignSession(transaction_tag); |
| 661 #endif |
| 646 } | 662 } |
| 647 | 663 |
| 648 // Check if anything has changed on the client side. | 664 // Check if anything has changed on the client side. |
| 649 if (!UpdateSyncModelDataFromClient(&error)) { | 665 if (!UpdateSyncModelDataFromClient(&error)) { |
| 650 DCHECK(error.IsSet()); | 666 DCHECK(error.IsSet()); |
| 651 return error; | 667 return error; |
| 652 } | 668 } |
| 653 | 669 |
| 654 DVLOG(1) << "Session models associated."; | 670 DVLOG(1) << "Session models associated."; |
| 655 DCHECK(!error.IsSet()); | 671 DCHECK(!error.IsSet()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 683 DCHECK(CalledOnValidThread()); | 699 DCHECK(CalledOnValidThread()); |
| 684 DCHECK(current_machine_tag_.empty()); | 700 DCHECK(current_machine_tag_.empty()); |
| 685 std::string persisted_guid; | 701 std::string persisted_guid; |
| 686 if (pref_service_) | 702 if (pref_service_) |
| 687 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); | 703 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); |
| 688 if (!persisted_guid.empty()) { | 704 if (!persisted_guid.empty()) { |
| 689 current_machine_tag_ = persisted_guid; | 705 current_machine_tag_ = persisted_guid; |
| 690 DVLOG(1) << "Restoring persisted session sync guid: " | 706 DVLOG(1) << "Restoring persisted session sync guid: " |
| 691 << persisted_guid; | 707 << persisted_guid; |
| 692 } else { | 708 } else { |
| 693 syncer::syncable::Directory* dir = | 709 current_machine_tag_ = GetMachineTagFromTransaction(trans); |
| 694 trans->GetWrappedWriteTrans()->directory(); | |
| 695 current_machine_tag_ = "session_sync"; | |
| 696 #if defined(OS_ANDROID) | |
| 697 const std::string android_id = syncer::internal::GetAndroidId(); | |
| 698 // There are reports that sometimes the android_id can't be read. Those | |
| 699 // are supposed to be fixed as of Gingerbread, but if it happens we fall | |
| 700 // back to use the same GUID generation as on other platforms. | |
| 701 current_machine_tag_.append(android_id.empty() ? | |
| 702 dir->cache_guid() : android_id); | |
| 703 #else | |
| 704 current_machine_tag_.append(dir->cache_guid()); | |
| 705 #endif | |
| 706 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; | 710 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; |
| 707 if (pref_service_) | 711 if (pref_service_) |
| 708 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); | 712 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); |
| 709 } | 713 } |
| 710 | 714 |
| 711 tab_pool_.set_machine_tag(current_machine_tag_); | 715 tab_pool_.set_machine_tag(current_machine_tag_); |
| 712 } | 716 } |
| 713 | 717 |
| 714 void SessionModelAssociator::OnSessionNameInitialized( | 718 void SessionModelAssociator::OnSessionNameInitialized( |
| 715 const std::string& name) { | 719 const std::string& name) { |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 | 1318 |
| 1315 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1319 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1316 // We only access the cryptographer while holding a transaction. | 1320 // We only access the cryptographer while holding a transaction. |
| 1317 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1321 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1318 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); | 1322 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); |
| 1319 return !encrypted_types.Has(SESSIONS) || | 1323 return !encrypted_types.Has(SESSIONS) || |
| 1320 sync_service_->IsCryptographerReady(&trans); | 1324 sync_service_->IsCryptographerReady(&trans); |
| 1321 } | 1325 } |
| 1322 | 1326 |
| 1323 } // namespace browser_sync | 1327 } // namespace browser_sync |
| OLD | NEW |