Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 41 bool GetBooleanPref(const char* pref_name) { | 41 bool GetBooleanPref(const char* pref_name) { |
| 42 Browser* browser = BrowserList::GetLastActive(); | 42 Browser* browser = BrowserList::GetLastActive(); |
| 43 // Default to safe value which is false (not to show bubble). | 43 // Default to safe value which is false (not to show bubble). |
| 44 if (!browser || !browser->profile()) | 44 if (!browser || !browser->profile()) |
| 45 return false; | 45 return false; |
| 46 | 46 |
| 47 PrefService* prefs = browser->profile()->GetPrefs(); | 47 PrefService* prefs = browser->profile()->GetPrefs(); |
| 48 return prefs->GetBoolean(pref_name); | 48 return prefs->GetBoolean(pref_name); |
| 49 } | 49 } |
| 50 | 50 |
| 51 int GetIntegerPref(const char* pref_name) { | 51 int GetIntegerLocalPref(const char* pref_name) { |
| 52 Browser* browser = BrowserList::GetLastActive(); | 52 PrefService* prefs = g_browser_process->local_state(); |
| 53 // Default to "safe" value. | |
| 54 if (!browser || !browser->profile()) | |
| 55 return kNotificationCountPrefDefault; | |
| 56 | |
| 57 PrefService* prefs = browser->profile()->GetPrefs(); | |
| 58 return prefs->GetInteger(pref_name); | 53 return prefs->GetInteger(pref_name); |
| 59 } | 54 } |
| 60 | 55 |
| 61 void SetBooleanPref(const char* pref_name, bool value) { | 56 void SetBooleanPref(const char* pref_name, bool value) { |
| 62 Browser* browser = BrowserList::GetLastActive(); | 57 Browser* browser = BrowserList::GetLastActive(); |
| 63 if (!browser || !browser->profile()) | 58 if (!browser || !browser->profile()) |
| 64 return; | 59 return; |
| 65 | 60 |
| 66 PrefService* prefs = browser->profile()->GetPrefs(); | 61 PrefService* prefs = browser->profile()->GetPrefs(); |
| 67 prefs->SetBoolean(pref_name, value); | 62 prefs->SetBoolean(pref_name, value); |
| 68 } | 63 } |
| 69 | 64 |
| 70 void SetIntegerPref(const char* pref_name, int value) { | 65 void SetIntegerLocalPref(const char* pref_name, int value) { |
| 71 Browser* browser = BrowserList::GetLastActive(); | 66 PrefService* prefs = g_browser_process->local_state(); |
| 72 if (!browser || !browser->profile()) | |
| 73 return; | |
| 74 | |
| 75 PrefService* prefs = browser->profile()->GetPrefs(); | |
| 76 prefs->SetInteger(pref_name, value); | 67 prefs->SetInteger(pref_name, value); |
| 77 } | 68 } |
| 78 | 69 |
| 79 // Returns prefs::kShow3gPromoNotification or false | 70 // Returns prefs::kShow3gPromoNotification or false |
| 80 // if there's no active browser. | 71 // if there's no active browser. |
| 81 bool ShouldShow3gPromoNotification() { | 72 bool ShouldShow3gPromoNotification() { |
| 82 return GetBooleanPref(prefs::kShow3gPromoNotification); | 73 return GetBooleanPref(prefs::kShow3gPromoNotification); |
| 83 } | 74 } |
| 84 | 75 |
| 85 void SetShow3gPromoNotification(bool value) { | 76 void SetShow3gPromoNotification(bool value) { |
| 86 SetBooleanPref(prefs::kShow3gPromoNotification, value); | 77 SetBooleanPref(prefs::kShow3gPromoNotification, value); |
| 87 } | 78 } |
| 88 // Returns prefs::kCarrierDealPromoShown which is number of times | 79 // Returns prefs::kCarrierDealPromoShown which is number of times |
|
Dmitry Polukhin
2011/05/23 12:46:59
Please add empty line above the comment.
Nikita (slow)
2011/05/24 08:22:53
Done.
| |
| 89 // carrier deal notification has been shown to user or -1 | 80 // carrier deal notification has been shown to users on this machine. |
| 90 // if there's no active browser. | |
| 91 int GetCarrierDealPromoShown() { | 81 int GetCarrierDealPromoShown() { |
| 92 return GetIntegerPref(prefs::kCarrierDealPromoShown); | 82 return GetIntegerLocalPref(prefs::kCarrierDealPromoShown); |
| 93 } | 83 } |
| 94 | 84 |
| 95 void SetCarrierDealPromoShown(int value) { | 85 void SetCarrierDealPromoShown(int value) { |
| 96 SetIntegerPref(prefs::kCarrierDealPromoShown, value); | 86 SetIntegerLocalPref(prefs::kCarrierDealPromoShown, value); |
| 97 } | 87 } |
| 98 | 88 |
| 99 } // namespace | 89 } // namespace |
| 100 | 90 |
| 101 namespace chromeos { | 91 namespace chromeos { |
| 102 | 92 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
| 104 // NetworkMenuButton | 94 // NetworkMenuButton |
| 105 | 95 |
| 106 // static | 96 // static |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 133 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 123 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 134 netlib->RemoveNetworkManagerObserver(this); | 124 netlib->RemoveNetworkManagerObserver(this); |
| 135 netlib->RemoveObserverForAllNetworks(this); | 125 netlib->RemoveObserverForAllNetworks(this); |
| 136 netlib->RemoveCellularDataPlanObserver(this); | 126 netlib->RemoveCellularDataPlanObserver(this); |
| 137 if (!cellular_device_path_.empty()) | 127 if (!cellular_device_path_.empty()) |
| 138 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); | 128 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); |
| 139 if (mobile_data_bubble_) | 129 if (mobile_data_bubble_) |
| 140 mobile_data_bubble_->Close(); | 130 mobile_data_bubble_->Close(); |
| 141 } | 131 } |
| 142 | 132 |
| 133 // static | |
| 134 void NetworkMenuButton::RegisterPrefs(PrefService* local_state) { | |
| 135 // Carrier deal notification shown count defaults to 0. | |
| 136 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0); | |
| 137 } | |
| 138 | |
| 143 //////////////////////////////////////////////////////////////////////////////// | 139 //////////////////////////////////////////////////////////////////////////////// |
| 144 // NetworkMenuButton, ui::AnimationDelegate implementation: | 140 // NetworkMenuButton, ui::AnimationDelegate implementation: |
| 145 | 141 |
| 146 void NetworkMenuButton::AnimationProgressed(const ui::Animation* animation) { | 142 void NetworkMenuButton::AnimationProgressed(const ui::Animation* animation) { |
| 147 if (animation == &animation_connecting_) { | 143 if (animation == &animation_connecting_) { |
| 148 SetIconOnly(IconForNetworkConnecting( | 144 SetIconOnly(IconForNetworkConnecting( |
| 149 animation_connecting_.GetCurrentValue(), false)); | 145 animation_connecting_.GetCurrentValue(), false)); |
| 150 // No need to set the badge here, because it should already be set. | 146 // No need to set the badge here, because it should already be set. |
| 151 SchedulePaint(); | 147 SchedulePaint(); |
| 152 } else { | 148 } else { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 this); | 486 this); |
| 491 | 487 |
| 492 check_for_promo_ = false; | 488 check_for_promo_ = false; |
| 493 SetShow3gPromoNotification(false); | 489 SetShow3gPromoNotification(false); |
| 494 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) | 490 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) |
| 495 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); | 491 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); |
| 496 } | 492 } |
| 497 } | 493 } |
| 498 | 494 |
| 499 } // namespace chromeos | 495 } // namespace chromeos |
| OLD | NEW |