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

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

Issue 10985008: sync: Add DeviceInfo protobuf and supporting code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another missing include Created 8 years, 2 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
16 #include "chrome/browser/favicon/favicon_service_factory.h" 16 #include "chrome/browser/favicon/favicon_service_factory.h"
17 #include "chrome/browser/history/history.h" 17 #include "chrome/browser/history/history.h"
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/sessions/session_id.h" 20 #include "chrome/browser/sessions/session_id.h"
21 #include "chrome/browser/sync/glue/device_info.h"
21 #include "chrome/browser/sync/glue/synced_session.h" 22 #include "chrome/browser/sync/glue/synced_session.h"
22 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 23 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
23 #include "chrome/browser/sync/glue/synced_window_delegate.h" 24 #include "chrome/browser/sync/glue/synced_window_delegate.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/navigation_entry.h" 30 #include "content/public/browser/navigation_entry.h"
30 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 "Server did not create the top-level sessions node. We " 64 "Server did not create the top-level sessions node. We "
64 "might be running against an out-of-date server."; 65 "might be running against an out-of-date server.";
65 66
66 // The maximum number of navigations in each direction we care to sync. 67 // The maximum number of navigations in each direction we care to sync.
67 static const int kMaxSyncNavigationCount = 6; 68 static const int kMaxSyncNavigationCount = 6;
68 69
69 // Default number of days without activity after which a session is considered 70 // Default number of days without activity after which a session is considered
70 // stale and becomes a candidate for garbage collection. 71 // stale and becomes a candidate for garbage collection.
71 static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks. 72 static const size_t kDefaultStaleSessionThresholdDays = 14; // 2 weeks.
72 73
73 #if defined(OS_ANDROID)
74 bool IsTabletUI() {
75 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kTabletUI);
76 }
77 #endif
78
79 sync_pb::SessionHeader::DeviceType GetLocalDeviceType() {
80 // TODO(yfriedman): Refactor/combine with "DeviceInformation" code in
81 // sync_manager.cc[1060]
82 #if defined(OS_CHROMEOS)
83 return sync_pb::SessionHeader_DeviceType_TYPE_CROS;
84 #elif defined(OS_LINUX)
85 return sync_pb::SessionHeader_DeviceType_TYPE_LINUX;
86 #elif defined(OS_MACOSX)
87 return sync_pb::SessionHeader_DeviceType_TYPE_MAC;
88 #elif defined(OS_WIN)
89 return sync_pb::SessionHeader_DeviceType_TYPE_WIN;
90 #elif defined(OS_ANDROID)
91 return IsTabletUI() ?
92 sync_pb::SessionHeader_DeviceType_TYPE_TABLET :
93 sync_pb::SessionHeader_DeviceType_TYPE_PHONE;
94 #else
95 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER;
96 #endif
97 }
98
99 } // namespace 74 } // namespace
100 75
101 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service, 76 SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service,
102 DataTypeErrorHandler* error_handler) 77 DataTypeErrorHandler* error_handler)
103 : tab_pool_(sync_service), 78 : tab_pool_(sync_service),
104 local_session_syncid_(syncer::kInvalidId), 79 local_session_syncid_(syncer::kInvalidId),
105 sync_service_(sync_service), 80 sync_service_(sync_service),
106 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), 81 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
107 setup_for_test_(false), 82 setup_for_test_(false),
108 waiting_for_change_(false), 83 waiting_for_change_(false),
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 syncer::SyncError* error) { 171 syncer::SyncError* error) {
197 DCHECK(CalledOnValidThread()); 172 DCHECK(CalledOnValidThread());
198 std::string local_tag = GetCurrentMachineTag(); 173 std::string local_tag = GetCurrentMachineTag();
199 sync_pb::SessionSpecifics specifics; 174 sync_pb::SessionSpecifics specifics;
200 specifics.set_session_tag(local_tag); 175 specifics.set_session_tag(local_tag);
201 sync_pb::SessionHeader* header_s = specifics.mutable_header(); 176 sync_pb::SessionHeader* header_s = specifics.mutable_header();
202 SyncedSession* current_session = 177 SyncedSession* current_session =
203 synced_session_tracker_.GetSession(local_tag); 178 synced_session_tracker_.GetSession(local_tag);
204 current_session->modified_time = base::Time::Now(); 179 current_session->modified_time = base::Time::Now();
205 header_s->set_client_name(current_session_name_); 180 header_s->set_client_name(current_session_name_);
206 header_s->set_device_type(GetLocalDeviceType()); 181 header_s->set_device_type(DeviceInfo::GetLocalDeviceType());
207 182
208 synced_session_tracker_.ResetSessionTracking(local_tag); 183 synced_session_tracker_.ResetSessionTracking(local_tag);
209 std::set<SyncedWindowDelegate*> windows = 184 std::set<SyncedWindowDelegate*> windows =
210 SyncedWindowDelegate::GetSyncedWindowDelegates(); 185 SyncedWindowDelegate::GetSyncedWindowDelegates();
211 for (std::set<SyncedWindowDelegate*>::const_iterator i = 186 for (std::set<SyncedWindowDelegate*>::const_iterator i =
212 windows.begin(); i != windows.end(); ++i) { 187 windows.begin(); i != windows.end(); ++i) {
213 // Make sure the window has tabs and a viewable window. The viewable window 188 // Make sure the window has tabs and a viewable window. The viewable window
214 // check is necessary because, for example, when a browser is closed the 189 // check is necessary because, for example, when a browser is closed the
215 // destructor is not necessarily run immediately. This means its possible 190 // destructor is not necessarily run immediately. This means its possible
216 // for us to get a handle to a browser that is about to be removed. If 191 // for us to get a handle to a browser that is about to be removed. If
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 model_type()); 629 model_type());
655 } 630 }
656 631
657 // Write the initial values to the specifics so that in case of a crash or 632 // Write the initial values to the specifics so that in case of a crash or
658 // error we don't persist a half-written node. 633 // error we don't persist a half-written node.
659 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); 634 write_node.SetTitle(UTF8ToWide(current_machine_tag_));
660 sync_pb::SessionSpecifics base_specifics; 635 sync_pb::SessionSpecifics base_specifics;
661 base_specifics.set_session_tag(current_machine_tag_); 636 base_specifics.set_session_tag(current_machine_tag_);
662 sync_pb::SessionHeader* header_s = base_specifics.mutable_header(); 637 sync_pb::SessionHeader* header_s = base_specifics.mutable_header();
663 header_s->set_client_name(current_session_name_); 638 header_s->set_client_name(current_session_name_);
664 header_s->set_device_type(GetLocalDeviceType()); 639 header_s->set_device_type(DeviceInfo::GetLocalDeviceType());
665 write_node.SetSessionSpecifics(base_specifics); 640 write_node.SetSessionSpecifics(base_specifics);
666 641
667 local_session_syncid_ = write_node.GetId(); 642 local_session_syncid_ = write_node.GetId();
668 } 643 }
669 } 644 }
670 645
671 // Check if anything has changed on the client side. 646 // Check if anything has changed on the client side.
672 if (!UpdateSyncModelDataFromClient(&error)) { 647 if (!UpdateSyncModelDataFromClient(&error)) {
673 DCHECK(error.IsSet()); 648 DCHECK(error.IsSet());
674 return error; 649 return error;
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 // Static 955 // Static
981 void SessionModelAssociator::PopulateSessionHeaderFromSpecifics( 956 void SessionModelAssociator::PopulateSessionHeaderFromSpecifics(
982 const sync_pb::SessionHeader& header_specifics, 957 const sync_pb::SessionHeader& header_specifics,
983 base::Time mtime, 958 base::Time mtime,
984 SyncedSession* session_header) { 959 SyncedSession* session_header) {
985 if (header_specifics.has_client_name()) { 960 if (header_specifics.has_client_name()) {
986 session_header->session_name = header_specifics.client_name(); 961 session_header->session_name = header_specifics.client_name();
987 } 962 }
988 if (header_specifics.has_device_type()) { 963 if (header_specifics.has_device_type()) {
989 switch (header_specifics.device_type()) { 964 switch (header_specifics.device_type()) {
990 case sync_pb::SessionHeader_DeviceType_TYPE_WIN: 965 case sync_pb::SyncEnums_DeviceType_TYPE_WIN:
991 session_header->device_type = SyncedSession::TYPE_WIN; 966 session_header->device_type = SyncedSession::TYPE_WIN;
992 break; 967 break;
993 case sync_pb::SessionHeader_DeviceType_TYPE_MAC: 968 case sync_pb::SyncEnums_DeviceType_TYPE_MAC:
994 session_header->device_type = SyncedSession::TYPE_MACOSX; 969 session_header->device_type = SyncedSession::TYPE_MACOSX;
995 break; 970 break;
996 case sync_pb::SessionHeader_DeviceType_TYPE_LINUX: 971 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX:
997 session_header->device_type = SyncedSession::TYPE_LINUX; 972 session_header->device_type = SyncedSession::TYPE_LINUX;
998 break; 973 break;
999 case sync_pb::SessionHeader_DeviceType_TYPE_CROS: 974 case sync_pb::SyncEnums_DeviceType_TYPE_CROS:
1000 session_header->device_type = SyncedSession::TYPE_CHROMEOS; 975 session_header->device_type = SyncedSession::TYPE_CHROMEOS;
1001 break; 976 break;
1002 case sync_pb::SessionHeader_DeviceType_TYPE_PHONE: 977 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE:
1003 session_header->device_type = SyncedSession::TYPE_PHONE; 978 session_header->device_type = SyncedSession::TYPE_PHONE;
1004 break; 979 break;
1005 case sync_pb::SessionHeader_DeviceType_TYPE_TABLET: 980 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET:
1006 session_header->device_type = SyncedSession::TYPE_TABLET; 981 session_header->device_type = SyncedSession::TYPE_TABLET;
1007 break; 982 break;
1008 case sync_pb::SessionHeader_DeviceType_TYPE_OTHER: 983 case sync_pb::SyncEnums_DeviceType_TYPE_OTHER:
1009 // Intentionally fall-through 984 // Intentionally fall-through
1010 default: 985 default:
1011 session_header->device_type = SyncedSession::TYPE_OTHER; 986 session_header->device_type = SyncedSession::TYPE_OTHER;
1012 break; 987 break;
1013 } 988 }
1014 } 989 }
1015 session_header->modified_time = mtime; 990 session_header->modified_time = mtime;
1016 } 991 }
1017 992
1018 // Static 993 // Static
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 1312
1338 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1313 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1339 // We only access the cryptographer while holding a transaction. 1314 // We only access the cryptographer while holding a transaction.
1340 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1315 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1341 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 1316 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
1342 return !encrypted_types.Has(SESSIONS) || 1317 return !encrypted_types.Has(SESSIONS) ||
1343 sync_service_->IsCryptographerReady(&trans); 1318 sync_service_->IsCryptographerReady(&trans);
1344 } 1319 }
1345 1320
1346 } // namespace browser_sync 1321 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/model_association_manager.cc ('k') | chrome/browser/sync/glue/session_model_associator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698