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

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

Issue 9664008: Add Phone/Tablet device types for syncing session from Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: self-review Created 8 years, 9 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 SyncError* error) { 146 SyncError* error) {
147 DCHECK(CalledOnValidThread()); 147 DCHECK(CalledOnValidThread());
148 std::string local_tag = GetCurrentMachineTag(); 148 std::string local_tag = GetCurrentMachineTag();
149 sync_pb::SessionSpecifics specifics; 149 sync_pb::SessionSpecifics specifics;
150 specifics.set_session_tag(local_tag); 150 specifics.set_session_tag(local_tag);
151 sync_pb::SessionHeader* header_s = specifics.mutable_header(); 151 sync_pb::SessionHeader* header_s = specifics.mutable_header();
152 SyncedSession* current_session = 152 SyncedSession* current_session =
153 synced_session_tracker_.GetSession(local_tag); 153 synced_session_tracker_.GetSession(local_tag);
154 current_session->modified_time = base::Time::Now(); 154 current_session->modified_time = base::Time::Now();
155 header_s->set_client_name(current_session_name_); 155 header_s->set_client_name(current_session_name_);
156 #if defined(OS_CHROMEOS) 156 header_s->set_device_type(GetLocalDeviceType());
157 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_CROS);
158 #elif defined(OS_LINUX)
159 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_LINUX);
160 #elif defined(OS_MACOSX)
161 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_MAC);
162 #elif defined(OS_WIN)
163 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN);
164 #else
165 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_OTHER);
166 #endif
167 157
168 synced_session_tracker_.ResetSessionTracking(local_tag); 158 synced_session_tracker_.ResetSessionTracking(local_tag);
169 std::set<SyncedWindowDelegate*> windows = 159 std::set<SyncedWindowDelegate*> windows =
170 SyncedWindowDelegate::GetSyncedWindowDelegates(); 160 SyncedWindowDelegate::GetSyncedWindowDelegates();
171 for (std::set<SyncedWindowDelegate*>::const_iterator i = 161 for (std::set<SyncedWindowDelegate*>::const_iterator i =
172 windows.begin(); i != windows.end(); ++i) { 162 windows.begin(); i != windows.end(); ++i) {
173 // Make sure the window has tabs and a viewable window. The viewable window 163 // Make sure the window has tabs and a viewable window. The viewable window
174 // check is necessary because, for example, when a browser is closed the 164 // check is necessary because, for example, when a browser is closed the
175 // destructor is not necessarily run immediately. This means its possible 165 // destructor is not necessarily run immediately. This means its possible
176 // for us to get a handle to a browser that is about to be removed. If 166 // for us to get a handle to a browser that is about to be removed. If
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 break; 704 break;
715 case sync_pb::SessionHeader_DeviceType_TYPE_MAC: 705 case sync_pb::SessionHeader_DeviceType_TYPE_MAC:
716 session_header->device_type = SyncedSession::TYPE_MACOSX; 706 session_header->device_type = SyncedSession::TYPE_MACOSX;
717 break; 707 break;
718 case sync_pb::SessionHeader_DeviceType_TYPE_LINUX: 708 case sync_pb::SessionHeader_DeviceType_TYPE_LINUX:
719 session_header->device_type = SyncedSession::TYPE_LINUX; 709 session_header->device_type = SyncedSession::TYPE_LINUX;
720 break; 710 break;
721 case sync_pb::SessionHeader_DeviceType_TYPE_CROS: 711 case sync_pb::SessionHeader_DeviceType_TYPE_CROS:
722 session_header->device_type = SyncedSession::TYPE_CHROMEOS; 712 session_header->device_type = SyncedSession::TYPE_CHROMEOS;
723 break; 713 break;
714 case sync_pb::SessionHeader_DeviceType_TYPE_PHONE:
715 session_header->device_type = SyncedSession::TYPE_PHONE;
716 break;
717 case sync_pb::SessionHeader_DeviceType_TYPE_TABLET:
718 session_header->device_type = SyncedSession::TYPE_TABLET;
719 break;
724 case sync_pb::SessionHeader_DeviceType_TYPE_OTHER: 720 case sync_pb::SessionHeader_DeviceType_TYPE_OTHER:
725 // Intentionally fall-through 721 // Intentionally fall-through
726 default: 722 default:
727 session_header->device_type = SyncedSession::TYPE_OTHER; 723 session_header->device_type = SyncedSession::TYPE_OTHER;
728 break; 724 break;
729 } 725 }
730 } 726 }
731 session_header->modified_time = mtime; 727 session_header->modified_time = mtime;
732 } 728 }
733 729
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 return false; 1072 return false;
1077 if (entry->GetVirtualURL().is_valid() && 1073 if (entry->GetVirtualURL().is_valid() &&
1078 !entry->GetVirtualURL().SchemeIs("chrome") && 1074 !entry->GetVirtualURL().SchemeIs("chrome") &&
1079 !entry->GetVirtualURL().SchemeIsFile()) { 1075 !entry->GetVirtualURL().SchemeIsFile()) {
1080 found_valid_url = true; 1076 found_valid_url = true;
1081 } 1077 }
1082 } 1078 }
1083 return found_valid_url; 1079 return found_valid_url;
1084 } 1080 }
1085 1081
1082 sync_pb::SessionHeader::DeviceType
1083 SessionModelAssociator::GetLocalDeviceType() {
1084 #if defined(OS_CHROMEOS)
1085 return sync_pb::SessionHeader_DeviceType_TYPE_CROS;
1086 #elif defined(OS_LINUX)
1087 return sync_pb::SessionHeader_DeviceType_TYPE_LINUX;
1088 #elif defined(OS_MACOSX)
1089 return sync_pb::SessionHeader_DeviceType_TYPE_MAC;
1090 #elif defined(OS_WIN)
1091 return sync_pb::SessionHeader_DeviceType_TYPE_WIN;
1092 #elif defined(OS_ANDROID)
1093 // TODO(yfriedman): Add logic to conditionally set device_type to tablet.
1094 return sync_pb::SessionHeader_DeviceType_TYPE_PHONE;
1095 #else
1096 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER;
1097 #endif
1098 }
1099
1086 // If this functionality changes, SyncedSession::ShouldSyncSessionTab should be 1100 // If this functionality changes, SyncedSession::ShouldSyncSessionTab should be
1087 // modified to match. 1101 // modified to match.
1088 bool SessionModelAssociator::ShouldSyncTab(const SyncedTabDelegate& tab) const { 1102 bool SessionModelAssociator::ShouldSyncTab(const SyncedTabDelegate& tab) const {
1089 DCHECK(CalledOnValidThread()); 1103 DCHECK(CalledOnValidThread());
1090 if (!IsValidTab(tab)) 1104 if (!IsValidTab(tab))
1091 return false; 1105 return false;
1092 return TabHasValidEntry(tab); 1106 return TabHasValidEntry(tab);
1093 } 1107 }
1094 1108
1095 void SessionModelAssociator::QuitLoopForSubtleTesting() { 1109 void SessionModelAssociator::QuitLoopForSubtleTesting() {
(...skipping 20 matching lines...) Expand all
1116 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1130 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1117 // We only access the cryptographer while holding a transaction. 1131 // We only access the cryptographer while holding a transaction.
1118 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1132 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1119 const syncable::ModelTypeSet encrypted_types = 1133 const syncable::ModelTypeSet encrypted_types =
1120 sync_api::GetEncryptedTypes(&trans); 1134 sync_api::GetEncryptedTypes(&trans);
1121 return !encrypted_types.Has(SESSIONS) || 1135 return !encrypted_types.Has(SESSIONS) ||
1122 sync_service_->IsCryptographerReady(&trans); 1136 sync_service_->IsCryptographerReady(&trans);
1123 } 1137 }
1124 1138
1125 } // namespace browser_sync 1139 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698