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 } |
| 79 |
88 // Returns prefs::kCarrierDealPromoShown which is number of times | 80 // Returns prefs::kCarrierDealPromoShown which is number of times |
89 // carrier deal notification has been shown to user or -1 | 81 // carrier deal notification has been shown to users on this machine. |
90 // if there's no active browser. | |
91 int GetCarrierDealPromoShown() { | 82 int GetCarrierDealPromoShown() { |
92 return GetIntegerPref(prefs::kCarrierDealPromoShown); | 83 return GetIntegerLocalPref(prefs::kCarrierDealPromoShown); |
93 } | 84 } |
94 | 85 |
95 void SetCarrierDealPromoShown(int value) { | 86 void SetCarrierDealPromoShown(int value) { |
96 SetIntegerPref(prefs::kCarrierDealPromoShown, value); | 87 SetIntegerLocalPref(prefs::kCarrierDealPromoShown, value); |
97 } | 88 } |
98 | 89 |
99 } // namespace | 90 } // namespace |
100 | 91 |
101 namespace chromeos { | 92 namespace chromeos { |
102 | 93 |
103 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
104 // NetworkMenuButton | 95 // NetworkMenuButton |
105 | 96 |
106 // static | 97 // static |
(...skipping 26 matching lines...) Expand all Loading... |
133 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 124 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
134 netlib->RemoveNetworkManagerObserver(this); | 125 netlib->RemoveNetworkManagerObserver(this); |
135 netlib->RemoveObserverForAllNetworks(this); | 126 netlib->RemoveObserverForAllNetworks(this); |
136 netlib->RemoveCellularDataPlanObserver(this); | 127 netlib->RemoveCellularDataPlanObserver(this); |
137 if (!cellular_device_path_.empty()) | 128 if (!cellular_device_path_.empty()) |
138 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); | 129 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); |
139 if (mobile_data_bubble_) | 130 if (mobile_data_bubble_) |
140 mobile_data_bubble_->Close(); | 131 mobile_data_bubble_->Close(); |
141 } | 132 } |
142 | 133 |
| 134 // static |
| 135 void NetworkMenuButton::RegisterPrefs(PrefService* local_state) { |
| 136 // Carrier deal notification shown count defaults to 0. |
| 137 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0); |
| 138 } |
| 139 |
143 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
144 // NetworkMenuButton, ui::AnimationDelegate implementation: | 141 // NetworkMenuButton, ui::AnimationDelegate implementation: |
145 | 142 |
146 void NetworkMenuButton::AnimationProgressed(const ui::Animation* animation) { | 143 void NetworkMenuButton::AnimationProgressed(const ui::Animation* animation) { |
147 if (animation == &animation_connecting_) { | 144 if (animation == &animation_connecting_) { |
148 SetIconOnly(IconForNetworkConnecting( | 145 SetIconOnly(IconForNetworkConnecting( |
149 animation_connecting_.GetCurrentValue(), false)); | 146 animation_connecting_.GetCurrentValue(), false)); |
150 // No need to set the badge here, because it should already be set. | 147 // No need to set the badge here, because it should already be set. |
151 SchedulePaint(); | 148 SchedulePaint(); |
152 } else { | 149 } else { |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 this); | 487 this); |
491 | 488 |
492 check_for_promo_ = false; | 489 check_for_promo_ = false; |
493 SetShow3gPromoNotification(false); | 490 SetShow3gPromoNotification(false); |
494 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) | 491 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) |
495 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); | 492 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); |
496 } | 493 } |
497 } | 494 } |
498 | 495 |
499 } // namespace chromeos | 496 } // namespace chromeos |
OLD | NEW |