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

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

Issue 7778043: [cros] Support global carrier config. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/network_menu_button.h" 5 #include "chrome/browser/chromeos/status/network_menu_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 Browser* browser = BrowserList::GetLastActive(); 270 Browser* browser = BrowserList::GetLastActive();
271 if (!browser) 271 if (!browser)
272 return; 272 return;
273 browser->ShowSingletonTab(GURL(deal_url_to_open)); 273 browser->ShowSingletonTab(GURL(deal_url_to_open));
274 } 274 }
275 } 275 }
276 276
277 //////////////////////////////////////////////////////////////////////////////// 277 ////////////////////////////////////////////////////////////////////////////////
278 // NetworkMenuButton, private methods: 278 // NetworkMenuButton, private methods:
279 279
280 const ServicesCustomizationDocument::CarrierDeal* 280 const MobileConfig::Carrier* NetworkMenuButton::GetCarrier(
281 NetworkMenuButton::GetCarrierDeal(
282 NetworkLibrary* cros) { 281 NetworkLibrary* cros) {
283 std::string carrier_id = cros->GetCellularHomeCarrierId(); 282 std::string carrier_id = cros->GetCellularHomeCarrierId();
284 if (carrier_id.empty()) { 283 if (carrier_id.empty()) {
285 LOG(ERROR) << "Empty carrier ID with a cellular connected."; 284 LOG(ERROR) << "Empty carrier ID with a cellular connected.";
286 return NULL; 285 return NULL;
287 } 286 }
288 287
289 ServicesCustomizationDocument* customization = 288 MobileConfig* config = MobileConfig::GetInstance();
290 ServicesCustomizationDocument::GetInstance(); 289 if (!config->IsReady())
291 if (!customization->IsReady())
292 return NULL; 290 return NULL;
293 291
294 const ServicesCustomizationDocument::CarrierDeal* deal = 292 return config->GetCarrier(carrier_id);
295 customization->GetCarrierDeal(carrier_id, true); 293 }
294
295 const MobileConfig::CarrierDeal* NetworkMenuButton::GetCarrierDeal(
296 const MobileConfig::Carrier* carrier) {
297 const MobileConfig::CarrierDeal* deal = carrier->GetDefaultDeal();
296 if (deal) { 298 if (deal) {
297 // Check deal for validity. 299 // Check deal for validity.
298 int carrier_deal_promo_pref = GetCarrierDealPromoShown(); 300 int carrier_deal_promo_pref = GetCarrierDealPromoShown();
299 if (carrier_deal_promo_pref >= deal->notification_count()) 301 if (carrier_deal_promo_pref >= deal->notification_count())
300 return NULL; 302 return NULL;
301 const std::string locale = g_browser_process->GetApplicationLocale(); 303 const std::string locale = g_browser_process->GetApplicationLocale();
302 std::string deal_text = deal->GetLocalizedString(locale, 304 std::string deal_text = deal->GetLocalizedString(locale,
303 "notification_text"); 305 "notification_text");
304 if (deal_text.empty()) 306 if (deal_text.empty())
305 return NULL; 307 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 349
348 void NetworkMenuButton::ShowOptionalMobileDataPromoNotification( 350 void NetworkMenuButton::ShowOptionalMobileDataPromoNotification(
349 NetworkLibrary* cros) { 351 NetworkLibrary* cros) {
350 // Display one-time notification for non-Guest users on first use 352 // Display one-time notification for non-Guest users on first use
351 // of Mobile Data connection or if there's a carrier deal defined 353 // of Mobile Data connection or if there's a carrier deal defined
352 // show that even if user has already seen generic promo. 354 // show that even if user has already seen generic promo.
353 if (is_browser_mode_ && !UserManager::Get()->IsLoggedInAsGuest() && 355 if (is_browser_mode_ && !UserManager::Get()->IsLoggedInAsGuest() &&
354 check_for_promo_ && BrowserList::GetLastActive() && 356 check_for_promo_ && BrowserList::GetLastActive() &&
355 cros->cellular_connected() && !cros->ethernet_connected() && 357 cros->cellular_connected() && !cros->ethernet_connected() &&
356 !cros->wifi_connected()) { 358 !cros->wifi_connected()) {
357 const ServicesCustomizationDocument::CarrierDeal* deal = 359 const MobileConfig::Carrier* carrier = GetCarrier(cros);
358 GetCarrierDeal(cros);
359 std::string deal_text; 360 std::string deal_text;
360 int carrier_deal_promo_pref = -1; 361 int carrier_deal_promo_pref = -1;
361 if (deal) { 362 if (carrier) {
363 const MobileConfig::CarrierDeal* deal = GetCarrierDeal(carrier);
362 carrier_deal_promo_pref = GetCarrierDealPromoShown(); 364 carrier_deal_promo_pref = GetCarrierDealPromoShown();
363 const std::string locale = g_browser_process->GetApplicationLocale(); 365 const std::string locale = g_browser_process->GetApplicationLocale();
364 deal_text = deal->GetLocalizedString(locale, "notification_text"); 366 deal_text = deal->GetLocalizedString(locale, "notification_text");
365 deal_info_url_ = deal->info_url(); 367 deal_info_url_ = deal->info_url();
366 deal_topup_url_ = deal->top_up_url(); 368 deal_topup_url_ = carrier->top_up_url();
367 } else if (!ShouldShow3gPromoNotification()) { 369 } else if (!ShouldShow3gPromoNotification()) {
368 check_for_promo_ = false; 370 check_for_promo_ = false;
369 return; 371 return;
370 } 372 }
371 373
372 gfx::Rect button_bounds = GetScreenBounds(); 374 gfx::Rect button_bounds = GetScreenBounds();
373 // StatusArea button Y position is usually -1, fix it so that 375 // StatusArea button Y position is usually -1, fix it so that
374 // Contains() method for screen bounds works correctly. 376 // Contains() method for screen bounds works correctly.
375 button_bounds.set_y(button_bounds.y() + 1); 377 button_bounds.set_y(button_bounds.y() + 1);
376 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size())); 378 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); 431 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1);
430 } 432 }
431 } 433 }
432 434
433 void NetworkMenuButton::SetTooltipAndAccessibleName(const string16& label) { 435 void NetworkMenuButton::SetTooltipAndAccessibleName(const string16& label) {
434 SetTooltipText(UTF16ToWide(label)); 436 SetTooltipText(UTF16ToWide(label));
435 SetAccessibleName(label); 437 SetAccessibleName(label);
436 } 438 }
437 439
438 } // namespace chromeos 440 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698