Home | History | Annotate | Download | only in chromeos
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_MESSAGE_OBSERVER_H_
      6 #define CHROME_BROWSER_CHROMEOS_NETWORK_MESSAGE_OBSERVER_H_
      7 #pragma once
      8 
      9 #include <map>
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "chrome/browser/chromeos/cros/network_library.h"
     14 #include "chrome/browser/chromeos/notifications/system_notification.h"
     15 
     16 class Profile;
     17 
     18 namespace chromeos {
     19 
     20 // The network message observer displays a system notification for network
     21 // messages.
     22 
     23 class NetworkMessageObserver : public NetworkLibrary::NetworkManagerObserver,
     24                                public NetworkLibrary::CellularDataPlanObserver,
     25                                public NetworkLibrary::UserActionObserver {
     26  public:
     27   explicit NetworkMessageObserver(Profile* profile);
     28   virtual ~NetworkMessageObserver();
     29 
     30   static bool IsApplicableBackupPlan(const CellularDataPlan* plan,
     31                                      const CellularDataPlan* other_plan);
     32  private:
     33   virtual void OpenMobileSetupPage(const ListValue* args);
     34   virtual void OpenMoreInfoPage(const ListValue* args);
     35   virtual void InitNewPlan(const CellularDataPlan* plan);
     36   virtual void ShowNeedsPlanNotification(const CellularNetwork* cellular);
     37   virtual void ShowNoDataNotification(CellularDataPlanType plan_type);
     38   virtual void ShowLowDataNotification(const CellularDataPlan* plan);
     39   virtual bool CheckNetworkFailed(const Network* network);
     40 
     41   // NetworkLibrary::NetworkManagerObserver implementation.
     42   virtual void OnNetworkManagerChanged(NetworkLibrary* obj);
     43   // NetworkLibrary::CellularDataPlanObserver implementation.
     44   virtual void OnCellularDataPlanChanged(NetworkLibrary* obj);
     45   // NetworkLibrary::UserActionObserver implementation.
     46   virtual void OnConnectionInitiated(NetworkLibrary* obj,
     47                                      const Network* network);
     48 
     49   // Saves the current cellular and plan information.
     50   // |plan| can be NULL. In that case, we set it to unknown.
     51   void SaveLastCellularInfo(const CellularNetwork* cellular,
     52                             const CellularDataPlan* plan);
     53 
     54   typedef std::map<std::string, ConnectionState> NetworkStateMap;
     55 
     56   // Network state by service path.
     57   NetworkStateMap network_states_;
     58 
     59   // Current connect celluar service path.
     60   std::string cellular_service_path_;
     61   // Last cellular data plan unique id.
     62   std::string cellular_data_plan_unique_id_;
     63   // Last cellular data plan type.
     64   CellularDataPlanType cellular_data_plan_type_;
     65   // Last cellular data left.
     66   CellularNetwork::DataLeft cellular_data_left_;
     67 
     68   // Notification for connection errors
     69   SystemNotification notification_connection_error_;
     70   // Notification for showing low data warning
     71   SystemNotification notification_low_data_;
     72   // Notification for showing no data warning
     73   SystemNotification notification_no_data_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(NetworkMessageObserver);
     76 };
     77 
     78 }  // namespace chromeos
     79 
     80 #endif  // CHROME_BROWSER_CHROMEOS_NETWORK_MESSAGE_OBSERVER_H_
     81