| 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 // Guard against calls to libcros (http://crosbug.com/17863). |
| 35 !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) | 32 if (!CrosLibrary::Get()->libcros_loaded()) |
| 36 return; | 33 return; |
| 37 | 34 |
| 38 const CellularNetworkVector& networks = library->cellular_networks(); | 35 const CellularNetworkVector& networks = library->cellular_networks(); |
| 39 // Remove monitors for networks that are not in the list anymore. | 36 // Remove monitors for networks that are not in the list anymore. |
| 40 for (ObserversMap::iterator it_observer = observers_.begin(); | 37 for (ObserversMap::iterator it_observer = observers_.begin(); |
| 41 it_observer != observers_.end();) { | 38 it_observer != observers_.end();) { |
| 42 bool found = false; | 39 bool found = false; |
| 43 for (CellularNetworkVector::const_iterator it_network = networks.begin(); | 40 for (CellularNetworkVector::const_iterator it_network = networks.begin(); |
| 44 it_network != networks.end(); ++it_network) { | 41 it_network != networks.end(); ++it_network) { |
| 45 if (it_observer->first == (*it_network)->device_path()) { | 42 if (it_observer->first == (*it_network)->device_path()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 chromeos::SMSMonitor monitor = | 68 chromeos::SMSMonitor monitor = |
| 72 chromeos::MonitorSMS(device_path.c_str(), &StaticCallback, this); | 69 chromeos::MonitorSMS(device_path.c_str(), &StaticCallback, this); |
| 73 observers_.insert(ObserversMap::value_type(device_path, monitor)); | 70 observers_.insert(ObserversMap::value_type(device_path, monitor)); |
| 74 } else { | 71 } else { |
| 75 VLOG(1) << "Already has SMS monitor for " << device_path; | 72 VLOG(1) << "Already has SMS monitor for " << device_path; |
| 76 } | 73 } |
| 77 } | 74 } |
| 78 } | 75 } |
| 79 | 76 |
| 80 void SmsObserver::DisconnectAll() { | 77 void SmsObserver::DisconnectAll() { |
| 81 if (!CrosLibrary::Get()->EnsureLoaded() || | 78 // Guard against calls to libcros (http://crosbug.com/17863). |
| 82 !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) | 79 if (!CrosLibrary::Get()->libcros_loaded()) |
| 83 return; | 80 return; |
| 84 | 81 |
| 85 for (ObserversMap::iterator it = observers_.begin(); | 82 for (ObserversMap::iterator it = observers_.begin(); |
| 86 it != observers_.end(); ++it) { | 83 it != observers_.end(); ++it) { |
| 87 VLOG(1) << "Remove SMS monitor for " << it->first; | 84 VLOG(1) << "Remove SMS monitor for " << it->first; |
| 88 chromeos::DisconnectSMSMonitor(it->second); | 85 chromeos::DisconnectSMSMonitor(it->second); |
| 89 } | 86 } |
| 90 observers_.clear(); | 87 observers_.clear(); |
| 91 } | 88 } |
| 92 | 89 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 111 profile_, | 108 profile_, |
| 112 "incoming _sms.chromeos", | 109 "incoming _sms.chromeos", |
| 113 IDR_NOTIFICATION_SMS, | 110 IDR_NOTIFICATION_SMS, |
| 114 l10n_util::GetStringFUTF16( | 111 l10n_util::GetStringFUTF16( |
| 115 IDS_SMS_NOTIFICATION_TITLE, UTF8ToUTF16(message->number))); | 112 IDS_SMS_NOTIFICATION_TITLE, UTF8ToUTF16(message->number))); |
| 116 | 113 |
| 117 note.Show(UTF8ToUTF16(message->text), true, false); | 114 note.Show(UTF8ToUTF16(message->text), true, false); |
| 118 } | 115 } |
| 119 | 116 |
| 120 } // namespace chromeos | 117 } // namespace chromeos |
| OLD | NEW |