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 |
60 namespace browser_sync { | 58 namespace browser_sync { |
61 | 59 |
62 namespace { | 60 namespace { |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); | 634 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); |
637 sync_pb::SessionSpecifics base_specifics; | 635 sync_pb::SessionSpecifics base_specifics; |
638 base_specifics.set_session_tag(current_machine_tag_); | 636 base_specifics.set_session_tag(current_machine_tag_); |
639 sync_pb::SessionHeader* header_s = base_specifics.mutable_header(); | 637 sync_pb::SessionHeader* header_s = base_specifics.mutable_header(); |
640 header_s->set_client_name(current_session_name_); | 638 header_s->set_client_name(current_session_name_); |
641 header_s->set_device_type(DeviceInfo::GetLocalDeviceType()); | 639 header_s->set_device_type(DeviceInfo::GetLocalDeviceType()); |
642 write_node.SetSessionSpecifics(base_specifics); | 640 write_node.SetSessionSpecifics(base_specifics); |
643 | 641 |
644 local_session_syncid_ = write_node.GetId(); | 642 local_session_syncid_ = write_node.GetId(); |
645 } | 643 } |
644 #if defined(OS_ANDROID) | |
645 std::string persisted_machine_tag; | |
Nicolas Zea
2012/11/16 18:55:20
I don't think you need this variable, doesn't curr
nyquist
2012/12/04 01:55:05
Done.
| |
646 if (pref_service_) | |
647 persisted_machine_tag = pref_service_->GetString(kSyncSessionsGUID); | |
648 | |
649 std::string transaction_tag = GetMachineTagFromTransaction(&trans); | |
650 if (persisted_machine_tag.compare(transaction_tag) != 0) { | |
651 DeleteForeignSession(transaction_tag); | |
652 } | |
653 #endif | |
646 } | 654 } |
647 | 655 |
648 // Check if anything has changed on the client side. | 656 // Check if anything has changed on the client side. |
649 if (!UpdateSyncModelDataFromClient(&error)) { | 657 if (!UpdateSyncModelDataFromClient(&error)) { |
650 DCHECK(error.IsSet()); | 658 DCHECK(error.IsSet()); |
651 return error; | 659 return error; |
652 } | 660 } |
653 | 661 |
654 DVLOG(1) << "Session models associated."; | 662 DVLOG(1) << "Session models associated."; |
655 DCHECK(!error.IsSet()); | 663 DCHECK(!error.IsSet()); |
(...skipping 27 matching lines...) Expand all Loading... | |
683 DCHECK(CalledOnValidThread()); | 691 DCHECK(CalledOnValidThread()); |
684 DCHECK(current_machine_tag_.empty()); | 692 DCHECK(current_machine_tag_.empty()); |
685 std::string persisted_guid; | 693 std::string persisted_guid; |
686 if (pref_service_) | 694 if (pref_service_) |
687 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); | 695 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); |
688 if (!persisted_guid.empty()) { | 696 if (!persisted_guid.empty()) { |
689 current_machine_tag_ = persisted_guid; | 697 current_machine_tag_ = persisted_guid; |
690 DVLOG(1) << "Restoring persisted session sync guid: " | 698 DVLOG(1) << "Restoring persisted session sync guid: " |
691 << persisted_guid; | 699 << persisted_guid; |
692 } else { | 700 } else { |
693 syncer::syncable::Directory* dir = | 701 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_; | 702 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; |
707 if (pref_service_) | 703 if (pref_service_) |
708 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); | 704 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); |
709 } | 705 } |
710 | 706 |
711 tab_pool_.set_machine_tag(current_machine_tag_); | 707 tab_pool_.set_machine_tag(current_machine_tag_); |
712 } | 708 } |
713 | 709 |
714 void SessionModelAssociator::OnSessionNameInitialized( | 710 void SessionModelAssociator::OnSessionNameInitialized( |
715 const std::string& name) { | 711 const std::string& name) { |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 return false; | 1271 return false; |
1276 if (entry->GetVirtualURL().is_valid() && | 1272 if (entry->GetVirtualURL().is_valid() && |
1277 !entry->GetVirtualURL().SchemeIs("chrome") && | 1273 !entry->GetVirtualURL().SchemeIs("chrome") && |
1278 !entry->GetVirtualURL().SchemeIsFile()) { | 1274 !entry->GetVirtualURL().SchemeIsFile()) { |
1279 found_valid_url = true; | 1275 found_valid_url = true; |
1280 } | 1276 } |
1281 } | 1277 } |
1282 return found_valid_url; | 1278 return found_valid_url; |
1283 } | 1279 } |
1284 | 1280 |
1281 std::string SessionModelAssociator::GetMachineTagFromTransaction( | |
Nicolas Zea
2012/11/16 18:55:20
Since this is basically a static helper method, I
nyquist
2012/12/04 01:55:05
Done.
| |
1282 syncer::WriteTransaction* trans) { | |
1283 syncer::syncable::Directory* dir = trans->GetWrappedWriteTrans()->directory(); | |
1284 std::string machine_tag = "session_sync"; | |
1285 machine_tag.append(dir->cache_guid()); | |
1286 return machine_tag; | |
1287 } | |
1288 | |
1285 // If this functionality changes, SyncedSession::ShouldSyncSessionTab should be | 1289 // If this functionality changes, SyncedSession::ShouldSyncSessionTab should be |
1286 // modified to match. | 1290 // modified to match. |
1287 bool SessionModelAssociator::ShouldSyncTab(const SyncedTabDelegate& tab) const { | 1291 bool SessionModelAssociator::ShouldSyncTab(const SyncedTabDelegate& tab) const { |
1288 DCHECK(CalledOnValidThread()); | 1292 DCHECK(CalledOnValidThread()); |
1289 if (!IsValidTab(tab)) | 1293 if (!IsValidTab(tab)) |
1290 return false; | 1294 return false; |
1291 return TabHasValidEntry(tab); | 1295 return TabHasValidEntry(tab); |
1292 } | 1296 } |
1293 | 1297 |
1294 void SessionModelAssociator::QuitLoopForSubtleTesting() { | 1298 void SessionModelAssociator::QuitLoopForSubtleTesting() { |
(...skipping 19 matching lines...) Expand all 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 |