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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 11347054: [Sync] Unrevert fix for bug 154940 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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/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 10 matching lines...) Expand all
21 #include "base/string16.h" 21 #include "base/string16.h"
22 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
23 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "chrome/browser/about_flags.h" 25 #include "chrome/browser/about_flags.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/defaults.h" 27 #include "chrome/browser/defaults.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/extension_system.h" 29 #include "chrome/browser/extensions/extension_system.h"
30 #include "chrome/browser/net/chrome_cookie_notification_details.h" 30 #include "chrome/browser/net/chrome_cookie_notification_details.h"
31 #include "chrome/browser/prefs/pref_service.h"
31 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/signin/signin_manager.h" 33 #include "chrome/browser/signin/signin_manager.h"
33 #include "chrome/browser/signin/signin_manager_factory.h" 34 #include "chrome/browser/signin/signin_manager_factory.h"
34 #include "chrome/browser/signin/token_service.h" 35 #include "chrome/browser/signin/token_service.h"
35 #include "chrome/browser/signin/token_service_factory.h" 36 #include "chrome/browser/signin/token_service_factory.h"
36 #include "chrome/browser/sync/backend_migrator.h" 37 #include "chrome/browser/sync/backend_migrator.h"
37 #include "chrome/browser/sync/glue/change_processor.h" 38 #include "chrome/browser/sync/glue/change_processor.h"
38 #include "chrome/browser/sync/glue/chrome_encryptor.h" 39 #include "chrome/browser/sync/glue/chrome_encryptor.h"
39 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" 40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
40 #include "chrome/browser/sync/glue/data_type_controller.h" 41 #include "chrome/browser/sync/glue/data_type_controller.h"
41 #include "chrome/browser/sync/glue/session_data_type_controller.h" 42 #include "chrome/browser/sync/glue/session_data_type_controller.h"
42 #include "chrome/browser/sync/glue/session_model_associator.h" 43 #include "chrome/browser/sync/glue/session_model_associator.h"
43 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" 44 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
44 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 45 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
45 #include "chrome/browser/sync/sync_global_error.h" 46 #include "chrome/browser/sync/sync_global_error.h"
46 #include "chrome/browser/sync/user_selectable_sync_type.h" 47 #include "chrome/browser/sync/user_selectable_sync_type.h"
47 #include "chrome/browser/ui/browser.h" 48 #include "chrome/browser/ui/browser.h"
48 #include "chrome/browser/ui/browser_list.h" 49 #include "chrome/browser/ui/browser_list.h"
49 #include "chrome/browser/ui/browser_window.h" 50 #include "chrome/browser/ui/browser_window.h"
50 #include "chrome/browser/ui/global_error/global_error_service.h" 51 #include "chrome/browser/ui/global_error/global_error_service.h"
51 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 52 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
52 #include "chrome/common/chrome_notification_types.h" 53 #include "chrome/common/chrome_notification_types.h"
53 #include "chrome/common/chrome_switches.h" 54 #include "chrome/common/chrome_switches.h"
54 #include "chrome/common/chrome_version_info.h" 55 #include "chrome/common/chrome_version_info.h"
56 #include "chrome/common/pref_names.h"
55 #include "chrome/common/time_format.h" 57 #include "chrome/common/time_format.h"
56 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
57 #include "content/public/browser/notification_details.h" 59 #include "content/public/browser/notification_details.h"
58 #include "content/public/browser/notification_service.h" 60 #include "content/public/browser/notification_service.h"
59 #include "content/public/browser/notification_source.h" 61 #include "content/public/browser/notification_source.h"
60 #include "google_apis/gaia/gaia_constants.h" 62 #include "google_apis/gaia/gaia_constants.h"
61 #include "grit/generated_resources.h" 63 #include "grit/generated_resources.h"
62 #include "net/cookies/cookie_monster.h" 64 #include "net/cookies/cookie_monster.h"
63 #include "sync/api/sync_error.h" 65 #include "sync/api/sync_error.h"
64 #include "sync/internal_api/public/configure_reason.h" 66 #include "sync/internal_api/public/configure_reason.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return; 211 return;
210 } 212 }
211 213
212 RegisterAuthNotifications(); 214 RegisterAuthNotifications();
213 215
214 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { 216 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) {
215 // Clean up in case of previous crash / setup abort / signout. 217 // Clean up in case of previous crash / setup abort / signout.
216 DisableForUser(); 218 DisableForUser();
217 } 219 }
218 220
221 TrySyncDatatypePrefRecovery();
222
219 TryStart(); 223 TryStart();
220 } 224 }
221 225
226 void ProfileSyncService::TrySyncDatatypePrefRecovery() {
227 DCHECK(!sync_initialized());
228 if (!HasSyncSetupCompleted())
229 return;
230
231 // There was a bug where OnUserChoseDatatypes was not properly called on
232 // configuration (see crbug.com/154940). We detect this by checking whether
233 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has
234 // completed, it means sync was not properly configured, so we manually
235 // set kSyncKeepEverythingSynced.
236 PrefService* const pref_service = profile_->GetPrefs();
237 if (!pref_service)
238 return;
239 if (sync_prefs_.HasKeepEverythingSynced())
240 return;
241 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes();
242 if (sync_prefs_.GetPreferredDataTypes(registered_types).Size() > 1)
243 return;
244
245 const PrefService::Preference* keep_everything_synced =
246 pref_service->FindPreference(prefs::kSyncKeepEverythingSynced);
247 // This will be false if the preference was properly set or if it's controlled
248 // by policy.
249 if (!keep_everything_synced->IsDefaultValue())
250 return;
251
252 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred
253 // types now, before we configure.
254 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1);
255 sync_prefs_.SetKeepEverythingSynced(true);
256 sync_prefs_.SetPreferredDataTypes(registered_types,
257 registered_types);
258 }
259
222 void ProfileSyncService::TryStart() { 260 void ProfileSyncService::TryStart() {
223 if (!IsSyncEnabledAndLoggedIn()) 261 if (!IsSyncEnabledAndLoggedIn())
224 return; 262 return;
225 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 263 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
226 if (!token_service) 264 if (!token_service)
227 return; 265 return;
228 // Don't start the backend if the token service hasn't finished loading tokens 266 // Don't start the backend if the token service hasn't finished loading tokens
229 // yet (if the backend is started before the sync token has been loaded, 267 // yet (if the backend is started before the sync token has been loaded,
230 // GetCredentials() will return bogus credentials). On auto_start platforms 268 // GetCredentials() will return bogus credentials). On auto_start platforms
231 // (like ChromeOS) we don't start sync until tokens are loaded, because the 269 // (like ChromeOS) we don't start sync until tokens are loaded, because the
(...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1903 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1866 ProfileSyncService* old_this = this; 1904 ProfileSyncService* old_this = this;
1867 this->~ProfileSyncService(); 1905 this->~ProfileSyncService();
1868 new(old_this) ProfileSyncService( 1906 new(old_this) ProfileSyncService(
1869 new ProfileSyncComponentsFactoryImpl(profile, 1907 new ProfileSyncComponentsFactoryImpl(profile,
1870 CommandLine::ForCurrentProcess()), 1908 CommandLine::ForCurrentProcess()),
1871 profile, 1909 profile,
1872 signin, 1910 signin,
1873 behavior); 1911 behavior);
1874 } 1912 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_startup_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698