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/sync_prefs.h" | 5 #include "chrome/browser/sync/sync_prefs.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/public/pref_member.h" | 10 #include "base/prefs/public/pref_member.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "chrome/browser/prefs/pref_registry_syncable.h" | 14 #include "chrome/browser/prefs/pref_registry_syncable.h" |
14 #include "chrome/browser/profiles/profile_io_data.h" | 15 #include "chrome/browser/profiles/profile_io_data.h" |
15 #include "chrome/browser/sync/profile_sync_service.h" | 16 #include "chrome/browser/sync/profile_sync_service.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
21 | 23 |
22 namespace browser_sync { | 24 namespace browser_sync { |
23 | 25 |
24 SyncPrefObserver::~SyncPrefObserver() {} | 26 SyncPrefObserver::~SyncPrefObserver() {} |
25 | 27 |
26 SyncPrefs::SyncPrefs(PrefService* pref_service) | 28 SyncPrefs::SyncPrefs(PrefService* pref_service) |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 case syncer::HISTORY_DELETE_DIRECTIVES: | 315 case syncer::HISTORY_DELETE_DIRECTIVES: |
314 return prefs::kSyncHistoryDeleteDirectives; | 316 return prefs::kSyncHistoryDeleteDirectives; |
315 case syncer::SYNCED_NOTIFICATIONS: | 317 case syncer::SYNCED_NOTIFICATIONS: |
316 return prefs::kSyncSyncedNotifications; | 318 return prefs::kSyncSyncedNotifications; |
317 case syncer::DICTIONARY: | 319 case syncer::DICTIONARY: |
318 return prefs::kSyncDictionary; | 320 return prefs::kSyncDictionary; |
319 case syncer::FAVICON_IMAGES: | 321 case syncer::FAVICON_IMAGES: |
320 return prefs::kSyncFaviconImages; | 322 return prefs::kSyncFaviconImages; |
321 case syncer::FAVICON_TRACKING: | 323 case syncer::FAVICON_TRACKING: |
322 return prefs::kSyncFaviconTracking; | 324 return prefs::kSyncFaviconTracking; |
| 325 case syncer::PROXY_TABS: |
| 326 return prefs::kSyncTabs; |
323 default: | 327 default: |
324 break; | 328 break; |
325 } | 329 } |
326 NOTREACHED(); | 330 NOTREACHED(); |
327 return NULL; | 331 return NULL; |
328 } | 332 } |
329 | 333 |
330 #if defined(OS_CHROMEOS) | 334 #if defined(OS_CHROMEOS) |
331 std::string SyncPrefs::GetSpareBootstrapToken() const { | 335 std::string SyncPrefs::GetSpareBootstrapToken() const { |
332 DCHECK(CalledOnValidThread()); | 336 DCHECK(CalledOnValidThread()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 pref_groups_[syncer::APPS].Put(syncer::APP_NOTIFICATIONS); | 384 pref_groups_[syncer::APPS].Put(syncer::APP_NOTIFICATIONS); |
381 pref_groups_[syncer::APPS].Put(syncer::APP_SETTINGS); | 385 pref_groups_[syncer::APPS].Put(syncer::APP_SETTINGS); |
382 | 386 |
383 pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_PROFILE); | 387 pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_PROFILE); |
384 | 388 |
385 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); | 389 pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); |
386 | 390 |
387 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); | 391 pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); |
388 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); | 392 pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); |
389 | 393 |
| 394 pref_groups_[syncer::TYPED_URLS].Put(syncer::HISTORY_DELETE_DIRECTIVES); |
| 395 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 396 if (command_line.HasSwitch(switches::kHistoryEnableFullHistorySync)) { |
| 397 pref_groups_[syncer::TYPED_URLS].Put(syncer::SESSIONS); |
| 398 pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_IMAGES); |
| 399 pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_TRACKING); |
| 400 } |
| 401 |
| 402 pref_groups_[syncer::PROXY_TABS].Put(syncer::SESSIONS); |
| 403 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_IMAGES); |
| 404 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_TRACKING); |
| 405 |
390 // TODO(zea): put favicons in the bookmarks group as well once it handles | 406 // TODO(zea): put favicons in the bookmarks group as well once it handles |
391 // those favicons. | 407 // those favicons. |
392 pref_groups_[syncer::SESSIONS].Put(syncer::FAVICON_IMAGES); | |
393 pref_groups_[syncer::SESSIONS].Put(syncer::FAVICON_TRACKING); | |
394 | |
395 // TODO(akalin): Revisit this once UI lands. | |
396 pref_groups_[syncer::SESSIONS].Put(syncer::HISTORY_DELETE_DIRECTIVES); | |
397 } | 408 } |
398 | 409 |
399 // static | 410 // static |
400 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry, | 411 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry, |
401 syncer::ModelType type, | 412 syncer::ModelType type, |
402 bool is_preferred) { | 413 bool is_preferred) { |
403 const char* pref_name = GetPrefNameForDataType(type); | 414 const char* pref_name = GetPrefNameForDataType(type); |
404 if (!pref_name) { | 415 if (!pref_name) { |
405 NOTREACHED(); | 416 NOTREACHED(); |
406 return; | 417 return; |
407 } | 418 } |
408 registry->RegisterBooleanPref(pref_name, is_preferred, | 419 registry->RegisterBooleanPref(pref_name, is_preferred, |
409 PrefRegistrySyncable::UNSYNCABLE_PREF); | 420 PrefRegistrySyncable::UNSYNCABLE_PREF); |
410 } | 421 } |
411 | 422 |
412 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { | 423 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { |
413 DCHECK(CalledOnValidThread()); | 424 DCHECK(CalledOnValidThread()); |
414 if (!pref_service_) { | 425 if (!pref_service_) { |
415 return false; | 426 return false; |
416 } | 427 } |
417 const char* pref_name = GetPrefNameForDataType(type); | 428 const char* pref_name = GetPrefNameForDataType(type); |
418 if (!pref_name) { | 429 if (!pref_name) { |
419 NOTREACHED(); | 430 NOTREACHED(); |
420 return false; | 431 return false; |
421 } | 432 } |
| 433 if (type == syncer::PROXY_TABS && |
| 434 pref_service_->GetUserPrefValue(pref_name) == NULL && |
| 435 pref_service_->IsUserModifiablePreference(pref_name)) { |
| 436 // If there is no tab sync preference yet (i.e. newly enabled type), |
| 437 // default to the session sync preference value. |
| 438 pref_name = GetPrefNameForDataType(syncer::SESSIONS); |
| 439 } |
422 | 440 |
423 return pref_service_->GetBoolean(pref_name); | 441 return pref_service_->GetBoolean(pref_name); |
424 } | 442 } |
425 | 443 |
426 void SyncPrefs::SetDataTypePreferred( | 444 void SyncPrefs::SetDataTypePreferred( |
427 syncer::ModelType type, bool is_preferred) { | 445 syncer::ModelType type, bool is_preferred) { |
428 DCHECK(CalledOnValidThread()); | 446 DCHECK(CalledOnValidThread()); |
429 CHECK(pref_service_); | 447 CHECK(pref_service_); |
430 const char* pref_name = GetPrefNameForDataType(type); | 448 const char* pref_name = GetPrefNameForDataType(type); |
431 if (!pref_name) { | 449 if (!pref_name) { |
432 NOTREACHED(); | 450 NOTREACHED(); |
433 return; | 451 return; |
434 } | 452 } |
435 pref_service_->SetBoolean(pref_name, is_preferred); | 453 pref_service_->SetBoolean(pref_name, is_preferred); |
436 } | 454 } |
437 | 455 |
438 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( | 456 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( |
439 syncer::ModelTypeSet registered_types, | 457 syncer::ModelTypeSet registered_types, |
440 syncer::ModelTypeSet types) const { | 458 syncer::ModelTypeSet types) const { |
441 DCHECK(registered_types.HasAll(types)); | 459 DCHECK(registered_types.HasAll(types)); |
442 syncer::ModelTypeSet types_with_groups = types; | 460 syncer::ModelTypeSet types_with_groups = types; |
443 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); | 461 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); |
444 i != pref_groups_.end(); ++i) { | 462 i != pref_groups_.end(); ++i) { |
445 if (types.Has(i->first)) | 463 if (types.Has(i->first)) |
446 types_with_groups.PutAll(i->second); | 464 types_with_groups.PutAll(i->second); |
447 else | |
448 types_with_groups.RemoveAll(i->second); | |
449 } | 465 } |
450 types_with_groups.RetainAll(registered_types); | 466 types_with_groups.RetainAll(registered_types); |
451 return types_with_groups; | 467 return types_with_groups; |
452 } | 468 } |
453 | 469 |
454 } // namespace browser_sync | 470 } // namespace browser_sync |
OLD | NEW |