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

Side by Side Diff: chrome/browser/chromeos/network_message_observer.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/network_message_observer.h" 5 #include "chrome/browser/chromeos/network_message_observer.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h" 9 #include "ash/shell_delegate.h"
10 #include "ash/system/network/network_observer.h" 10 #include "ash/system/network/network_observer.h"
(...skipping 30 matching lines...) Expand all
41 return prefs->GetBoolean(prefs::kShowPlanNotifications); 41 return prefs->GetBoolean(prefs::kShowPlanNotifications);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 namespace chromeos { 46 namespace chromeos {
47 47
48 class NetworkMessageNotification : public ash::NetworkTrayDelegate { 48 class NetworkMessageNotification : public ash::NetworkTrayDelegate {
49 public: 49 public:
50 NetworkMessageNotification(Profile* profile, 50 NetworkMessageNotification(Profile* profile,
51 ash::NetworkObserver::ErrorType error_type) 51 ash::NetworkObserver::MessageType error_type)
52 : error_type_(error_type) { 52 : error_type_(error_type) {
53 std::string id; 53 std::string id;
54 int icon_id = 0; 54 int icon_id = 0;
55 switch (error_type) { 55 switch (error_type) {
56 case ash::NetworkObserver::ERROR_CONNECT_FAILED: 56 case ash::NetworkObserver::ERROR_CONNECT_FAILED:
57 id = "network_connection.chromeos"; 57 id = "network_connection.chromeos";
58 icon_id = IDR_NOTIFICATION_NETWORK_FAILED; 58 icon_id = IDR_NOTIFICATION_NETWORK_FAILED;
59 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE); 59 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE);
60 break; 60 break;
61 case ash::NetworkObserver::ERROR_DATA_LOW: 61 case ash::NetworkObserver::MESSAGE_DATA_LOW:
62 id = "network_low_data.chromeos"; 62 id = "network_low_data.chromeos";
63 icon_id = IDR_NOTIFICATION_BARS_CRITICAL; 63 icon_id = IDR_NOTIFICATION_BARS_CRITICAL;
64 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_LOW_DATA_TITLE); 64 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_LOW_DATA_TITLE);
65 break; 65 break;
66 case ash::NetworkObserver::ERROR_DATA_NONE: 66 case ash::NetworkObserver::MESSAGE_DATA_NONE:
67 id = "network_no_data.chromeos"; 67 id = "network_no_data.chromeos";
68 icon_id = IDR_NOTIFICATION_BARS_EMPTY; 68 icon_id = IDR_NOTIFICATION_BARS_EMPTY;
69 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE); 69 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE);
70 break; 70 break;
71 case ash::NetworkObserver::MESSAGE_DATA_PROMO:
72 NOTREACHED();
73 break;
71 } 74 }
72 DCHECK(!id.empty()); 75 DCHECK(!id.empty());
73 if (CommandLine::ForCurrentProcess()->HasSwitch( 76 if (CommandLine::ForCurrentProcess()->HasSwitch(
74 ash::switches::kAshNotifyDisabled)) { 77 ash::switches::kAshNotifyDisabled)) {
75 system_notification_.reset( 78 system_notification_.reset(
76 new SystemNotification(profile, id, icon_id, title_)); 79 new SystemNotification(profile, id, icon_id, title_));
77 } 80 }
78 } 81 }
79 82
80 // Overridden from ash::NetworkTrayDelegate: 83 // Overridden from ash::NetworkTrayDelegate:
81 virtual void NotificationLinkClicked() { 84 virtual void NotificationLinkClicked(size_t index) OVERRIDE {
82 base::ListValue empty_value; 85 base::ListValue empty_value;
83 if (!callback_.is_null()) 86 if (!callback_.is_null())
84 callback_.Run(&empty_value); 87 callback_.Run(&empty_value);
85 } 88 }
86 89
87 void Hide() { 90 void Hide() {
88 if (system_notification_.get()) { 91 if (system_notification_.get()) {
89 system_notification_->Hide(); 92 system_notification_->Hide();
90 } else { 93 } else {
91 ash::Shell::GetInstance()->system_tray()->network_observer()-> 94 ash::Shell::GetInstance()->system_tray()->network_observer()->
92 ClearNetworkError(error_type_); 95 ClearNetworkMessage(error_type_);
93 } 96 }
94 } 97 }
95 98
96 void SetTitle(const string16& title) { 99 void SetTitle(const string16& title) {
97 title_ = title; 100 title_ = title;
98 if (system_notification_.get()) { 101 if (system_notification_.get()) {
99 system_notification_->set_title(title); 102 system_notification_->set_title(title);
100 } 103 }
101 } 104 }
102 105
103 void Show(const string16& message, 106 void Show(const string16& message,
104 const string16& link_text, 107 const string16& link_text,
105 const BalloonViewHost::MessageCallback& callback, 108 const BalloonViewHost::MessageCallback& callback,
106 bool urgent, bool sticky) { 109 bool urgent, bool sticky) {
107 if (system_notification_.get()) { 110 if (system_notification_.get()) {
108 system_notification_->Show(message, link_text, callback, urgent, sticky); 111 system_notification_->Show(message, link_text, callback, urgent, sticky);
109 } else { 112 } else {
110 callback_ = callback; 113 callback_ = callback;
114 std::vector<string16> links;
115 links.push_back(link_text);
111 ash::Shell::GetInstance()->system_tray()->network_observer()-> 116 ash::Shell::GetInstance()->system_tray()->network_observer()->
112 SetNetworkError(this, error_type_, title_, message, link_text); 117 SetNetworkMessage(this, error_type_, title_, message, links);
113 } 118 }
114 } 119 }
115 120
116 void ShowAlways(const string16& message, 121 void ShowAlways(const string16& message,
117 const string16& link_text, 122 const string16& link_text,
118 const BalloonViewHost::MessageCallback& callback, 123 const BalloonViewHost::MessageCallback& callback,
119 bool urgent, bool sticky) { 124 bool urgent, bool sticky) {
120 if (system_notification_.get()) { 125 if (system_notification_.get()) {
121 // Hide if already shown to force show it in case user has closed it. 126 // Hide if already shown to force show it in case user has closed it.
122 if (system_notification_->visible()) 127 if (system_notification_->visible())
123 system_notification_->Hide(); 128 system_notification_->Hide();
124 } 129 }
125 Show(message, link_text, callback, urgent, sticky); 130 Show(message, link_text, callback, urgent, sticky);
126 } 131 }
127 132
128 private: 133 private:
129 string16 title_; 134 string16 title_;
130 scoped_ptr<SystemNotification> system_notification_; 135 scoped_ptr<SystemNotification> system_notification_;
131 ash::NetworkObserver::ErrorType error_type_; 136 ash::NetworkObserver::MessageType error_type_;
132 BalloonViewHost::MessageCallback callback_; 137 BalloonViewHost::MessageCallback callback_;
133 }; 138 };
134 139
135 NetworkMessageObserver::NetworkMessageObserver(Profile* profile) { 140 NetworkMessageObserver::NetworkMessageObserver(Profile* profile) {
136 notification_connection_error_.reset( 141 notification_connection_error_.reset(
137 new NetworkMessageNotification( 142 new NetworkMessageNotification(
138 profile, ash::NetworkObserver::ERROR_CONNECT_FAILED)); 143 profile, ash::NetworkObserver::ERROR_CONNECT_FAILED));
139 notification_low_data_.reset( 144 notification_low_data_.reset(
140 new NetworkMessageNotification( 145 new NetworkMessageNotification(
141 profile, 146 profile,
142 ash::NetworkObserver::ERROR_DATA_LOW)); 147 ash::NetworkObserver::MESSAGE_DATA_LOW));
143 notification_no_data_.reset( 148 notification_no_data_.reset(
144 new NetworkMessageNotification( 149 new NetworkMessageNotification(
145 profile, 150 profile,
146 ash::NetworkObserver::ERROR_DATA_NONE)); 151 ash::NetworkObserver::MESSAGE_DATA_NONE));
147 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); 152 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
148 OnNetworkManagerChanged(netlib); 153 OnNetworkManagerChanged(netlib);
149 // Note that this gets added as a NetworkManagerObserver, 154 // Note that this gets added as a NetworkManagerObserver,
150 // CellularDataPlanObserver, and UserActionObserver in 155 // CellularDataPlanObserver, and UserActionObserver in
151 // startup_browser_creator.cc 156 // startup_browser_creator.cc
152 } 157 }
153 158
154 NetworkMessageObserver::~NetworkMessageObserver() { 159 NetworkMessageObserver::~NetworkMessageObserver() {
155 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); 160 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
156 netlib->RemoveNetworkManagerObserver(this); 161 netlib->RemoveNetworkManagerObserver(this);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (plan) { 394 if (plan) {
390 cellular_data_plan_unique_id_ = plan->GetUniqueIdentifier(); 395 cellular_data_plan_unique_id_ = plan->GetUniqueIdentifier();
391 cellular_data_plan_type_ = plan->plan_type; 396 cellular_data_plan_type_ = plan->plan_type;
392 } else { 397 } else {
393 cellular_data_plan_unique_id_ = std::string(); 398 cellular_data_plan_unique_id_ = std::string();
394 cellular_data_plan_type_ = CELLULAR_DATA_PLAN_UNKNOWN; 399 cellular_data_plan_type_ = CELLULAR_DATA_PLAN_UNKNOWN;
395 } 400 }
396 } 401 }
397 402
398 } // namespace chromeos 403 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | chrome/browser/chromeos/status/data_promo_notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698