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 <vector> |
10 #include <utility> | |
11 | 10 |
12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
13 #include "base/bind.h" | 12 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 14 #include "base/callback.h" |
16 #include "base/command_line.h" | 15 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
18 #include "base/file_util.h" | 17 #include "base/file_util.h" |
19 #include "base/logging.h" | 18 #include "base/logging.h" |
20 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
48 #include "chrome/browser/sync/glue/sync_backend_host.h" | 47 #include "chrome/browser/sync/glue/sync_backend_host.h" |
49 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" | 48 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
50 #include "chrome/browser/sync/glue/sync_start_util.h" | 49 #include "chrome/browser/sync/glue/sync_start_util.h" |
51 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 50 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
52 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 51 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
53 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 52 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
54 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" | 53 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
55 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" | 54 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
56 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 55 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
57 #include "chrome/browser/sync/sync_error_controller.h" | 56 #include "chrome/browser/sync/sync_error_controller.h" |
57 #include "chrome/browser/sync/sync_type_preference_provider.h" | |
58 #include "chrome/browser/ui/browser.h" | 58 #include "chrome/browser/ui/browser.h" |
59 #include "chrome/browser/ui/browser_list.h" | 59 #include "chrome/browser/ui/browser_list.h" |
60 #include "chrome/browser/ui/browser_window.h" | 60 #include "chrome/browser/ui/browser_window.h" |
61 #include "chrome/browser/ui/global_error/global_error_service.h" | 61 #include "chrome/browser/ui/global_error/global_error_service.h" |
62 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 62 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
63 #include "chrome/common/chrome_switches.h" | 63 #include "chrome/common/chrome_switches.h" |
64 #include "chrome/common/chrome_version_info.h" | 64 #include "chrome/common/chrome_version_info.h" |
65 #include "chrome/common/pref_names.h" | 65 #include "chrome/common/pref_names.h" |
66 #include "chrome/common/url_constants.h" | 66 #include "chrome/common/url_constants.h" |
67 #include "components/gcm_driver/gcm_driver.h" | 67 #include "components/gcm_driver/gcm_driver.h" |
(...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1930 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1930 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
1931 base::Unretained(this)))); | 1931 base::Unretained(this)))); |
1932 } | 1932 } |
1933 | 1933 |
1934 syncer::ModelTypeSet types; | 1934 syncer::ModelTypeSet types; |
1935 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1935 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
1936 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) { | 1936 if (backend_mode_ == BACKUP || backend_mode_ == ROLLBACK) { |
1937 types = syncer::BackupTypes(); | 1937 types = syncer::BackupTypes(); |
1938 reason = syncer::CONFIGURE_REASON_BACKUP_ROLLBACK; | 1938 reason = syncer::CONFIGURE_REASON_BACKUP_ROLLBACK; |
1939 } else { | 1939 } else { |
1940 types = GetPreferredDirectoryDataTypes(); | 1940 types = Union(GetPreferredDirectoryDataTypes(), |
Nicolas Zea
2014/08/07 17:16:33
I think it might make more sense to put the GetDat
Marc Treib
2014/08/08 13:03:59
Done.
| |
1941 GetDataTypesFromPreferenceProviders()); | |
1941 if (!HasSyncSetupCompleted()) { | 1942 if (!HasSyncSetupCompleted()) { |
1942 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; | 1943 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; |
1943 } else if (restart) { | 1944 } else if (restart) { |
1944 // Datatype downloads on restart are generally due to newly supported | 1945 // Datatype downloads on restart are generally due to newly supported |
1945 // datatypes (although it's also possible we're picking up where a failed | 1946 // datatypes (although it's also possible we're picking up where a failed |
1946 // previous configuration left off). | 1947 // previous configuration left off). |
1947 // TODO(sync): consider detecting configuration recovery and setting | 1948 // TODO(sync): consider detecting configuration recovery and setting |
1948 // the reason here appropriately. | 1949 // the reason here appropriately. |
1949 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | 1950 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
1950 } else { | 1951 } else { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2289 | 2290 |
2290 void ProfileSyncService::RemoveTypeDebugInfoObserver( | 2291 void ProfileSyncService::RemoveTypeDebugInfoObserver( |
2291 syncer::TypeDebugInfoObserver* type_debug_info_observer) { | 2292 syncer::TypeDebugInfoObserver* type_debug_info_observer) { |
2292 type_debug_info_observers_.RemoveObserver(type_debug_info_observer); | 2293 type_debug_info_observers_.RemoveObserver(type_debug_info_observer); |
2293 if (!type_debug_info_observers_.might_have_observers() && | 2294 if (!type_debug_info_observers_.might_have_observers() && |
2294 backend_initialized_) { | 2295 backend_initialized_) { |
2295 backend_->DisableDirectoryTypeDebugInfoForwarding(); | 2296 backend_->DisableDirectoryTypeDebugInfoForwarding(); |
2296 } | 2297 } |
2297 } | 2298 } |
2298 | 2299 |
2300 void ProfileSyncService::AddPreferenceProvider( | |
2301 SyncTypePreferenceProvider* provider) { | |
2302 DCHECK(!HasPreferenceProvider(provider)) | |
2303 << "Providers may only be added once!"; | |
2304 preference_providers_.insert(provider); | |
2305 } | |
2306 | |
2307 void ProfileSyncService::RemovePreferenceProvider( | |
2308 SyncTypePreferenceProvider* provider) { | |
2309 DCHECK(HasPreferenceProvider(provider)) | |
2310 << "Only providers that have been added before can be removed!"; | |
2311 preference_providers_.erase(provider); | |
2312 } | |
2313 | |
2314 bool ProfileSyncService::HasPreferenceProvider( | |
2315 SyncTypePreferenceProvider* provider) const { | |
2316 return preference_providers_.count(provider) > 0; | |
2317 } | |
2318 | |
2299 namespace { | 2319 namespace { |
2300 | 2320 |
2301 class GetAllNodesRequestHelper | 2321 class GetAllNodesRequestHelper |
2302 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { | 2322 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { |
2303 public: | 2323 public: |
2304 GetAllNodesRequestHelper( | 2324 GetAllNodesRequestHelper( |
2305 syncer::ModelTypeSet requested_types, | 2325 syncer::ModelTypeSet requested_types, |
2306 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback); | 2326 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback); |
2307 | 2327 |
2308 void OnReceivedNodesForTypes( | 2328 void OnReceivedNodesForTypes( |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2477 NotifyObservers(); | 2497 NotifyObservers(); |
2478 | 2498 |
2479 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " | 2499 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " |
2480 << "Unrecoverable error."; | 2500 << "Unrecoverable error."; |
2481 } else { | 2501 } else { |
2482 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 2502 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
2483 << "initialized"; | 2503 << "initialized"; |
2484 } | 2504 } |
2485 } | 2505 } |
2486 | 2506 |
2507 syncer::ModelTypeSet ProfileSyncService::GetDataTypesFromPreferenceProviders() { | |
2508 syncer::ModelTypeSet types; | |
2509 for (std::set<SyncTypePreferenceProvider*>::iterator it = | |
2510 preference_providers_.begin(); | |
2511 it != preference_providers_.end(); | |
2512 ++it) { | |
2513 types.PutAll((*it)->GetPreferredDataTypes()); | |
2514 } | |
2515 return types; | |
2516 } | |
2517 | |
2487 const FailedDataTypesHandler& ProfileSyncService::failed_data_types_handler() | 2518 const FailedDataTypesHandler& ProfileSyncService::failed_data_types_handler() |
2488 const { | 2519 const { |
2489 return failed_data_types_handler_; | 2520 return failed_data_types_handler_; |
2490 } | 2521 } |
2491 | 2522 |
2492 void ProfileSyncService::OnInternalUnrecoverableError( | 2523 void ProfileSyncService::OnInternalUnrecoverableError( |
2493 const tracked_objects::Location& from_here, | 2524 const tracked_objects::Location& from_here, |
2494 const std::string& message, | 2525 const std::string& message, |
2495 bool delete_sync_database, | 2526 bool delete_sync_database, |
2496 UnrecoverableErrorReason reason) { | 2527 UnrecoverableErrorReason reason) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2663 browser_sync::SyncedDeviceTracker* device_tracker = | 2694 browser_sync::SyncedDeviceTracker* device_tracker = |
2664 backend_->GetSyncedDeviceTracker(); | 2695 backend_->GetSyncedDeviceTracker(); |
2665 if (device_tracker) | 2696 if (device_tracker) |
2666 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); | 2697 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); |
2667 } | 2698 } |
2668 } | 2699 } |
2669 | 2700 |
2670 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { | 2701 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { |
2671 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); | 2702 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); |
2672 } | 2703 } |
OLD | NEW |