Chromium Code Reviews| 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 // Extension ID for previous Now notifications component. | |
|
robliao
2015/02/19 18:43:25
Since there is more than one item in this namespac
skare_
2015/02/19 20:19:29
Done.
| |
| 17 const char kNowNotifierId[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; | |
| 11 }; // namespace | 18 }; // namespace |
| 12 | 19 |
| 13 bool GetGoogleNowExtensionId(std::string* extension_id) { | 20 bool GetGoogleNowExtensionId(std::string* extension_id) { |
| 14 *extension_id = variations::GetVariationParamValue( | 21 *extension_id = variations::GetVariationParamValue( |
| 15 kGoogleNowExtensionFieldTrialName, "id"); | 22 kGoogleNowExtensionFieldTrialName, "id"); |
| 16 return !extension_id->empty(); | 23 return !extension_id->empty(); |
| 17 } | 24 } |
| 25 | |
| 26 // TODO(skare): Remove this if/when the Now Notifications component is | |
| 27 // deprecated. http://crbug.com/459846 | |
| 28 void MigrateGoogleNowPrefs(Profile* profile) { | |
| 29 std::string now_extension_id; | |
| 30 if (GetGoogleNowExtensionId(&now_extension_id) == false) { | |
|
robliao
2015/02/19 18:43:25
Replace == false with !GetGoogleNowExtensionId
skare_
2015/02/19 20:19:29
Done.
| |
| 31 return; | |
| 32 } | |
| 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 | |
| 43 DesktopNotificationService* const notification_service = | |
| 44 DesktopNotificationServiceFactory::GetForProfile(profile); | |
| 45 bool notifier_enabled = notification_service->IsNotifierEnabled( | |
| 46 message_center::NotifierId( | |
| 47 message_center::NotifierId::APPLICATION, kNowNotifierId)); | |
| 48 prefs->SetBoolean(prefs::kGoogleNowLauncherEnabled, notifier_enabled); | |
| 49 } | |
| OLD | NEW |