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

Side by Side Diff: chrome/browser/chromeos/status/data_promo_notification.cc

Issue 10907224: Data promo notification should follow the normal ash notifications theme. This (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/status/data_promo_notification.h" 5 #include "chrome/browser/chromeos/status/data_promo_notification.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/system/network/network_observer.h"
10 #include "ash/system/tray/system_tray.h"
9 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
12 #include "chrome/browser/chromeos/cros/network_library.h" 14 #include "chrome/browser/chromeos/cros/network_library.h"
13 #include "chrome/browser/chromeos/login/helper.h" 15 #include "chrome/browser/chromeos/login/helper.h"
14 #include "chrome/browser/chromeos/login/message_bubble.h"
15 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/chromeos/mobile_config.h" 17 #include "chrome/browser/chromeos/mobile_config.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 111 }
111 112
112 } // namespace 113 } // namespace
113 114
114 namespace chromeos { 115 namespace chromeos {
115 116
116 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
117 // DataPromoNotification 118 // DataPromoNotification
118 119
119 DataPromoNotification::DataPromoNotification() 120 DataPromoNotification::DataPromoNotification()
120 : mobile_data_bubble_(NULL), 121 : check_for_promo_(true),
121 check_for_promo_(true),
122 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 122 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
123 } 123 }
124 124
125 DataPromoNotification::~DataPromoNotification() { 125 DataPromoNotification::~DataPromoNotification() {
126 if (mobile_data_bubble_) 126 CloseNotification();
127 mobile_data_bubble_->GetWidget()->Close();
128 } 127 }
129 128
130 void DataPromoNotification::RegisterPrefs(PrefService* local_state) { 129 void DataPromoNotification::RegisterPrefs(PrefService* local_state) {
131 // Carrier deal notification shown count defaults to 0. 130 // Carrier deal notification shown count defaults to 0.
132 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0); 131 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0);
133 } 132 }
134 133
135 void DataPromoNotification::ShowOptionalMobileDataPromoNotification( 134 void DataPromoNotification::ShowOptionalMobileDataPromoNotification(
136 NetworkLibrary* cros, 135 NetworkLibrary* cros,
137 views::View* host, 136 views::View* host,
138 MessageBubbleLinkListener* listener) { 137 ash::NetworkTrayDelegate* listener) {
139 // Display one-time notification for non-Guest users on first use 138 // Display one-time notification for non-Guest users on first use
140 // of Mobile Data connection or if there's a carrier deal defined 139 // of Mobile Data connection or if there's a carrier deal defined
141 // show that even if user has already seen generic promo. 140 // show that even if user has already seen generic promo.
142 if (UserManager::Get()->IsUserLoggedIn() && 141 if (UserManager::Get()->IsUserLoggedIn() &&
143 !UserManager::Get()->IsLoggedInAsGuest() && 142 !UserManager::Get()->IsLoggedInAsGuest() &&
144 check_for_promo_ && 143 check_for_promo_ &&
145 cros->cellular_connected() && !cros->ethernet_connected() && 144 cros->cellular_connected() && !cros->ethernet_connected() &&
146 !cros->wifi_connected() && !cros->wimax_connected()) { 145 !cros->wifi_connected() && !cros->wimax_connected()) {
147 std::string deal_text; 146 std::string deal_text;
148 int carrier_deal_promo_pref = kNotificationCountPrefDefault; 147 int carrier_deal_promo_pref = kNotificationCountPrefDefault;
149 const MobileConfig::CarrierDeal* deal = NULL; 148 const MobileConfig::CarrierDeal* deal = NULL;
150 const MobileConfig::Carrier* carrier = GetCarrier(cros); 149 const MobileConfig::Carrier* carrier = GetCarrier(cros);
151 if (carrier) 150 if (carrier)
152 deal = GetCarrierDeal(carrier); 151 deal = GetCarrierDeal(carrier);
152 deal_info_url_.clear();
153 deal_topup_url_.clear();
153 if (deal) { 154 if (deal) {
154 carrier_deal_promo_pref = GetCarrierDealPromoShown(); 155 carrier_deal_promo_pref = GetCarrierDealPromoShown();
155 const std::string locale = g_browser_process->GetApplicationLocale(); 156 const std::string locale = g_browser_process->GetApplicationLocale();
156 deal_text = deal->GetLocalizedString(locale, "notification_text"); 157 deal_text = deal->GetLocalizedString(locale, "notification_text");
157 deal_info_url_ = deal->info_url(); 158 deal_info_url_ = deal->info_url();
158 deal_topup_url_ = carrier->top_up_url(); 159 deal_topup_url_ = carrier->top_up_url();
159 } else if (!ShouldShow3gPromoNotification()) { 160 } else if (!ShouldShow3gPromoNotification()) {
160 check_for_promo_ = false; 161 check_for_promo_ = false;
161 return; 162 return;
162 } 163 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 int link_message_id; 195 int link_message_id;
195 if (deal_topup_url_.empty()) 196 if (deal_topup_url_.empty())
196 link_message_id = IDS_OFFLINE_NETWORK_SETTINGS; 197 link_message_id = IDS_OFFLINE_NETWORK_SETTINGS;
197 else 198 else
198 link_message_id = IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT; 199 link_message_id = IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT;
199 200
200 std::vector<string16> links; 201 std::vector<string16> links;
201 links.push_back(l10n_util::GetStringUTF16(link_message_id)); 202 links.push_back(l10n_util::GetStringUTF16(link_message_id));
202 if (!deal_info_url_.empty()) 203 if (!deal_info_url_.empty())
203 links.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 204 links.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
204 mobile_data_bubble_ = new MessageBubble( 205 if (ash::Shell::GetInstance()->system_tray()->network_observer()) {
205 host, 206 ash::Shell::GetInstance()->system_tray()->network_observer()->
206 views::BubbleBorder::TOP_RIGHT, 207 SetNetworkMessage(listener, ash::NetworkObserver::MESSAGE_DATA_PROMO,
207 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 208 string16(), message, links);
208 IDR_NOTIFICATION_3G), 209 }
209 message,
210 links);
211 mobile_data_bubble_->set_link_listener(listener);
212 mobile_data_bubble_->set_parent_window(
213 ash::Shell::GetContainer(
214 ash::Shell::GetPrimaryRootWindow(),
215 ash::internal::kShellWindowId_SettingBubbleContainer));
216 views::BubbleDelegateView::CreateBubble(mobile_data_bubble_);
217 mobile_data_bubble_->Show();
218 mobile_data_bubble_->GetWidget()->AddObserver(this);
219 210
220 check_for_promo_ = false; 211 check_for_promo_ = false;
221 SetShow3gPromoNotification(false); 212 SetShow3gPromoNotification(false);
222 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) 213 if (carrier_deal_promo_pref != kNotificationCountPrefDefault)
223 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); 214 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1);
224 } 215 }
225 } 216 }
226 217
227 void DataPromoNotification::CloseNotification() { 218 void DataPromoNotification::CloseNotification() {
228 if (mobile_data_bubble_) 219 if (ash::Shell::GetInstance()->system_tray()->network_observer()) {
229 mobile_data_bubble_->GetWidget()->Close(); 220 ash::Shell::GetInstance()->system_tray()->network_observer()->
230 } 221 ClearNetworkMessage(ash::NetworkObserver::MESSAGE_DATA_PROMO);
231 222 }
232 void DataPromoNotification::OnWidgetClosing(views::Widget* widget) {
233 if (!mobile_data_bubble_ || mobile_data_bubble_->GetWidget() != widget)
234 return;
235
236 mobile_data_bubble_ = NULL;
237 deal_info_url_.clear();
238 deal_topup_url_.clear();
239 } 223 }
240 224
241 } // namespace chromeos 225 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/data_promo_notification.h ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698