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 |
| 395 pref_groups_[syncer::TYPED_URLS].Put(syncer::HISTORY_DELETE_DIRECTIVES); |
| 396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 397 if (command_line.HasSwitch(switches::kHistoryEnableFullHistorySync)) { |
| 398 pref_groups_[syncer::TYPED_URLS].Put(syncer::SESSIONS); |
| 399 pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_IMAGES); |
| 400 pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_TRACKING); |
| 401 } |
| 402 |
| 403 pref_groups_[syncer::PROXY_TABS].Put(syncer::SESSIONS); |
| 404 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_IMAGES); |
| 405 pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_TRACKING); |
| 406 |
390 // TODO(zea): put favicons in the bookmarks group as well once it handles | 407 // TODO(zea): put favicons in the bookmarks group as well once it handles |
391 // those favicons. | 408 // 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 } | 409 } |
398 | 410 |
399 // static | 411 // static |
400 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry, | 412 void SyncPrefs::RegisterDataTypePreferredPref(PrefRegistrySyncable* registry, |
401 syncer::ModelType type, | 413 syncer::ModelType type, |
402 bool is_preferred) { | 414 bool is_preferred) { |
403 const char* pref_name = GetPrefNameForDataType(type); | 415 const char* pref_name = GetPrefNameForDataType(type); |
404 if (!pref_name) { | 416 if (!pref_name) { |
405 NOTREACHED(); | 417 NOTREACHED(); |
406 return; | 418 return; |
407 } | 419 } |
408 registry->RegisterBooleanPref(pref_name, is_preferred, | 420 registry->RegisterBooleanPref(pref_name, is_preferred, |
409 PrefRegistrySyncable::UNSYNCABLE_PREF); | 421 PrefRegistrySyncable::UNSYNCABLE_PREF); |
410 } | 422 } |
411 | 423 |
412 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { | 424 bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { |
413 DCHECK(CalledOnValidThread()); | 425 DCHECK(CalledOnValidThread()); |
414 if (!pref_service_) { | 426 if (!pref_service_) { |
415 return false; | 427 return false; |
416 } | 428 } |
417 const char* pref_name = GetPrefNameForDataType(type); | 429 const char* pref_name = GetPrefNameForDataType(type); |
418 if (!pref_name) { | 430 if (!pref_name) { |
419 NOTREACHED(); | 431 NOTREACHED(); |
420 return false; | 432 return false; |
421 } | 433 } |
| 434 if (type == syncer::PROXY_TABS && |
| 435 pref_service_->GetUserPrefValue(pref_name) == NULL && |
| 436 pref_service_->IsUserModifiablePreference(pref_name)) { |
| 437 // If there is no tab sync preference yet (i.e. newly enabled type), |
| 438 // default to the session sync preference value. |
| 439 pref_name = GetPrefNameForDataType(syncer::SESSIONS); |
| 440 } |
422 | 441 |
423 return pref_service_->GetBoolean(pref_name); | 442 return pref_service_->GetBoolean(pref_name); |
424 } | 443 } |
425 | 444 |
426 void SyncPrefs::SetDataTypePreferred( | 445 void SyncPrefs::SetDataTypePreferred( |
427 syncer::ModelType type, bool is_preferred) { | 446 syncer::ModelType type, bool is_preferred) { |
428 DCHECK(CalledOnValidThread()); | 447 DCHECK(CalledOnValidThread()); |
429 CHECK(pref_service_); | 448 CHECK(pref_service_); |
430 const char* pref_name = GetPrefNameForDataType(type); | 449 const char* pref_name = GetPrefNameForDataType(type); |
431 if (!pref_name) { | 450 if (!pref_name) { |
432 NOTREACHED(); | 451 NOTREACHED(); |
433 return; | 452 return; |
434 } | 453 } |
435 pref_service_->SetBoolean(pref_name, is_preferred); | 454 pref_service_->SetBoolean(pref_name, is_preferred); |
436 } | 455 } |
437 | 456 |
438 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( | 457 syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( |
439 syncer::ModelTypeSet registered_types, | 458 syncer::ModelTypeSet registered_types, |
440 syncer::ModelTypeSet types) const { | 459 syncer::ModelTypeSet types) const { |
441 DCHECK(registered_types.HasAll(types)); | 460 DCHECK(registered_types.HasAll(types)); |
442 syncer::ModelTypeSet types_with_groups = types; | 461 syncer::ModelTypeSet types_with_groups = types; |
443 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); | 462 for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); |
444 i != pref_groups_.end(); ++i) { | 463 i != pref_groups_.end(); ++i) { |
445 if (types.Has(i->first)) | 464 if (types.Has(i->first)) |
446 types_with_groups.PutAll(i->second); | 465 types_with_groups.PutAll(i->second); |
447 else | |
448 types_with_groups.RemoveAll(i->second); | |
449 } | 466 } |
450 types_with_groups.RetainAll(registered_types); | 467 types_with_groups.RetainAll(registered_types); |
451 return types_with_groups; | 468 return types_with_groups; |
452 } | 469 } |
453 | 470 |
454 } // namespace browser_sync | 471 } // namespace browser_sync |
OLD | NEW |