| 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 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_STATE_NOTIFIER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_STATE_NOTIFIER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_NETWORK_STATE_NOTIFIER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NETWORK_STATE_NOTIFIER_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/chromeos/cros/network_library.h" | 8 #include "chrome/browser/chromeos/cros/network_library.h" |
| 9 | 9 |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "base/time.h" |
| 12 | 13 |
| 13 namespace chromeos { | 14 namespace chromeos { |
| 14 | 15 |
| 15 // NetworkStateDetails contains the information about | 16 // NetworkStateDetails contains the information about |
| 16 // network status. | 17 // network status. |
| 17 class NetworkStateDetails { | 18 class NetworkStateDetails { |
| 18 public: | 19 public: |
| 19 enum State { | 20 enum State { |
| 20 UNKNOWN = 0, | 21 UNKNOWN = 0, |
| 21 DISCONNECTED, | 22 DISCONNECTED, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 | 42 |
| 42 // NetworkStateNotifier sends notification when network state has | 43 // NetworkStateNotifier sends notification when network state has |
| 43 // chagned. Notificatio is sent in UI thread. | 44 // chagned. Notificatio is sent in UI thread. |
| 44 // TODO(oshima): port this to other platform. merge with | 45 // TODO(oshima): port this to other platform. merge with |
| 45 // NetworkChangeNotifier if possible. | 46 // NetworkChangeNotifier if possible. |
| 46 class NetworkStateNotifier : public NetworkLibrary::Observer { | 47 class NetworkStateNotifier : public NetworkLibrary::Observer { |
| 47 public: | 48 public: |
| 48 // Returns the singleton instance of the network state notifier; | 49 // Returns the singleton instance of the network state notifier; |
| 49 static NetworkStateNotifier* Get(); | 50 static NetworkStateNotifier* Get(); |
| 50 | 51 |
| 51 // NetworkLibrary::Observer implementation. | 52 // The duration of being in offline. The value is undefined when |
| 52 virtual void NetworkChanged(NetworkLibrary* cros); | 53 // when network is connected. |
| 53 virtual void NetworkTraffic(NetworkLibrary* cros, int traffic_type) {} | 54 static base::TimeDelta GetOfflineDuration(); |
| 54 | 55 |
| 55 // Returns true if the network is connected. | 56 // Returns true if the network is connected. |
| 56 static bool is_connected() { | 57 static bool is_connected() { |
| 57 return Get()->state_ == NetworkStateDetails::CONNECTED; | 58 return Get()->state_ == NetworkStateDetails::CONNECTED; |
| 58 } | 59 } |
| 59 | 60 |
| 61 // NetworkLibrary::Observer implementation. |
| 62 virtual void NetworkChanged(NetworkLibrary* cros); |
| 63 virtual void NetworkTraffic(NetworkLibrary* cros, int traffic_type) {} |
| 64 |
| 60 private: | 65 private: |
| 61 friend struct DefaultSingletonTraits<NetworkStateNotifier>; | 66 friend struct DefaultSingletonTraits<NetworkStateNotifier>; |
| 62 | 67 |
| 63 // Retrieve the current state from libcros. | 68 // Retrieve the current state from libcros. |
| 64 static NetworkStateDetails::State RetrieveState(); | 69 static NetworkStateDetails::State RetrieveState(); |
| 65 | 70 |
| 66 NetworkStateNotifier(); | 71 NetworkStateNotifier(); |
| 67 virtual ~NetworkStateNotifier() {} | 72 virtual ~NetworkStateNotifier() {} |
| 68 | 73 |
| 69 // Update the current state and sends notification to observers. | 74 // Update the current state and sends notification to observers. |
| 70 // This should be invoked in UI thread. | 75 // This should be invoked in UI thread. |
| 71 void UpdateNetworkState(NetworkStateDetails::State new_state); | 76 void UpdateNetworkState(NetworkStateDetails::State new_state); |
| 72 | 77 |
| 78 // A factory to post a task in UI thread. |
| 79 ScopedRunnableMethodFactory<NetworkStateNotifier> task_factory_; |
| 80 |
| 73 // The current network state. | 81 // The current network state. |
| 74 NetworkStateDetails::State state_; | 82 NetworkStateDetails::State state_; |
| 75 | 83 |
| 76 ScopedRunnableMethodFactory<NetworkStateNotifier> task_factory_; | 84 // The start time of offline. |
| 85 base::Time offline_start_time_; |
| 77 | 86 |
| 78 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); | 87 DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); |
| 79 }; | 88 }; |
| 80 | 89 |
| 81 } // chromeos | 90 } // namespace chromeos |
| 82 | 91 |
| 83 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_STATE_NOTIFIER_H_ | 92 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_STATE_NOTIFIER_H_ |
| OLD | NEW |