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

Side by Side Diff: chrome/browser/sync/glue/session_model_associator.cc

Issue 10966002: Add cache_guid accessor to UserShare (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/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 16 matching lines...) Expand all
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/navigation_entry.h" 29 #include "content/public/browser/navigation_entry.h"
30 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
32 #include "sync/api/sync_error.h" 32 #include "sync/api/sync_error.h"
33 #include "sync/internal_api/public/base/model_type.h" 33 #include "sync/internal_api/public/base/model_type.h"
34 #include "sync/internal_api/public/base/model_type_state_map.h" 34 #include "sync/internal_api/public/base/model_type_state_map.h"
35 #include "sync/internal_api/public/read_node.h" 35 #include "sync/internal_api/public/read_node.h"
36 #include "sync/internal_api/public/read_transaction.h" 36 #include "sync/internal_api/public/read_transaction.h"
37 #include "sync/internal_api/public/user_share.h"
37 #include "sync/internal_api/public/write_node.h" 38 #include "sync/internal_api/public/write_node.h"
38 #include "sync/internal_api/public/write_transaction.h" 39 #include "sync/internal_api/public/write_transaction.h"
39 #include "sync/protocol/session_specifics.pb.h" 40 #include "sync/protocol/session_specifics.pb.h"
40 #include "sync/syncable/directory.h"
41 #include "sync/syncable/read_transaction.h"
42 #include "sync/syncable/write_transaction.h"
43 #include "sync/util/get_session_name.h" 41 #include "sync/util/get_session_name.h"
44 #include "sync/util/time.h" 42 #include "sync/util/time.h"
45 #include "ui/gfx/favicon_size.h" 43 #include "ui/gfx/favicon_size.h"
46 #if defined(OS_LINUX) 44 #if defined(OS_LINUX)
47 #include "base/linux_util.h" 45 #include "base/linux_util.h"
48 #elif defined(OS_WIN) 46 #elif defined(OS_WIN)
49 #include <windows.h> 47 #include <windows.h>
50 #elif defined(OS_ANDROID) 48 #elif defined(OS_ANDROID)
51 #include "sync/util/session_utils_android.h" 49 #include "sync/util/session_utils_android.h"
52 #endif 50 #endif
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(model_type())) != 754 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(model_type())) !=
757 syncer::BaseNode::INIT_OK) { 755 syncer::BaseNode::INIT_OK) {
758 return error_handler_->CreateAndUploadError( 756 return error_handler_->CreateAndUploadError(
759 FROM_HERE, 757 FROM_HERE,
760 kNoSessionsFolderError, 758 kNoSessionsFolderError,
761 model_type()); 759 model_type());
762 } 760 }
763 761
764 // Make sure we have a machine tag. 762 // Make sure we have a machine tag.
765 if (current_machine_tag_.empty()) { 763 if (current_machine_tag_.empty()) {
766 InitializeCurrentMachineTag(&trans); 764 InitializeCurrentMachineTag(sync_service_->GetUserShare());
767 // The session name is retrieved asynchronously so it might not come back 765 // The session name is retrieved asynchronously so it might not come back
768 // for the writing of the session. However, we write to the session often 766 // for the writing of the session. However, we write to the session often
769 // enough (on every navigation) that we'll pick it up quickly. 767 // enough (on every navigation) that we'll pick it up quickly.
770 InitializeCurrentSessionName(); 768 InitializeCurrentSessionName();
771 } 769 }
772 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); 770 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_);
773 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) { 771 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) {
774 DCHECK(error.IsSet()); 772 DCHECK(error.IsSet());
775 return error; 773 return error;
776 } 774 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // There is no local model stored with which to disassociate, just notify 829 // There is no local model stored with which to disassociate, just notify
832 // foreign session handlers. 830 // foreign session handlers.
833 content::NotificationService::current()->Notify( 831 content::NotificationService::current()->Notify(
834 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, 832 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED,
835 content::Source<Profile>(sync_service_->profile()), 833 content::Source<Profile>(sync_service_->profile()),
836 content::NotificationService::NoDetails()); 834 content::NotificationService::NoDetails());
837 return syncer::SyncError(); 835 return syncer::SyncError();
838 } 836 }
839 837
840 void SessionModelAssociator::InitializeCurrentMachineTag( 838 void SessionModelAssociator::InitializeCurrentMachineTag(
841 syncer::WriteTransaction* trans) { 839 syncer::UserShare* share) {
842 DCHECK(CalledOnValidThread()); 840 DCHECK(CalledOnValidThread());
843 DCHECK(current_machine_tag_.empty()); 841 DCHECK(current_machine_tag_.empty());
844 std::string persisted_guid; 842 std::string persisted_guid;
845 if (pref_service_) 843 if (pref_service_)
846 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); 844 persisted_guid = pref_service_->GetString(kSyncSessionsGUID);
847 if (!persisted_guid.empty()) { 845 if (!persisted_guid.empty()) {
848 current_machine_tag_ = persisted_guid; 846 current_machine_tag_ = persisted_guid;
849 DVLOG(1) << "Restoring persisted session sync guid: " 847 DVLOG(1) << "Restoring persisted session sync guid: "
850 << persisted_guid; 848 << persisted_guid;
851 } else { 849 } else {
852 syncer::syncable::Directory* dir =
853 trans->GetWrappedWriteTrans()->directory();
854 current_machine_tag_ = "session_sync"; 850 current_machine_tag_ = "session_sync";
855 #if defined(OS_ANDROID) 851 #if defined(OS_ANDROID)
856 const std::string android_id = syncer::internal::GetAndroidId(); 852 const std::string android_id = syncer::internal::GetAndroidId();
857 // There are reports that sometimes the android_id can't be read. Those 853 // There are reports that sometimes the android_id can't be read. Those
858 // are supposed to be fixed as of Gingerbread, but if it happens we fall 854 // are supposed to be fixed as of Gingerbread, but if it happens we fall
859 // back to use the same GUID generation as on other platforms. 855 // back to use the same GUID generation as on other platforms.
860 current_machine_tag_.append(android_id.empty() ? 856 current_machine_tag_.append(android_id.empty() ?
861 dir->cache_guid() : android_id); 857 share->cache_guid() : android_id);
862 #else 858 #else
863 current_machine_tag_.append(dir->cache_guid()); 859 current_machine_tag_.append(share->cache_guid());
864 #endif 860 #endif
865 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; 861 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_;
866 if (pref_service_) 862 if (pref_service_)
867 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); 863 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_);
868 } 864 }
869 865
870 tab_pool_.set_machine_tag(current_machine_tag_); 866 tab_pool_.set_machine_tag(current_machine_tag_);
871 } 867 }
872 868
873 void SessionModelAssociator::OnSessionNameInitialized( 869 void SessionModelAssociator::OnSessionNameInitialized(
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 1593
1598 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1594 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1599 // We only access the cryptographer while holding a transaction. 1595 // We only access the cryptographer while holding a transaction.
1600 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1596 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1601 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 1597 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
1602 return !encrypted_types.Has(SESSIONS) || 1598 return !encrypted_types.Has(SESSIONS) ||
1603 sync_service_->IsCryptographerReady(&trans); 1599 sync_service_->IsCryptographerReady(&trans);
1604 } 1600 }
1605 1601
1606 } // namespace browser_sync 1602 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698