| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/app_list/google_now_extension.h" | 5 #include "chrome/browser/ui/app_list/google_now_extension.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 9 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/pref_names.h" |
| 7 #include "components/variations/variations_associated_data.h" | 12 #include "components/variations/variations_associated_data.h" |
| 8 | 13 |
| 9 namespace { | 14 namespace { |
| 10 const char kGoogleNowExtensionFieldTrialName[] = "GoogleNowExtension"; | 15 const char kGoogleNowExtensionFieldTrialName[] = "GoogleNowExtension"; |
| 16 |
| 17 // Extension ID for previous Now notifications component. |
| 18 const char kNowNotifierId[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; |
| 11 }; // namespace | 19 }; // namespace |
| 12 | 20 |
| 13 bool GetGoogleNowExtensionId(std::string* extension_id) { | 21 bool GetGoogleNowExtensionId(std::string* extension_id) { |
| 14 *extension_id = variations::GetVariationParamValue( | 22 *extension_id = variations::GetVariationParamValue( |
| 15 kGoogleNowExtensionFieldTrialName, "id"); | 23 kGoogleNowExtensionFieldTrialName, "id"); |
| 16 return !extension_id->empty(); | 24 return !extension_id->empty(); |
| 17 } | 25 } |
| 26 |
| 27 // TODO(skare): Remove this if/when the Now Notifications component is |
| 28 // deprecated. http://crbug.com/459846 |
| 29 void MigrateGoogleNowPrefs(Profile* profile) { |
| 30 std::string now_extension_id; |
| 31 if (!GetGoogleNowExtensionId(&now_extension_id)) |
| 32 return; |
| 33 |
| 34 PrefService* prefs = profile->GetPrefs(); |
| 35 const PrefService::Preference* enabled_pref = |
| 36 prefs->FindPreference(prefs::kGoogleNowLauncherEnabled); |
| 37 |
| 38 // If the pref is not its default value, migration was performed. |
| 39 if (!enabled_pref->IsDefaultValue()) |
| 40 return; |
| 41 |
| 42 DesktopNotificationService* const notification_service = |
| 43 DesktopNotificationServiceFactory::GetForProfile(profile); |
| 44 bool notifier_enabled = notification_service->IsNotifierEnabled( |
| 45 message_center::NotifierId( |
| 46 message_center::NotifierId::APPLICATION, kNowNotifierId)); |
| 47 prefs->SetBoolean(prefs::kGoogleNowLauncherEnabled, notifier_enabled); |
| 48 } |
| OLD | NEW |