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

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: Update + back to small patch Created 8 years, 1 month 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 18 matching lines...) Expand all
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "content/public/browser/navigation_entry.h" 30 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "sync/api/sync_error.h" 33 #include "sync/api/sync_error.h"
34 #include "sync/api/time.h" 34 #include "sync/api/time.h"
35 #include "sync/internal_api/public/base/model_type.h" 35 #include "sync/internal_api/public/base/model_type.h"
36 #include "sync/internal_api/public/base/model_type_invalidation_map.h" 36 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
37 #include "sync/internal_api/public/read_node.h" 37 #include "sync/internal_api/public/read_node.h"
38 #include "sync/internal_api/public/read_transaction.h" 38 #include "sync/internal_api/public/read_transaction.h"
39 #include "sync/internal_api/public/user_share.h"
39 #include "sync/internal_api/public/write_node.h" 40 #include "sync/internal_api/public/write_node.h"
40 #include "sync/internal_api/public/write_transaction.h" 41 #include "sync/internal_api/public/write_transaction.h"
41 #include "sync/protocol/session_specifics.pb.h" 42 #include "sync/protocol/session_specifics.pb.h"
42 #include "sync/syncable/directory.h"
43 #include "sync/syncable/read_transaction.h"
44 #include "sync/syncable/write_transaction.h"
45 #include "sync/util/get_session_name.h" 43 #include "sync/util/get_session_name.h"
46 #include "ui/gfx/favicon_size.h" 44 #include "ui/gfx/favicon_size.h"
47 #if defined(OS_LINUX) 45 #if defined(OS_LINUX)
48 #include "base/linux_util.h" 46 #include "base/linux_util.h"
49 #elif defined(OS_WIN) 47 #elif defined(OS_WIN)
50 #include <windows.h> 48 #include <windows.h>
51 #elif defined(OS_ANDROID) 49 #elif defined(OS_ANDROID)
52 #include "sync/util/session_utils_android.h" 50 #include "sync/util/session_utils_android.h"
53 #endif 51 #endif
54 52
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(model_type())) != 593 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(model_type())) !=
596 syncer::BaseNode::INIT_OK) { 594 syncer::BaseNode::INIT_OK) {
597 return error_handler_->CreateAndUploadError( 595 return error_handler_->CreateAndUploadError(
598 FROM_HERE, 596 FROM_HERE,
599 kNoSessionsFolderError, 597 kNoSessionsFolderError,
600 model_type()); 598 model_type());
601 } 599 }
602 600
603 // Make sure we have a machine tag. 601 // Make sure we have a machine tag.
604 if (current_machine_tag_.empty()) { 602 if (current_machine_tag_.empty()) {
605 InitializeCurrentMachineTag(&trans); 603 InitializeCurrentMachineTag(sync_service_->GetUserShare());
606 // The session name is retrieved asynchronously so it might not come back 604 // The session name is retrieved asynchronously so it might not come back
607 // for the writing of the session. However, we write to the session often 605 // for the writing of the session. However, we write to the session often
608 // enough (on every navigation) that we'll pick it up quickly. 606 // enough (on every navigation) that we'll pick it up quickly.
609 InitializeCurrentSessionName(); 607 InitializeCurrentSessionName();
610 } 608 }
611 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); 609 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_);
612 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) { 610 if (!UpdateAssociationsFromSyncModel(root, &trans, &error)) {
613 DCHECK(error.IsSet()); 611 DCHECK(error.IsSet());
614 return error; 612 return error;
615 } 613 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 // There is no local model stored with which to disassociate, just notify 668 // There is no local model stored with which to disassociate, just notify
671 // foreign session handlers. 669 // foreign session handlers.
672 content::NotificationService::current()->Notify( 670 content::NotificationService::current()->Notify(
673 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, 671 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED,
674 content::Source<Profile>(sync_service_->profile()), 672 content::Source<Profile>(sync_service_->profile()),
675 content::NotificationService::NoDetails()); 673 content::NotificationService::NoDetails());
676 return syncer::SyncError(); 674 return syncer::SyncError();
677 } 675 }
678 676
679 void SessionModelAssociator::InitializeCurrentMachineTag( 677 void SessionModelAssociator::InitializeCurrentMachineTag(
680 syncer::WriteTransaction* trans) { 678 syncer::UserShare* share) {
681 DCHECK(CalledOnValidThread()); 679 DCHECK(CalledOnValidThread());
682 DCHECK(current_machine_tag_.empty()); 680 DCHECK(current_machine_tag_.empty());
683 std::string persisted_guid; 681 std::string persisted_guid;
684 if (pref_service_) 682 if (pref_service_)
685 persisted_guid = pref_service_->GetString(kSyncSessionsGUID); 683 persisted_guid = pref_service_->GetString(kSyncSessionsGUID);
686 if (!persisted_guid.empty()) { 684 if (!persisted_guid.empty()) {
687 current_machine_tag_ = persisted_guid; 685 current_machine_tag_ = persisted_guid;
688 DVLOG(1) << "Restoring persisted session sync guid: " 686 DVLOG(1) << "Restoring persisted session sync guid: "
689 << persisted_guid; 687 << persisted_guid;
690 } else { 688 } else {
691 syncer::syncable::Directory* dir =
692 trans->GetWrappedWriteTrans()->directory();
693 current_machine_tag_ = "session_sync"; 689 current_machine_tag_ = "session_sync";
694 #if defined(OS_ANDROID) 690 #if defined(OS_ANDROID)
695 const std::string android_id = syncer::internal::GetAndroidId(); 691 const std::string android_id = syncer::internal::GetAndroidId();
696 // There are reports that sometimes the android_id can't be read. Those 692 // There are reports that sometimes the android_id can't be read. Those
697 // are supposed to be fixed as of Gingerbread, but if it happens we fall 693 // are supposed to be fixed as of Gingerbread, but if it happens we fall
698 // back to use the same GUID generation as on other platforms. 694 // back to use the same GUID generation as on other platforms.
699 current_machine_tag_.append(android_id.empty() ? 695 current_machine_tag_.append(android_id.empty() ?
700 dir->cache_guid() : android_id); 696 share->cache_guid() : android_id);
701 #else 697 #else
702 current_machine_tag_.append(dir->cache_guid()); 698 current_machine_tag_.append(share->cache_guid());
703 #endif 699 #endif
704 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; 700 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_;
705 if (pref_service_) 701 if (pref_service_)
706 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_); 702 pref_service_->SetString(kSyncSessionsGUID, current_machine_tag_);
707 } 703 }
708 704
709 tab_pool_.set_machine_tag(current_machine_tag_); 705 tab_pool_.set_machine_tag(current_machine_tag_);
710 } 706 }
711 707
712 void SessionModelAssociator::OnSessionNameInitialized( 708 void SessionModelAssociator::OnSessionNameInitialized(
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 1308
1313 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1309 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1314 // We only access the cryptographer while holding a transaction. 1310 // We only access the cryptographer while holding a transaction.
1315 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1311 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1316 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 1312 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
1317 return !encrypted_types.Has(SESSIONS) || 1313 return !encrypted_types.Has(SESSIONS) ||
1318 sync_service_->IsCryptographerReady(&trans); 1314 sync_service_->IsCryptographerReady(&trans);
1319 } 1315 }
1320 1316
1321 } // namespace browser_sync 1317 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.h ('k') | sync/internal_api/public/user_share.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698