Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 #include "chrome/browser/sync/backend_migrator.h" | 44 #include "chrome/browser/sync/backend_migrator.h" |
| 45 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 45 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
| 46 #include "chrome/browser/sync/glue/device_info.h" | 46 #include "chrome/browser/sync/glue/device_info.h" |
| 47 #include "chrome/browser/sync/glue/favicon_cache.h" | 47 #include "chrome/browser/sync/glue/favicon_cache.h" |
| 48 #include "chrome/browser/sync/glue/sync_backend_host.h" | 48 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 49 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" | 49 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
| 50 #include "chrome/browser/sync/glue/sync_start_util.h" | 50 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 51 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 51 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 52 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 52 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
| 53 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 53 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 54 #include "chrome/browser/sync/profile_sync_service_data_type_provider.h" | |
| 54 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" | 55 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
| 55 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" | 56 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
| 56 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 57 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
| 57 #include "chrome/browser/sync/sync_error_controller.h" | 58 #include "chrome/browser/sync/sync_error_controller.h" |
| 58 #include "chrome/browser/ui/browser.h" | 59 #include "chrome/browser/ui/browser.h" |
| 59 #include "chrome/browser/ui/browser_list.h" | 60 #include "chrome/browser/ui/browser_list.h" |
| 60 #include "chrome/browser/ui/browser_window.h" | 61 #include "chrome/browser/ui/browser_window.h" |
| 61 #include "chrome/browser/ui/global_error/global_error_service.h" | 62 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 62 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 63 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 63 #include "chrome/common/chrome_switches.h" | 64 #include "chrome/common/chrome_switches.h" |
| (...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1927 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1928 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| 1928 base::Unretained(this)))); | 1929 base::Unretained(this)))); |
| 1929 } | 1930 } |
| 1930 | 1931 |
| 1931 syncer::ModelTypeSet types; | 1932 syncer::ModelTypeSet types; |
| 1932 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1933 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
| 1933 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) { | 1934 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) { |
| 1934 types = syncer::BackupTypes(); | 1935 types = syncer::BackupTypes(); |
| 1935 reason = syncer::CONFIGURE_REASON_BACKUP_ROLLBACK; | 1936 reason = syncer::CONFIGURE_REASON_BACKUP_ROLLBACK; |
| 1936 } else { | 1937 } else { |
| 1937 types = GetPreferredDirectoryDataTypes(); | 1938 types = Union(GetPreferredDirectoryDataTypes(), GetRequiredDataTypes()); |
| 1938 if (!HasSyncSetupCompleted()) { | 1939 if (!HasSyncSetupCompleted()) { |
| 1939 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; | 1940 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; |
| 1940 } else if (restart) { | 1941 } else if (restart) { |
| 1941 // Datatype downloads on restart are generally due to newly supported | 1942 // Datatype downloads on restart are generally due to newly supported |
| 1942 // datatypes (although it's also possible we're picking up where a failed | 1943 // datatypes (although it's also possible we're picking up where a failed |
| 1943 // previous configuration left off). | 1944 // previous configuration left off). |
| 1944 // TODO(sync): consider detecting configuration recovery and setting | 1945 // TODO(sync): consider detecting configuration recovery and setting |
| 1945 // the reason here appropriately. | 1946 // the reason here appropriately. |
| 1946 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | 1947 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
| 1947 } else { | 1948 } else { |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2286 | 2287 |
| 2287 void ProfileSyncService::RemoveTypeDebugInfoObserver( | 2288 void ProfileSyncService::RemoveTypeDebugInfoObserver( |
| 2288 syncer::TypeDebugInfoObserver* type_debug_info_observer) { | 2289 syncer::TypeDebugInfoObserver* type_debug_info_observer) { |
| 2289 type_debug_info_observers_.RemoveObserver(type_debug_info_observer); | 2290 type_debug_info_observers_.RemoveObserver(type_debug_info_observer); |
| 2290 if (!type_debug_info_observers_.might_have_observers() && | 2291 if (!type_debug_info_observers_.might_have_observers() && |
| 2291 backend_initialized_) { | 2292 backend_initialized_) { |
| 2292 backend_->DisableDirectoryTypeDebugInfoForwarding(); | 2293 backend_->DisableDirectoryTypeDebugInfoForwarding(); |
| 2293 } | 2294 } |
| 2294 } | 2295 } |
| 2295 | 2296 |
| 2297 void ProfileSyncService::AddDataTypeProvider( | |
| 2298 ProfileSyncServiceDataTypeProvider* provider) { | |
| 2299 DCHECK(!HasDataTypeProvider(provider)) << "Providers may only be added once!"; | |
| 2300 data_type_providers_.push_back(provider); | |
| 2301 } | |
| 2302 | |
| 2303 void ProfileSyncService::RemoveDataTypeProvider( | |
| 2304 ProfileSyncServiceDataTypeProvider* provider) { | |
| 2305 data_type_providers_.remove(provider); | |
|
Bernhard Bauer
2014/07/30 12:38:51
DCHECK the result?
Marc Treib
2014/07/30 13:10:39
There is no result :P
We could DCHECK(HasDataTypeP
Bernhard Bauer
2014/07/30 14:13:20
Yeah, I meant checking whether there is one regist
Marc Treib
2014/08/07 13:05:55
Done.
| |
| 2306 } | |
| 2307 | |
| 2308 bool ProfileSyncService::HasDataTypeProvider( | |
| 2309 ProfileSyncServiceDataTypeProvider* provider) const { | |
| 2310 return std::find(data_type_providers_.begin(), | |
| 2311 data_type_providers_.end(), | |
| 2312 provider) != data_type_providers_.end(); | |
| 2313 } | |
| 2314 | |
| 2296 namespace { | 2315 namespace { |
| 2297 | 2316 |
| 2298 class GetAllNodesRequestHelper | 2317 class GetAllNodesRequestHelper |
| 2299 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { | 2318 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { |
| 2300 public: | 2319 public: |
| 2301 GetAllNodesRequestHelper( | 2320 GetAllNodesRequestHelper( |
| 2302 syncer::ModelTypeSet requested_types, | 2321 syncer::ModelTypeSet requested_types, |
| 2303 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback); | 2322 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback); |
| 2304 | 2323 |
| 2305 void OnReceivedNodesForTypes( | 2324 void OnReceivedNodesForTypes( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2474 NotifyObservers(); | 2493 NotifyObservers(); |
| 2475 | 2494 |
| 2476 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " | 2495 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " |
| 2477 << "Unrecoverable error."; | 2496 << "Unrecoverable error."; |
| 2478 } else { | 2497 } else { |
| 2479 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 2498 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
| 2480 << "initialized"; | 2499 << "initialized"; |
| 2481 } | 2500 } |
| 2482 } | 2501 } |
| 2483 | 2502 |
| 2503 syncer::ModelTypeSet ProfileSyncService::GetRequiredDataTypes() { | |
| 2504 syncer::ModelTypeSet types; | |
| 2505 std::list<ProfileSyncServiceDataTypeProvider*>::iterator it = | |
| 2506 data_type_providers_.begin(); | |
| 2507 while (it != data_type_providers_.end()) { | |
| 2508 // Dereference and increment the iterator *before* calling the callback, | |
| 2509 // because the provider might remove itself from the list in the callback. | |
|
Bernhard Bauer
2014/07/30 12:38:51
I think an easier solution here would be to requir
Marc Treib
2014/07/30 13:10:39
I guess we could. OTOH, this is a fairly common pa
Bernhard Bauer
2014/07/30 14:13:20
Not as common as a standard for loop ;-)
If you k
Marc Treib
2014/08/07 13:05:55
Alright. Bonus side-effect: It doesn't have to be
| |
| 2510 ProfileSyncServiceDataTypeProvider* provider = *it; | |
| 2511 ++it; | |
| 2512 types.PutAll(provider->GetRequiredSyncDataTypes()); | |
| 2513 } | |
| 2514 // TODO(treib): Resolve pref groups? | |
|
Marc Treib
2014/07/30 11:42:50
It'd be easiest to expose SyncPrefs::ResolvePrefGr
Bernhard Bauer
2014/07/30 12:38:51
Do we actually need that? Required data types coul
Marc Treib
2014/07/30 13:10:39
We could also specify the types explicitly, but I
Bernhard Bauer
2014/07/30 14:13:20
At the very least we would need to change the conc
| |
| 2515 return types; | |
| 2516 } | |
| 2517 | |
| 2484 const FailedDataTypesHandler& ProfileSyncService::failed_data_types_handler() | 2518 const FailedDataTypesHandler& ProfileSyncService::failed_data_types_handler() |
| 2485 const { | 2519 const { |
| 2486 return failed_data_types_handler_; | 2520 return failed_data_types_handler_; |
| 2487 } | 2521 } |
| 2488 | 2522 |
| 2489 void ProfileSyncService::OnInternalUnrecoverableError( | 2523 void ProfileSyncService::OnInternalUnrecoverableError( |
| 2490 const tracked_objects::Location& from_here, | 2524 const tracked_objects::Location& from_here, |
| 2491 const std::string& message, | 2525 const std::string& message, |
| 2492 bool delete_sync_database, | 2526 bool delete_sync_database, |
| 2493 UnrecoverableErrorReason reason) { | 2527 UnrecoverableErrorReason reason) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2660 browser_sync::SyncedDeviceTracker* device_tracker = | 2694 browser_sync::SyncedDeviceTracker* device_tracker = |
| 2661 backend_->GetSyncedDeviceTracker(); | 2695 backend_->GetSyncedDeviceTracker(); |
| 2662 if (device_tracker) | 2696 if (device_tracker) |
| 2663 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); | 2697 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); |
| 2664 } | 2698 } |
| 2665 } | 2699 } |
| 2666 | 2700 |
| 2667 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { | 2701 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { |
| 2668 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); | 2702 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); |
| 2669 } | 2703 } |
| OLD | NEW |