OLD | NEW |
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/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/signin/signin_manager.h" | 35 #include "chrome/browser/signin/signin_manager.h" |
36 #include "chrome/browser/signin/signin_manager_factory.h" | 36 #include "chrome/browser/signin/signin_manager_factory.h" |
37 #include "chrome/browser/signin/token_service.h" | 37 #include "chrome/browser/signin/token_service.h" |
38 #include "chrome/browser/signin/token_service_factory.h" | 38 #include "chrome/browser/signin/token_service_factory.h" |
39 #include "chrome/browser/sync/backend_migrator.h" | 39 #include "chrome/browser/sync/backend_migrator.h" |
40 #include "chrome/browser/sync/glue/change_processor.h" | 40 #include "chrome/browser/sync/glue/change_processor.h" |
41 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 41 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
42 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 42 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
43 #include "chrome/browser/sync/glue/data_type_controller.h" | 43 #include "chrome/browser/sync/glue/data_type_controller.h" |
44 #include "chrome/browser/sync/glue/device_info.h" | 44 #include "chrome/browser/sync/glue/device_info.h" |
| 45 #include "chrome/browser/sync/glue/favicon_cache.h" |
45 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 46 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
46 #include "chrome/browser/sync/glue/session_model_associator.h" | 47 #include "chrome/browser/sync/glue/session_model_associator.h" |
47 #include "chrome/browser/sync/glue/sync_backend_host.h" | 48 #include "chrome/browser/sync/glue/sync_backend_host.h" |
48 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" | 49 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
49 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 50 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
50 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 51 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
51 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 52 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 53 #include "chrome/browser/sync/sessions2/sessions_sync_manager.h" |
52 #include "chrome/browser/sync/sync_global_error.h" | 54 #include "chrome/browser/sync/sync_global_error.h" |
53 #include "chrome/browser/sync/user_selectable_sync_type.h" | 55 #include "chrome/browser/sync/user_selectable_sync_type.h" |
54 #include "chrome/browser/ui/browser.h" | 56 #include "chrome/browser/ui/browser.h" |
55 #include "chrome/browser/ui/browser_list.h" | 57 #include "chrome/browser/ui/browser_list.h" |
56 #include "chrome/browser/ui/browser_window.h" | 58 #include "chrome/browser/ui/browser_window.h" |
57 #include "chrome/browser/ui/global_error/global_error_service.h" | 59 #include "chrome/browser/ui/global_error/global_error_service.h" |
58 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 60 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
59 #include "chrome/common/chrome_switches.h" | 61 #include "chrome/common/chrome_switches.h" |
60 #include "chrome/common/chrome_version_info.h" | 62 #include "chrome/common/chrome_version_info.h" |
61 #include "chrome/common/pref_names.h" | 63 #include "chrome/common/pref_names.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // sync servers. Users with officially-branded Chrome stable and beta builds | 188 // sync servers. Users with officially-branded Chrome stable and beta builds |
187 // will go to the standard sync servers. | 189 // will go to the standard sync servers. |
188 // | 190 // |
189 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | 191 // GetChannel hits the registry on Windows. See http://crbug.com/70380. |
190 base::ThreadRestrictions::ScopedAllowIO allow_io; | 192 base::ThreadRestrictions::ScopedAllowIO allow_io; |
191 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 193 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
192 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 194 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
193 channel == chrome::VersionInfo::CHANNEL_BETA) { | 195 channel == chrome::VersionInfo::CHANNEL_BETA) { |
194 sync_service_url_ = GURL(kSyncServerUrl); | 196 sync_service_url_ = GURL(kSyncServerUrl); |
195 } | 197 } |
| 198 |
| 199 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 200 switches::kEnableSyncSessionsV2)) { |
| 201 sessions_sync_manager_.reset(new SessionsSyncManager(profile, this)); |
| 202 } |
196 } | 203 } |
197 | 204 |
198 ProfileSyncService::~ProfileSyncService() { | 205 ProfileSyncService::~ProfileSyncService() { |
199 sync_prefs_.RemoveSyncPrefObserver(this); | 206 sync_prefs_.RemoveSyncPrefObserver(this); |
200 // Shutdown() should have been called before destruction. | 207 // Shutdown() should have been called before destruction. |
201 CHECK(!backend_initialized_); | 208 CHECK(!backend_initialized_); |
202 } | 209 } |
203 | 210 |
204 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { | 211 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { |
205 // Exit if sync is disabled. | 212 // Exit if sync is disabled. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 358 } |
352 | 359 |
353 void ProfileSyncService::RegisterDataTypeController( | 360 void ProfileSyncService::RegisterDataTypeController( |
354 DataTypeController* data_type_controller) { | 361 DataTypeController* data_type_controller) { |
355 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 362 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
356 data_type_controllers_[data_type_controller->type()] = | 363 data_type_controllers_[data_type_controller->type()] = |
357 data_type_controller; | 364 data_type_controller; |
358 } | 365 } |
359 | 366 |
360 browser_sync::SessionModelAssociator* | 367 browser_sync::SessionModelAssociator* |
361 ProfileSyncService::GetSessionModelAssociator() { | 368 ProfileSyncService::GetSessionModelAssociatorDeprecated() { |
362 if (data_type_controllers_.find(syncer::SESSIONS) == | 369 if (data_type_controllers_.find(syncer::SESSIONS) == |
363 data_type_controllers_.end() || | 370 data_type_controllers_.end() || |
364 data_type_controllers_.find(syncer::SESSIONS)->second->state() != | 371 data_type_controllers_.find(syncer::SESSIONS)->second->state() != |
365 DataTypeController::RUNNING) { | 372 DataTypeController::RUNNING) { |
366 return NULL; | 373 return NULL; |
367 } | 374 } |
| 375 |
| 376 // If we're using sessions V2, there's no model associator. |
| 377 if (sessions_sync_manager_.get()) |
| 378 return NULL; |
| 379 |
368 return static_cast<browser_sync::SessionDataTypeController*>( | 380 return static_cast<browser_sync::SessionDataTypeController*>( |
369 data_type_controllers_.find( | 381 data_type_controllers_.find( |
370 syncer::SESSIONS)->second.get())->GetModelAssociator(); | 382 syncer::SESSIONS)->second.get())->GetModelAssociator(); |
371 } | 383 } |
372 | 384 |
| 385 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { |
| 386 if (data_type_controllers_.find(syncer::SESSIONS) == |
| 387 data_type_controllers_.end() || |
| 388 data_type_controllers_.find(syncer::SESSIONS)->second->state() != |
| 389 DataTypeController::RUNNING) { |
| 390 return NULL; |
| 391 } |
| 392 |
| 393 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 394 switches::kEnableSyncSessionsV2)) { |
| 395 return sessions_sync_manager_.get(); |
| 396 } else { |
| 397 return GetSessionModelAssociatorDeprecated(); |
| 398 } |
| 399 } |
| 400 |
| 401 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { |
| 402 // TODO(tim): Clean this up (or remove) once there's only one implementation. |
| 403 // Bug 98892. |
| 404 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 405 switches::kEnableSyncSessionsV2)) { |
| 406 return sessions_sync_manager_->GetFaviconCache(); |
| 407 } else if (GetSessionModelAssociatorDeprecated()) { |
| 408 return GetSessionModelAssociatorDeprecated()->GetFaviconCache(); |
| 409 } else { |
| 410 return NULL; |
| 411 } |
| 412 } |
| 413 |
373 scoped_ptr<browser_sync::DeviceInfo> | 414 scoped_ptr<browser_sync::DeviceInfo> |
374 ProfileSyncService::GetLocalDeviceInfo() const { | 415 ProfileSyncService::GetLocalDeviceInfo() const { |
375 if (backend_) { | 416 if (backend_) { |
376 browser_sync::SyncedDeviceTracker* device_tracker = | 417 browser_sync::SyncedDeviceTracker* device_tracker = |
377 backend_->GetSyncedDeviceTracker(); | 418 backend_->GetSyncedDeviceTracker(); |
378 if (device_tracker) | 419 if (device_tracker) |
379 return device_tracker->ReadLocalDeviceInfo(); | 420 return device_tracker->ReadLocalDeviceInfo(); |
380 } | 421 } |
381 return scoped_ptr<browser_sync::DeviceInfo>(); | 422 return scoped_ptr<browser_sync::DeviceInfo>(); |
382 } | 423 } |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 ConfigureDataTypeManager(); | 1063 ConfigureDataTypeManager(); |
1023 } else { | 1064 } else { |
1024 DCHECK(FirstSetupInProgress()); | 1065 DCHECK(FirstSetupInProgress()); |
1025 } | 1066 } |
1026 | 1067 |
1027 NotifyObservers(); | 1068 NotifyObservers(); |
1028 } | 1069 } |
1029 | 1070 |
1030 void ProfileSyncService::OnSyncCycleCompleted() { | 1071 void ProfileSyncService::OnSyncCycleCompleted() { |
1031 UpdateLastSyncedTime(); | 1072 UpdateLastSyncedTime(); |
1032 if (GetSessionModelAssociator()) { | 1073 if (GetSessionModelAssociatorDeprecated()) { |
1033 // Trigger garbage collection of old sessions now that we've downloaded | 1074 // Trigger garbage collection of old sessions now that we've downloaded |
1034 // any new session data. TODO(zea): Have this be a notification the session | 1075 // any new session data. TODO(zea): Have this be a notification the session |
1035 // model associator listens too. Also consider somehow plumbing the current | 1076 // model associator listens too. Also consider somehow plumbing the current |
1036 // server time as last reported by CheckServerReachable, so we don't have to | 1077 // server time as last reported by CheckServerReachable, so we don't have to |
1037 // rely on the local clock, which may be off significantly. | 1078 // rely on the local clock, which may be off significantly. |
1038 base::MessageLoop::current()->PostTask(FROM_HERE, | 1079 base::MessageLoop::current()->PostTask(FROM_HERE, |
1039 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, | 1080 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, |
1040 GetSessionModelAssociator()->AsWeakPtr())); | 1081 GetSessionModelAssociatorDeprecated()->AsWeakPtr())); |
1041 } | 1082 } |
1042 DVLOG(2) << "Notifying observers sync cycle completed"; | 1083 DVLOG(2) << "Notifying observers sync cycle completed"; |
1043 NotifySyncCycleCompleted(); | 1084 NotifySyncCycleCompleted(); |
1044 } | 1085 } |
1045 | 1086 |
1046 void ProfileSyncService::OnExperimentsChanged( | 1087 void ProfileSyncService::OnExperimentsChanged( |
1047 const syncer::Experiments& experiments) { | 1088 const syncer::Experiments& experiments) { |
1048 if (current_experiments_.Matches(experiments)) | 1089 if (current_experiments_.Matches(experiments)) |
1049 return; | 1090 return; |
1050 | 1091 |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2199 } | 2240 } |
2200 | 2241 |
2201 // TODO(fgorski): Use GetPrimaryAccountId() when it's available. | 2242 // TODO(fgorski): Use GetPrimaryAccountId() when it's available. |
2202 return signin_->GetAuthenticatedUsername(); | 2243 return signin_->GetAuthenticatedUsername(); |
2203 } | 2244 } |
2204 | 2245 |
2205 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { | 2246 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { |
2206 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); | 2247 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); |
2207 } | 2248 } |
2208 | 2249 |
| 2250 syncer::SyncableService* ProfileSyncService::GetSessionsSyncableService() { |
| 2251 return sessions_sync_manager_.get(); |
| 2252 } |
| 2253 |
2209 ProfileSyncService::SyncTokenStatus::SyncTokenStatus() | 2254 ProfileSyncService::SyncTokenStatus::SyncTokenStatus() |
2210 : connection_status(syncer::CONNECTION_NOT_ATTEMPTED), | 2255 : connection_status(syncer::CONNECTION_NOT_ATTEMPTED), |
2211 last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {} | 2256 last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {} |
2212 ProfileSyncService::SyncTokenStatus::~SyncTokenStatus() {} | 2257 ProfileSyncService::SyncTokenStatus::~SyncTokenStatus() {} |
2213 | 2258 |
2214 ProfileSyncService::SyncTokenStatus | 2259 ProfileSyncService::SyncTokenStatus |
2215 ProfileSyncService::GetSyncTokenStatus() const { | 2260 ProfileSyncService::GetSyncTokenStatus() const { |
2216 SyncTokenStatus status; | 2261 SyncTokenStatus status; |
2217 status.connection_status_update_time = connection_status_update_time_; | 2262 status.connection_status_update_time = connection_status_update_time_; |
2218 status.connection_status = connection_status_; | 2263 status.connection_status = connection_status_; |
2219 status.token_request_time = token_request_time_; | 2264 status.token_request_time = token_request_time_; |
2220 status.token_receive_time = token_receive_time_; | 2265 status.token_receive_time = token_receive_time_; |
2221 status.last_get_token_error = last_get_token_error_; | 2266 status.last_get_token_error = last_get_token_error_; |
2222 if (request_access_token_retry_timer_.IsRunning()) | 2267 if (request_access_token_retry_timer_.IsRunning()) |
2223 status.next_token_request_time = next_token_request_time_; | 2268 status.next_token_request_time = next_token_request_time_; |
2224 return status; | 2269 return status; |
2225 } | 2270 } |
OLD | NEW |