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

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: made function private 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
« no previous file with comments | « no previous file | chrome/browser/sync/glue/synced_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 static const char kNoSessionsFolderError[] = 50 static const char kNoSessionsFolderError[] =
51 "Server did not create the top-level sessions node. We " 51 "Server did not create the top-level sessions node. We "
52 "might be running against an out-of-date server."; 52 "might be running against an out-of-date server.";
53 53
54 // The maximum number of navigations in each direction we care to sync. 54 // The maximum number of navigations in each direction we care to sync.
55 static const int kMaxSyncNavigationCount = 6; 55 static const int kMaxSyncNavigationCount = 6;
56 56
57 // Default number of days without activity after which a session is considered 57 // Default number of days without activity after which a session is considered
58 // stale and becomes a candidate for garbage collection. 58 // stale and becomes a candidate for garbage collection.
59 static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks. 59 static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks.
60
61 sync_pb::SessionHeader::DeviceType GetLocalDeviceType() {
62 #if defined(OS_CHROMEOS)
63 return sync_pb::SessionHeader_DeviceType_TYPE_CROS;
64 #elif defined(OS_LINUX)
65 return sync_pb::SessionHeader_DeviceType_TYPE_LINUX;
66 #elif defined(OS_MACOSX)
67 return sync_pb::SessionHeader_DeviceType_TYPE_MAC;
68 #elif defined(OS_WIN)
69 return sync_pb::SessionHeader_DeviceType_TYPE_WIN;
70 #elif defined(OS_ANDROID)
71 // TODO(yfriedman): Add logic to conditionally set device_type to tablet.
72 return sync_pb::SessionHeader_DeviceType_TYPE_PHONE;
73 #else
74 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER;
75 #endif
76 }
77
60 } // namespace 78 } // namespace
61 79
62 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service) 80 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service)
63 : tab_pool_(sync_service), 81 : tab_pool_(sync_service),
64 local_session_syncid_(sync_api::kInvalidId), 82 local_session_syncid_(sync_api::kInvalidId),
65 sync_service_(sync_service), 83 sync_service_(sync_service),
66 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), 84 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
67 setup_for_test_(false), 85 setup_for_test_(false),
68 waiting_for_change_(false), 86 waiting_for_change_(false),
69 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)), 87 ALLOW_THIS_IN_INITIALIZER_LIST(test_weak_factory_(this)),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 SyncError* error) { 164 SyncError* error) {
147 DCHECK(CalledOnValidThread()); 165 DCHECK(CalledOnValidThread());
148 std::string local_tag = GetCurrentMachineTag(); 166 std::string local_tag = GetCurrentMachineTag();
149 sync_pb::SessionSpecifics specifics; 167 sync_pb::SessionSpecifics specifics;
150 specifics.set_session_tag(local_tag); 168 specifics.set_session_tag(local_tag);
151 sync_pb::SessionHeader* header_s = specifics.mutable_header(); 169 sync_pb::SessionHeader* header_s = specifics.mutable_header();
152 SyncedSession* current_session = 170 SyncedSession* current_session =
153 synced_session_tracker_.GetSession(local_tag); 171 synced_session_tracker_.GetSession(local_tag);
154 current_session->modified_time = base::Time::Now(); 172 current_session->modified_time = base::Time::Now();
155 header_s->set_client_name(current_session_name_); 173 header_s->set_client_name(current_session_name_);
156 #if defined(OS_CHROMEOS) 174 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 175
168 synced_session_tracker_.ResetSessionTracking(local_tag); 176 synced_session_tracker_.ResetSessionTracking(local_tag);
169 std::set<SyncedWindowDelegate*> windows = 177 std::set<SyncedWindowDelegate*> windows =
170 SyncedWindowDelegate::GetSyncedWindowDelegates(); 178 SyncedWindowDelegate::GetSyncedWindowDelegates();
171 for (std::set<SyncedWindowDelegate*>::const_iterator i = 179 for (std::set<SyncedWindowDelegate*>::const_iterator i =
172 windows.begin(); i != windows.end(); ++i) { 180 windows.begin(); i != windows.end(); ++i) {
173 // Make sure the window has tabs and a viewable window. The viewable window 181 // 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 182 // check is necessary because, for example, when a browser is closed the
175 // destructor is not necessarily run immediately. This means its possible 183 // 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 184 // 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; 722 break;
715 case sync_pb::SessionHeader_DeviceType_TYPE_MAC: 723 case sync_pb::SessionHeader_DeviceType_TYPE_MAC:
716 session_header->device_type = SyncedSession::TYPE_MACOSX; 724 session_header->device_type = SyncedSession::TYPE_MACOSX;
717 break; 725 break;
718 case sync_pb::SessionHeader_DeviceType_TYPE_LINUX: 726 case sync_pb::SessionHeader_DeviceType_TYPE_LINUX:
719 session_header->device_type = SyncedSession::TYPE_LINUX; 727 session_header->device_type = SyncedSession::TYPE_LINUX;
720 break; 728 break;
721 case sync_pb::SessionHeader_DeviceType_TYPE_CROS: 729 case sync_pb::SessionHeader_DeviceType_TYPE_CROS:
722 session_header->device_type = SyncedSession::TYPE_CHROMEOS; 730 session_header->device_type = SyncedSession::TYPE_CHROMEOS;
723 break; 731 break;
732 case sync_pb::SessionHeader_DeviceType_TYPE_PHONE:
733 session_header->device_type = SyncedSession::TYPE_PHONE;
734 break;
735 case sync_pb::SessionHeader_DeviceType_TYPE_TABLET:
736 session_header->device_type = SyncedSession::TYPE_TABLET;
737 break;
724 case sync_pb::SessionHeader_DeviceType_TYPE_OTHER: 738 case sync_pb::SessionHeader_DeviceType_TYPE_OTHER:
725 // Intentionally fall-through 739 // Intentionally fall-through
726 default: 740 default:
727 session_header->device_type = SyncedSession::TYPE_OTHER; 741 session_header->device_type = SyncedSession::TYPE_OTHER;
728 break; 742 break;
729 } 743 }
730 } 744 }
731 session_header->modified_time = mtime; 745 session_header->modified_time = mtime;
732 } 746 }
733 747
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
« no previous file with comments | « no previous file | chrome/browser/sync/glue/synced_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698