OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_state_notifier.h" | 5 #include "chrome/browser/chromeos/network_state_notifier.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // TODO(oshima): make this instance method so that | 27 // TODO(oshima): make this instance method so that |
28 // we can mock this for ui_tests. | 28 // we can mock this for ui_tests. |
29 // http://crbug.com/4825 . | 29 // http://crbug.com/4825 . |
30 return base::Time::Now() - Get()->offline_start_time_; | 30 return base::Time::Now() - Get()->offline_start_time_; |
31 } | 31 } |
32 | 32 |
33 NetworkStateNotifier::NetworkStateNotifier() | 33 NetworkStateNotifier::NetworkStateNotifier() |
34 : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 34 : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
35 state_(RetrieveState()), | 35 state_(RetrieveState()), |
36 offline_start_time_(Time::Now()) { | 36 offline_start_time_(Time::Now()) { |
| 37 DCHECK(CrosLibrary::Get()->EnsureLoaded()); |
| 38 // Note that this gets added as a NetworkManagerObserver |
| 39 // in browser_init.cc |
37 } | 40 } |
38 | 41 |
39 void NetworkStateNotifier::NetworkChanged(NetworkLibrary* cros) { | 42 NetworkStateNotifier::~NetworkStateNotifier() { |
| 43 DCHECK(CrosLibrary::Get()->EnsureLoaded()); |
| 44 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); |
| 45 } |
| 46 |
| 47 void NetworkStateNotifier::OnNetworkManagerChanged(NetworkLibrary* cros) { |
40 DCHECK(CrosLibrary::Get()->EnsureLoaded()); | 48 DCHECK(CrosLibrary::Get()->EnsureLoaded()); |
41 BrowserThread::PostTask( | 49 BrowserThread::PostTask( |
42 BrowserThread::UI, FROM_HERE, | 50 BrowserThread::UI, FROM_HERE, |
43 task_factory_.NewRunnableMethod( | 51 task_factory_.NewRunnableMethod( |
44 &NetworkStateNotifier::UpdateNetworkState, | 52 &NetworkStateNotifier::UpdateNetworkState, |
45 RetrieveState())); | 53 RetrieveState())); |
46 } | 54 } |
47 | 55 |
48 void NetworkStateNotifier::UpdateNetworkState( | 56 void NetworkStateNotifier::UpdateNetworkState( |
49 NetworkStateDetails::State new_state) { | 57 NetworkStateDetails::State new_state) { |
(...skipping 21 matching lines...) Expand all Loading... |
71 return NetworkStateDetails::CONNECTED; | 79 return NetworkStateDetails::CONNECTED; |
72 } else if (cros->Connecting()) { | 80 } else if (cros->Connecting()) { |
73 return NetworkStateDetails::CONNECTING; | 81 return NetworkStateDetails::CONNECTING; |
74 } else { | 82 } else { |
75 return NetworkStateDetails::DISCONNECTED; | 83 return NetworkStateDetails::DISCONNECTED; |
76 } | 84 } |
77 } | 85 } |
78 | 86 |
79 | 87 |
80 } // namespace chromeos | 88 } // namespace chromeos |
OLD | NEW |