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

Side by Side Diff: chrome/browser/chromeos/network_message_observer.cc

Issue 10947046: Eliminate kAshNotifyDisabled and SystemNotification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit Created 8 years, 2 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"
8 #include "ash/shell.h" 7 #include "ash/shell.h"
9 #include "ash/shell_delegate.h" 8 #include "ash/shell_delegate.h"
10 #include "ash/system/network/network_observer.h" 9 #include "ash/system/network/network_observer.h"
11 #include "ash/system/tray/system_tray.h" 10 #include "ash/system/tray/system_tray.h"
12 #include "base/bind.h" 11 #include "base/bind.h"
13 #include "base/callback.h" 12 #include "base/callback.h"
14 #include "base/command_line.h"
15 #include "base/stl_util.h" 13 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
17 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/chromeos/cros/cros_library.h" 16 #include "chrome/browser/chromeos/cros/cros_library.h"
19 #include "chrome/browser/chromeos/cros/network_library.h" 17 #include "chrome/browser/chromeos/cros/network_library.h"
20 #include "chrome/browser/chromeos/notifications/balloon_view_host_chromeos.h" 18 #include "chrome/browser/chromeos/notifications/balloon_view_host_chromeos.h"
21 #include "chrome/browser/chromeos/notifications/system_notification.h"
22 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/singleton_tabs.h" 24 #include "chrome/browser/ui/singleton_tabs.h"
28 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
29 #include "chrome/common/time_format.h" 26 #include "chrome/common/time_format.h"
30 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
31 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 case ash::NetworkObserver::MESSAGE_DATA_NONE: 63 case ash::NetworkObserver::MESSAGE_DATA_NONE:
67 id = "network_no_data.chromeos"; 64 id = "network_no_data.chromeos";
68 icon_id = IDR_NOTIFICATION_BARS_EMPTY; 65 icon_id = IDR_NOTIFICATION_BARS_EMPTY;
69 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE); 66 title_ = l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_DATA_TITLE);
70 break; 67 break;
71 case ash::NetworkObserver::MESSAGE_DATA_PROMO: 68 case ash::NetworkObserver::MESSAGE_DATA_PROMO:
72 NOTREACHED(); 69 NOTREACHED();
73 break; 70 break;
74 } 71 }
75 DCHECK(!id.empty()); 72 DCHECK(!id.empty());
76 if (CommandLine::ForCurrentProcess()->HasSwitch(
77 ash::switches::kAshNotifyDisabled)) {
78 system_notification_.reset(
79 new SystemNotification(profile, id, icon_id, title_));
80 }
81 } 73 }
82 74
83 // Overridden from ash::NetworkTrayDelegate: 75 // Overridden from ash::NetworkTrayDelegate:
84 virtual void NotificationLinkClicked(size_t index) OVERRIDE { 76 virtual void NotificationLinkClicked(size_t index) OVERRIDE {
85 base::ListValue empty_value; 77 base::ListValue empty_value;
86 if (!callback_.is_null()) 78 if (!callback_.is_null())
87 callback_.Run(&empty_value); 79 callback_.Run(&empty_value);
88 } 80 }
89 81
90 void Hide() { 82 void Hide() {
91 if (system_notification_.get()) { 83 ash::Shell::GetInstance()->system_tray()->network_observer()->
92 system_notification_->Hide(); 84 ClearNetworkMessage(error_type_);
93 } else {
94 ash::Shell::GetInstance()->system_tray()->network_observer()->
95 ClearNetworkMessage(error_type_);
96 }
97 } 85 }
98 86
99 void SetTitle(const string16& title) { 87 void SetTitle(const string16& title) {
100 title_ = title; 88 title_ = title;
101 if (system_notification_.get()) {
102 system_notification_->set_title(title);
103 }
104 } 89 }
105 90
106 void Show(const string16& message, 91 void Show(const string16& message,
107 const string16& link_text, 92 const string16& link_text,
108 const BalloonViewHost::MessageCallback& callback, 93 const BalloonViewHost::MessageCallback& callback,
109 bool urgent, bool sticky) { 94 bool urgent, bool sticky) {
110 if (system_notification_.get()) { 95 callback_ = callback;
111 system_notification_->Show(message, link_text, callback, urgent, sticky); 96 std::vector<string16> links;
112 } else { 97 links.push_back(link_text);
113 callback_ = callback; 98 ash::Shell::GetInstance()->system_tray()->network_observer()->
114 std::vector<string16> links; 99 SetNetworkMessage(this, error_type_, title_, message, links);
115 links.push_back(link_text);
116 ash::Shell::GetInstance()->system_tray()->network_observer()->
117 SetNetworkMessage(this, error_type_, title_, message, links);
118 }
119 } 100 }
120 101
121 void ShowAlways(const string16& message, 102 void ShowAlways(const string16& message,
122 const string16& link_text, 103 const string16& link_text,
123 const BalloonViewHost::MessageCallback& callback, 104 const BalloonViewHost::MessageCallback& callback,
124 bool urgent, bool sticky) { 105 bool urgent, bool sticky) {
125 if (system_notification_.get()) {
126 // Hide if already shown to force show it in case user has closed it.
127 if (system_notification_->visible())
128 system_notification_->Hide();
129 }
130 Show(message, link_text, callback, urgent, sticky); 106 Show(message, link_text, callback, urgent, sticky);
131 } 107 }
132 108
133 private: 109 private:
134 string16 title_; 110 string16 title_;
135 scoped_ptr<SystemNotification> system_notification_;
136 ash::NetworkObserver::MessageType error_type_; 111 ash::NetworkObserver::MessageType error_type_;
137 BalloonViewHost::MessageCallback callback_; 112 BalloonViewHost::MessageCallback callback_;
138 }; 113 };
139 114
140 NetworkMessageObserver::NetworkMessageObserver(Profile* profile) { 115 NetworkMessageObserver::NetworkMessageObserver(Profile* profile) {
141 notification_connection_error_.reset( 116 notification_connection_error_.reset(
142 new NetworkMessageNotification( 117 new NetworkMessageNotification(
143 profile, ash::NetworkObserver::ERROR_CONNECT_FAILED)); 118 profile, ash::NetworkObserver::ERROR_CONNECT_FAILED));
144 notification_low_data_.reset( 119 notification_low_data_.reset(
145 new NetworkMessageNotification( 120 new NetworkMessageNotification(
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (plan) { 369 if (plan) {
395 cellular_data_plan_unique_id_ = plan->GetUniqueIdentifier(); 370 cellular_data_plan_unique_id_ = plan->GetUniqueIdentifier();
396 cellular_data_plan_type_ = plan->plan_type; 371 cellular_data_plan_type_ = plan->plan_type;
397 } else { 372 } else {
398 cellular_data_plan_unique_id_ = std::string(); 373 cellular_data_plan_unique_id_ = std::string();
399 cellular_data_plan_type_ = CELLULAR_DATA_PLAN_UNKNOWN; 374 cellular_data_plan_type_ = CELLULAR_DATA_PLAN_UNKNOWN;
400 } 375 }
401 } 376 }
402 377
403 } // namespace chromeos 378 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.cc ('k') | chrome/browser/chromeos/notifications/system_notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698