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/sms_observer.h" | 5 #include "chrome/browser/chromeos/sms_observer.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
9 #include "chrome/browser/chromeos/notifications/system_notification.h" | 9 #include "chrome/browser/chromeos/notifications/system_notification.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
13 #include "third_party/cros/chromeos_network.h" | 13 #include "third_party/cros/chromeos_network.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 SmsObserver::SmsObserver(Profile* profile) | 18 SmsObserver::SmsObserver(Profile* profile) |
19 : profile_(profile) { | 19 : profile_(profile) { |
20 DCHECK(profile_); | 20 DCHECK(profile_); |
21 if (!CrosLibrary::Get()->EnsureLoaded()) | |
22 return; | |
23 | |
24 UpdateObservers(chromeos::CrosLibrary::Get()->GetNetworkLibrary()); | 21 UpdateObservers(chromeos::CrosLibrary::Get()->GetNetworkLibrary()); |
25 } | 22 } |
26 | 23 |
27 SmsObserver::~SmsObserver() { | 24 SmsObserver::~SmsObserver() { |
28 NetworkLibrary* library = chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 25 NetworkLibrary* library = chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
29 library->RemoveNetworkManagerObserver(this); | 26 library->RemoveNetworkManagerObserver(this); |
30 DisconnectAll(); | 27 DisconnectAll(); |
31 } | 28 } |
32 | 29 |
33 void SmsObserver::UpdateObservers(NetworkLibrary* library) { | 30 void SmsObserver::UpdateObservers(NetworkLibrary* library) { |
34 if (!CrosLibrary::Get()->EnsureLoaded() || | 31 if (!CrosLibrary::Get()->libcros_loaded()) |
satorux1
2011/11/16 23:51:34
This is a valid check. Let's add some comment like
stevenjb
2011/11/17 00:23:33
Done.
| |
35 !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) | |
36 return; | 32 return; |
37 | 33 |
38 const CellularNetworkVector& networks = library->cellular_networks(); | 34 const CellularNetworkVector& networks = library->cellular_networks(); |
39 // Remove monitors for networks that are not in the list anymore. | 35 // Remove monitors for networks that are not in the list anymore. |
40 for (ObserversMap::iterator it_observer = observers_.begin(); | 36 for (ObserversMap::iterator it_observer = observers_.begin(); |
41 it_observer != observers_.end();) { | 37 it_observer != observers_.end();) { |
42 bool found = false; | 38 bool found = false; |
43 for (CellularNetworkVector::const_iterator it_network = networks.begin(); | 39 for (CellularNetworkVector::const_iterator it_network = networks.begin(); |
44 it_network != networks.end(); ++it_network) { | 40 it_network != networks.end(); ++it_network) { |
45 if (it_observer->first == (*it_network)->device_path()) { | 41 if (it_observer->first == (*it_network)->device_path()) { |
(...skipping 25 matching lines...) Expand all Loading... | |
71 chromeos::SMSMonitor monitor = | 67 chromeos::SMSMonitor monitor = |
72 chromeos::MonitorSMS(device_path.c_str(), &StaticCallback, this); | 68 chromeos::MonitorSMS(device_path.c_str(), &StaticCallback, this); |
73 observers_.insert(ObserversMap::value_type(device_path, monitor)); | 69 observers_.insert(ObserversMap::value_type(device_path, monitor)); |
74 } else { | 70 } else { |
75 VLOG(1) << "Already has SMS monitor for " << device_path; | 71 VLOG(1) << "Already has SMS monitor for " << device_path; |
76 } | 72 } |
77 } | 73 } |
78 } | 74 } |
79 | 75 |
80 void SmsObserver::DisconnectAll() { | 76 void SmsObserver::DisconnectAll() { |
81 if (!CrosLibrary::Get()->EnsureLoaded() || | 77 if (!CrosLibrary::Get()->libcros_loaded()) |
82 !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) | |
83 return; | 78 return; |
84 | 79 |
85 for (ObserversMap::iterator it = observers_.begin(); | 80 for (ObserversMap::iterator it = observers_.begin(); |
86 it != observers_.end(); ++it) { | 81 it != observers_.end(); ++it) { |
87 VLOG(1) << "Remove SMS monitor for " << it->first; | 82 VLOG(1) << "Remove SMS monitor for " << it->first; |
88 chromeos::DisconnectSMSMonitor(it->second); | 83 chromeos::DisconnectSMSMonitor(it->second); |
89 } | 84 } |
90 observers_.clear(); | 85 observers_.clear(); |
91 } | 86 } |
92 | 87 |
(...skipping 18 matching lines...) Expand all Loading... | |
111 profile_, | 106 profile_, |
112 "incoming _sms.chromeos", | 107 "incoming _sms.chromeos", |
113 IDR_NOTIFICATION_SMS, | 108 IDR_NOTIFICATION_SMS, |
114 l10n_util::GetStringFUTF16( | 109 l10n_util::GetStringFUTF16( |
115 IDS_SMS_NOTIFICATION_TITLE, UTF8ToUTF16(message->number))); | 110 IDS_SMS_NOTIFICATION_TITLE, UTF8ToUTF16(message->number))); |
116 | 111 |
117 note.Show(UTF8ToUTF16(message->text), true, false); | 112 note.Show(UTF8ToUTF16(message->text), true, false); |
118 } | 113 } |
119 | 114 |
120 } // namespace chromeos | 115 } // namespace chromeos |
OLD | NEW |