OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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_CROS_UPDATE_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_UPDATE_LIBRARY_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/observer_list.h" |
| 11 #include "base/singleton.h" |
| 12 #include "base/time.h" |
| 13 #include "third_party/cros/chromeos_update_engine.h" |
| 14 |
| 15 namespace chromeos { |
| 16 |
| 17 // This interface defines interaction with the ChromeOS update library APIs. |
| 18 // Classes can add themselves as observers. Users can get an instance of this |
| 19 // library class like this: chromeos::CrosLibrary::Get()->GetUpdateLibrary() |
| 20 |
| 21 class UpdateLibrary { |
| 22 public: |
| 23 // TODO(seanparent): Should make the UpdateProgress type copyable. |
| 24 // We need to copy it to bind it for a deferred notification. |
| 25 // Modifying the cros library just for that, for a single use case, |
| 26 // isn't worth it. Instead we define this a local Status struct that |
| 27 // is copyable. |
| 28 |
| 29 struct Status { |
| 30 Status() |
| 31 : status(UPDATE_STATUS_IDLE), |
| 32 download_progress(0.0), |
| 33 last_checked_time(0), |
| 34 new_size(0) { |
| 35 } |
| 36 |
| 37 explicit Status(const UpdateProgress& x) : |
| 38 status(x.status_), |
| 39 download_progress(x.download_progress_), |
| 40 last_checked_time(x.last_checked_time_), |
| 41 new_version(x.new_version_), |
| 42 new_size(x.new_size_) { |
| 43 } |
| 44 |
| 45 UpdateStatusOperation status; |
| 46 double download_progress; // 0.0 - 1.0 |
| 47 int64_t last_checked_time; // As reported by std::time(). |
| 48 std::string new_version; |
| 49 int64_t new_size; // Valid during DOWNLOADING, in bytes. |
| 50 }; |
| 51 |
| 52 class Observer { |
| 53 public: |
| 54 virtual ~Observer() { } |
| 55 virtual void Changed(UpdateLibrary* obj) = 0; |
| 56 }; |
| 57 |
| 58 virtual ~UpdateLibrary() {} |
| 59 virtual void AddObserver(Observer* observer) = 0; |
| 60 virtual void RemoveObserver(Observer* observer) = 0; |
| 61 |
| 62 virtual const Status& status() const = 0; |
| 63 }; |
| 64 |
| 65 class UpdateLibraryImpl : public UpdateLibrary { |
| 66 public: |
| 67 UpdateLibraryImpl(); |
| 68 virtual ~UpdateLibraryImpl(); |
| 69 |
| 70 // UpdateLibrary overrides. |
| 71 virtual void AddObserver(Observer* observer); |
| 72 virtual void RemoveObserver(Observer* observer); |
| 73 |
| 74 virtual const Status& status() const; |
| 75 |
| 76 private: |
| 77 |
| 78 // This method is called when there's a change in status. |
| 79 // This method is called on a background thread. |
| 80 static void ChangedHandler(void* object, const UpdateProgress& status); |
| 81 |
| 82 // This methods starts the monitoring of power changes. |
| 83 void Init(); |
| 84 |
| 85 // Called by the handler to update the power status. |
| 86 // This will notify all the Observers. |
| 87 void UpdateStatus(const Status& status); |
| 88 |
| 89 ObserverList<Observer> observers_; |
| 90 |
| 91 // A reference to the update api, to allow callbacks when the update |
| 92 // status changes. |
| 93 UpdateStatusConnection status_connection_; |
| 94 |
| 95 // The latest power status. |
| 96 Status status_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(UpdateLibraryImpl); |
| 99 }; |
| 100 |
| 101 } // namespace chromeos |
| 102 |
| 103 #endif // CHROME_BROWSER_CHROMEOS_CROS_UPDATE_LIBRARY_H_ |
| 104 |
OLD | NEW |