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 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 33 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
34 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 34 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
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/sync/backend_migrator.h" | 37 #include "chrome/browser/sync/backend_migrator.h" |
38 #include "chrome/browser/sync/glue/change_processor.h" | 38 #include "chrome/browser/sync/glue/change_processor.h" |
39 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 39 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
41 #include "chrome/browser/sync/glue/data_type_controller.h" | 41 #include "chrome/browser/sync/glue/data_type_controller.h" |
42 #include "chrome/browser/sync/glue/device_info.h" | 42 #include "chrome/browser/sync/glue/device_info.h" |
| 43 #include "chrome/browser/sync/glue/favicon_cache.h" |
43 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 44 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
44 #include "chrome/browser/sync/glue/session_model_associator.h" | 45 #include "chrome/browser/sync/glue/session_model_associator.h" |
45 #include "chrome/browser/sync/glue/sync_backend_host.h" | 46 #include "chrome/browser/sync/glue/sync_backend_host.h" |
46 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" | 47 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
47 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 48 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
48 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 49 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
49 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 50 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 51 #include "chrome/browser/sync/sessions2/sessions_sync_manager.h" |
50 #include "chrome/browser/sync/sync_global_error.h" | 52 #include "chrome/browser/sync/sync_global_error.h" |
51 #include "chrome/browser/sync/user_selectable_sync_type.h" | 53 #include "chrome/browser/sync/user_selectable_sync_type.h" |
52 #include "chrome/browser/ui/browser.h" | 54 #include "chrome/browser/ui/browser.h" |
53 #include "chrome/browser/ui/browser_list.h" | 55 #include "chrome/browser/ui/browser_list.h" |
54 #include "chrome/browser/ui/browser_window.h" | 56 #include "chrome/browser/ui/browser_window.h" |
55 #include "chrome/browser/ui/global_error/global_error_service.h" | 57 #include "chrome/browser/ui/global_error/global_error_service.h" |
56 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 58 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
57 #include "chrome/common/chrome_switches.h" | 59 #include "chrome/common/chrome_switches.h" |
58 #include "chrome/common/chrome_version_info.h" | 60 #include "chrome/common/chrome_version_info.h" |
59 #include "chrome/common/pref_names.h" | 61 #include "chrome/common/pref_names.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // sync servers. Users with officially-branded Chrome stable and beta builds | 186 // sync servers. Users with officially-branded Chrome stable and beta builds |
185 // will go to the standard sync servers. | 187 // will go to the standard sync servers. |
186 // | 188 // |
187 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | 189 // GetChannel hits the registry on Windows. See http://crbug.com/70380. |
188 base::ThreadRestrictions::ScopedAllowIO allow_io; | 190 base::ThreadRestrictions::ScopedAllowIO allow_io; |
189 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 191 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
190 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 192 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
191 channel == chrome::VersionInfo::CHANNEL_BETA) { | 193 channel == chrome::VersionInfo::CHANNEL_BETA) { |
192 sync_service_url_ = GURL(kSyncServerUrl); | 194 sync_service_url_ = GURL(kSyncServerUrl); |
193 } | 195 } |
| 196 |
| 197 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 switches::kEnableSyncSessionsV2)) { |
| 199 sessions_sync_manager_.reset(new SessionsSyncManager(profile, this)); |
| 200 } |
194 } | 201 } |
195 | 202 |
196 ProfileSyncService::~ProfileSyncService() { | 203 ProfileSyncService::~ProfileSyncService() { |
197 sync_prefs_.RemoveSyncPrefObserver(this); | 204 sync_prefs_.RemoveSyncPrefObserver(this); |
198 // Shutdown() should have been called before destruction. | 205 // Shutdown() should have been called before destruction. |
199 CHECK(!backend_initialized_); | 206 CHECK(!backend_initialized_); |
200 } | 207 } |
201 | 208 |
202 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { | 209 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { |
203 // Exit if sync is disabled. | 210 // Exit if sync is disabled. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 349 } |
343 | 350 |
344 void ProfileSyncService::RegisterDataTypeController( | 351 void ProfileSyncService::RegisterDataTypeController( |
345 DataTypeController* data_type_controller) { | 352 DataTypeController* data_type_controller) { |
346 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 353 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
347 data_type_controllers_[data_type_controller->type()] = | 354 data_type_controllers_[data_type_controller->type()] = |
348 data_type_controller; | 355 data_type_controller; |
349 } | 356 } |
350 | 357 |
351 browser_sync::SessionModelAssociator* | 358 browser_sync::SessionModelAssociator* |
352 ProfileSyncService::GetSessionModelAssociator() { | 359 ProfileSyncService::GetSessionModelAssociatorDeprecated() { |
353 if (data_type_controllers_.find(syncer::SESSIONS) == | 360 if (data_type_controllers_.find(syncer::SESSIONS) == |
354 data_type_controllers_.end() || | 361 data_type_controllers_.end() || |
355 data_type_controllers_.find(syncer::SESSIONS)->second->state() != | 362 data_type_controllers_.find(syncer::SESSIONS)->second->state() != |
356 DataTypeController::RUNNING) { | 363 DataTypeController::RUNNING) { |
357 return NULL; | 364 return NULL; |
358 } | 365 } |
| 366 |
| 367 // If we're using sessions V2, there's no model associator. |
| 368 if (sessions_sync_manager_.get()) |
| 369 return NULL; |
| 370 |
359 return static_cast<browser_sync::SessionDataTypeController*>( | 371 return static_cast<browser_sync::SessionDataTypeController*>( |
360 data_type_controllers_.find( | 372 data_type_controllers_.find( |
361 syncer::SESSIONS)->second.get())->GetModelAssociator(); | 373 syncer::SESSIONS)->second.get())->GetModelAssociator(); |
362 } | 374 } |
363 | 375 |
| 376 browser_sync::OpenTabsUIDelegate* ProfileSyncService::GetOpenTabsUIDelegate() { |
| 377 if (data_type_controllers_.find(syncer::SESSIONS) == |
| 378 data_type_controllers_.end() || |
| 379 data_type_controllers_.find(syncer::SESSIONS)->second->state() != |
| 380 DataTypeController::RUNNING) { |
| 381 return NULL; |
| 382 } |
| 383 |
| 384 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 385 switches::kEnableSyncSessionsV2)) { |
| 386 return sessions_sync_manager_.get(); |
| 387 } else { |
| 388 return GetSessionModelAssociatorDeprecated(); |
| 389 } |
| 390 } |
| 391 |
| 392 browser_sync::FaviconCache* ProfileSyncService::GetFaviconCache() { |
| 393 // TODO(tim): Clean this up (or remove) once there's only one implementation. |
| 394 // Bug 98892. |
| 395 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 396 switches::kEnableSyncSessionsV2)) { |
| 397 return sessions_sync_manager_->GetFaviconCache(); |
| 398 } else if (GetSessionModelAssociatorDeprecated()) { |
| 399 return GetSessionModelAssociatorDeprecated()->GetFaviconCache(); |
| 400 } else { |
| 401 return NULL; |
| 402 } |
| 403 } |
| 404 |
364 scoped_ptr<browser_sync::DeviceInfo> | 405 scoped_ptr<browser_sync::DeviceInfo> |
365 ProfileSyncService::GetLocalDeviceInfo() const { | 406 ProfileSyncService::GetLocalDeviceInfo() const { |
366 if (backend_) { | 407 if (backend_) { |
367 browser_sync::SyncedDeviceTracker* device_tracker = | 408 browser_sync::SyncedDeviceTracker* device_tracker = |
368 backend_->GetSyncedDeviceTracker(); | 409 backend_->GetSyncedDeviceTracker(); |
369 if (device_tracker) | 410 if (device_tracker) |
370 return device_tracker->ReadLocalDeviceInfo(); | 411 return device_tracker->ReadLocalDeviceInfo(); |
371 } | 412 } |
372 return scoped_ptr<browser_sync::DeviceInfo>(); | 413 return scoped_ptr<browser_sync::DeviceInfo>(); |
373 } | 414 } |
(...skipping 16 matching lines...) Expand all Loading... |
390 browser_sync::SyncedDeviceTracker* device_tracker = | 431 browser_sync::SyncedDeviceTracker* device_tracker = |
391 backend_->GetSyncedDeviceTracker(); | 432 backend_->GetSyncedDeviceTracker(); |
392 if (device_tracker) { | 433 if (device_tracker) { |
393 // TODO(lipalani) - Make device tracker return a scoped vector. | 434 // TODO(lipalani) - Make device tracker return a scoped vector. |
394 device_tracker->GetAllSyncedDeviceInfo(&devices); | 435 device_tracker->GetAllSyncedDeviceInfo(&devices); |
395 } | 436 } |
396 } | 437 } |
397 return devices.Pass(); | 438 return devices.Pass(); |
398 } | 439 } |
399 | 440 |
400 std::string ProfileSyncService::GetLocalDeviceGUID() const { | 441 std::string ProfileSyncService::GetLocalSyncCacheGUID() const { |
401 if (backend_) { | 442 if (backend_) { |
402 browser_sync::SyncedDeviceTracker* device_tracker = | 443 browser_sync::SyncedDeviceTracker* device_tracker = |
403 backend_->GetSyncedDeviceTracker(); | 444 backend_->GetSyncedDeviceTracker(); |
404 if (device_tracker) { | 445 if (device_tracker) { |
405 return device_tracker->cache_guid(); | 446 return device_tracker->cache_guid(); |
406 } | 447 } |
407 } | 448 } |
408 return std::string(); | 449 return std::string(); |
409 } | 450 } |
410 | 451 |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 ConfigureDataTypeManager(); | 1054 ConfigureDataTypeManager(); |
1014 } else { | 1055 } else { |
1015 DCHECK(FirstSetupInProgress()); | 1056 DCHECK(FirstSetupInProgress()); |
1016 } | 1057 } |
1017 | 1058 |
1018 NotifyObservers(); | 1059 NotifyObservers(); |
1019 } | 1060 } |
1020 | 1061 |
1021 void ProfileSyncService::OnSyncCycleCompleted() { | 1062 void ProfileSyncService::OnSyncCycleCompleted() { |
1022 UpdateLastSyncedTime(); | 1063 UpdateLastSyncedTime(); |
1023 if (GetSessionModelAssociator()) { | 1064 if (GetSessionModelAssociatorDeprecated()) { |
1024 // Trigger garbage collection of old sessions now that we've downloaded | 1065 // Trigger garbage collection of old sessions now that we've downloaded |
1025 // any new session data. TODO(zea): Have this be a notification the session | 1066 // any new session data. TODO(zea): Have this be a notification the session |
1026 // model associator listens too. Also consider somehow plumbing the current | 1067 // model associator listens too. Also consider somehow plumbing the current |
1027 // server time as last reported by CheckServerReachable, so we don't have to | 1068 // server time as last reported by CheckServerReachable, so we don't have to |
1028 // rely on the local clock, which may be off significantly. | 1069 // rely on the local clock, which may be off significantly. |
1029 base::MessageLoop::current()->PostTask(FROM_HERE, | 1070 base::MessageLoop::current()->PostTask(FROM_HERE, |
1030 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, | 1071 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, |
1031 GetSessionModelAssociator()->AsWeakPtr())); | 1072 GetSessionModelAssociatorDeprecated()->AsWeakPtr())); |
1032 } | 1073 } |
1033 DVLOG(2) << "Notifying observers sync cycle completed"; | 1074 DVLOG(2) << "Notifying observers sync cycle completed"; |
1034 NotifySyncCycleCompleted(); | 1075 NotifySyncCycleCompleted(); |
1035 } | 1076 } |
1036 | 1077 |
1037 void ProfileSyncService::OnExperimentsChanged( | 1078 void ProfileSyncService::OnExperimentsChanged( |
1038 const syncer::Experiments& experiments) { | 1079 const syncer::Experiments& experiments) { |
1039 if (current_experiments_.Matches(experiments)) | 1080 if (current_experiments_.Matches(experiments)) |
1040 return; | 1081 return; |
1041 | 1082 |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 } | 2231 } |
2191 | 2232 |
2192 // TODO(fgorski): Use GetPrimaryAccountId() when it's available. | 2233 // TODO(fgorski): Use GetPrimaryAccountId() when it's available. |
2193 return signin_->GetAuthenticatedUsername(); | 2234 return signin_->GetAuthenticatedUsername(); |
2194 } | 2235 } |
2195 | 2236 |
2196 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { | 2237 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { |
2197 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); | 2238 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); |
2198 } | 2239 } |
2199 | 2240 |
| 2241 syncer::SyncableService* ProfileSyncService::GetSessionsSyncableService() { |
| 2242 return sessions_sync_manager_.get(); |
| 2243 } |
| 2244 |
2200 ProfileSyncService::SyncTokenStatus::SyncTokenStatus() | 2245 ProfileSyncService::SyncTokenStatus::SyncTokenStatus() |
2201 : connection_status(syncer::CONNECTION_NOT_ATTEMPTED), | 2246 : connection_status(syncer::CONNECTION_NOT_ATTEMPTED), |
2202 last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {} | 2247 last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {} |
2203 ProfileSyncService::SyncTokenStatus::~SyncTokenStatus() {} | 2248 ProfileSyncService::SyncTokenStatus::~SyncTokenStatus() {} |
2204 | 2249 |
2205 ProfileSyncService::SyncTokenStatus | 2250 ProfileSyncService::SyncTokenStatus |
2206 ProfileSyncService::GetSyncTokenStatus() const { | 2251 ProfileSyncService::GetSyncTokenStatus() const { |
2207 SyncTokenStatus status; | 2252 SyncTokenStatus status; |
2208 status.connection_status_update_time = connection_status_update_time_; | 2253 status.connection_status_update_time = connection_status_update_time_; |
2209 status.connection_status = connection_status_; | 2254 status.connection_status = connection_status_; |
2210 status.token_request_time = token_request_time_; | 2255 status.token_request_time = token_request_time_; |
2211 status.token_receive_time = token_receive_time_; | 2256 status.token_receive_time = token_receive_time_; |
2212 status.last_get_token_error = last_get_token_error_; | 2257 status.last_get_token_error = last_get_token_error_; |
2213 if (request_access_token_retry_timer_.IsRunning()) | 2258 if (request_access_token_retry_timer_.IsRunning()) |
2214 status.next_token_request_time = next_token_request_time_; | 2259 status.next_token_request_time = next_token_request_time_; |
2215 return status; | 2260 return status; |
2216 } | 2261 } |
OLD | NEW |