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

Unified Diff: chrome/browser/chromeos/status/data_promo_notification.cc

Issue 1022333002: Initial CL for Data Saver (Flywheel) prompt when cellular network detected (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from two reviewers Created 5 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/status/data_promo_notification.cc
diff --git a/chrome/browser/chromeos/status/data_promo_notification.cc b/chrome/browser/chromeos/status/data_promo_notification.cc
index 0cf7b9cfaa21517d8720174fcf7db461491b2219..0b7fb95fbbbc30d2ef9ceaa59b8d02499420ae51 100644
--- a/chrome/browser/chromeos/status/data_promo_notification.cc
+++ b/chrome/browser/chromeos/status/data_promo_notification.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/status/data_promo_notification.h"
#include "ash/system/system_notifier.h"
+#include "base/command_line.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
@@ -17,14 +18,17 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/singleton_tabs.h"
+#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
+#include "chromeos/chromeos_switches.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_connection_handler.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
+#include "extensions/browser/extension_registry.h"
#include "grit/ui_chromeos_resources.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h"
@@ -41,8 +45,12 @@ namespace chromeos {
namespace {
const char kDataPromoNotificationId[] = "chrome://settings/internet/data_promo";
+const char kDataSaverExtensionUrl[] =
+ "https://chrome.google.com/webstore/detail/"
+ "pfmgfdlgomnbgkofeojodiodmgpgmkac";
const int kNotificationCountPrefDefault = -1;
+const int kTimesToShowDataSaverPrompt = 2;
bool GetBooleanPref(const char* pref_name) {
Profile* profile = ProfileManager::GetPrimaryUserProfile();
@@ -85,6 +93,20 @@ void SetCarrierDealPromoShown(int value) {
SetIntegerLocalPref(prefs::kCarrierDealPromoShown, value);
}
+// Returns number of times the Data Saver prompt has been displayed.
+int GetDataSaverPromptsShown() {
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ PrefService* prefs = profile->GetPrefs();
stevenjb 2015/03/25 17:57:08 nit: I think these would actually be more clear wi
Greg Levin 2015/04/03 18:28:37 Done.
+ return prefs->GetInteger(prefs::kDataSaverPromptsShown);
+}
+
+// Updates number of times the Data Saver prompt has been displayed.
+void SetDataSaverPromptsShown(int times_shown) {
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ PrefService* prefs = profile->GetPrefs();
+ prefs->SetInteger(prefs::kDataSaverPromptsShown, times_shown);
+}
+
const chromeos::MobileConfig::Carrier* GetCarrier(
const NetworkState* cellular) {
const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
@@ -159,7 +181,10 @@ void DataPromoNotification::NetworkPropertiesUpdated(
const NetworkState* network) {
if (!network || network->type() != shill::kTypeCellular)
return;
- ShowOptionalMobileDataPromoNotification();
+
+ bool hotkey_debug = network->path() ==
+ NetworkStateHandlerObserver::kDebugDataSaverNetworkPath;
+ ShowOptionalMobileDataPromoNotification(hotkey_debug);
}
void DataPromoNotification::DefaultNetworkChanged(const NetworkState* network) {
@@ -168,21 +193,30 @@ void DataPromoNotification::DefaultNetworkChanged(const NetworkState* network) {
NetworkPropertiesUpdated(network);
}
-void DataPromoNotification::ShowOptionalMobileDataPromoNotification() {
- // Display a one-time notification for authenticated users on first use
- // of Mobile Data connection or if there is a carrier deal defined
- // show that even if user has already seen generic promo.
- if (!check_for_promo_ || !LoginState::Get()->IsUserAuthenticated())
- return;
+void DataPromoNotification::ShowOptionalMobileDataPromoNotification(
+ bool hotkey_debug) {
const NetworkState* default_network =
NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
- if (!default_network || default_network->type() != shill::kTypeCellular)
+ // Do not show notifications to unauthenticated users, or when requesting a
+ // network connection, or if no default_network.
+ if (!default_network || !LoginState::Get()->IsUserAuthenticated() ||
+ NetworkHandler::Get()
+ ->network_connection_handler()
+ ->HasPendingConnectRequest())
+ return;
+ // |hotkey_debug| is temporary code that lets us invoke this notification
+ // via CTRL+ALT+SHIFT+3.
+ if (!hotkey_debug && default_network->type() != shill::kTypeCellular)
return;
- // When requesting a network connection, do not show the notification.
- if (NetworkHandler::Get()->network_connection_handler()->
- HasPendingConnectRequest())
+
+ bool data_saver_prompt_shown = ShowDataSaverNotification(hotkey_debug);
+
+ if (!check_for_promo_)
return;
+ // Display a one-time notification on first use of Mobile Data connection or
+ // if there is a carrier deal defined show that even if user has already seen
+ // generic promo.
int carrier_deal_promo_pref = kNotificationCountPrefDefault;
const MobileConfig::CarrierDeal* deal = NULL;
const MobileConfig::Carrier* carrier = GetCarrier(default_network);
@@ -201,7 +235,7 @@ void DataPromoNotification::ShowOptionalMobileDataPromoNotification() {
info_url = deal->info_url();
if (info_url.empty() && carrier)
info_url = carrier->top_up_url();
- } else if (!ShouldShow3gPromoNotification()) {
+ } else if (data_saver_prompt_shown || !ShouldShow3gPromoNotification()) {
check_for_promo_ = false;
return;
}
@@ -226,4 +260,50 @@ void DataPromoNotification::ShowOptionalMobileDataPromoNotification() {
SetCarrierDealPromoShown(carrier_deal_promo_pref + 1);
}
+bool DataPromoNotification::ShowDataSaverNotification(bool hotkey_debug) {
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kEnableDataSaverPrompt))
+ return false;
+
+ int times_shown = GetDataSaverPromptsShown();
+ if (!hotkey_debug && times_shown >= kTimesToShowDataSaverPrompt)
+ return false;
+
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ if (extensions::ExtensionRegistry::Get(profile)
+ ->GetExtensionById(extension_misc::kDataSaverExtensionId,
+ extensions::ExtensionRegistry::EVERYTHING)) {
+ // If extension is installed, disable future prompts.
+ SetDataSaverPromptsShown(kTimesToShowDataSaverPrompt);
+ return false;
+ }
+
+ const NetworkState* default_network =
+ NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
+
+ base::string16 title = l10n_util::GetStringUTF16(IDS_3G_DATASAVER_TITLE);
+ base::string16 message = l10n_util::GetStringUTF16(IDS_3G_DATASAVER_MESSAGE);
+ const gfx::Image& icon =
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ IDR_AURA_UBER_TRAY_NOTIFICATION_DATASAVER);
+
+ // Clears the cached notification; otherwise, future calls from this session
+ // won't display it.
+ if (hotkey_debug) {
+ message_center::MessageCenter::Get()->RemoveNotification(
+ kDataPromoNotificationId, false);
+ }
+
+ message_center::MessageCenter::Get()->AddNotification(
+ message_center::Notification::CreateSystemNotification(
+ kDataPromoNotificationId, title, message, icon,
+ ui::NetworkStateNotifier::kNotifierNetwork,
+ base::Bind(&NotificationClicked, default_network->path(),
+ kDataSaverExtensionUrl)));
+
+ // Hotkey resets times shown count.
+ SetDataSaverPromptsShown(hotkey_debug ? 0 : times_shown + 1);
+ return true;
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698