OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 #ifndef CHROME_BROWSER_CHROMEOS_CROS_BURN_LIBRARY_H_ |
| 7 #define CHROME_BROWSER_CHROMEOS_CROS_BURN_LIBRARY_H_ |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/file_path.h" |
| 13 #include "base/weak_ptr.h" |
| 14 #include "base/observer_list.h" |
| 15 |
| 16 #include "third_party/cros/chromeos_imageburn.h" |
| 17 |
| 18 struct ImageBurnStatus { |
| 19 explicit ImageBurnStatus(const chromeos::BurnStatus& status) |
| 20 : amount_burnt(status.amount_burnt), |
| 21 total_size(status.total_size) { |
| 22 if (status.target_path) |
| 23 target_path = status.target_path; |
| 24 if (status.error) |
| 25 error = status.error; |
| 26 } |
| 27 std::string target_path; |
| 28 int64 amount_burnt; |
| 29 int64 total_size; |
| 30 std::string error; |
| 31 }; |
| 32 |
| 33 namespace chromeos { |
| 34 class BurnLibrary { |
| 35 public: |
| 36 class Observer { |
| 37 public: |
| 38 virtual void ProgressUpdated(BurnLibrary* object, BurnEventType evt, |
| 39 const ImageBurnStatus& status) = 0; |
| 40 }; |
| 41 |
| 42 virtual ~BurnLibrary() {} |
| 43 |
| 44 virtual void AddObserver(Observer* observer) = 0; |
| 45 virtual void RemoveObserver(Observer* observer) = 0; |
| 46 virtual bool DoBurn(const FilePath& from_path, const FilePath& to_path) = 0; |
| 47 |
| 48 // Factory function, creates a new instance and returns ownership. |
| 49 // For normal usage, access the singleton via CrosLibrary::Get(). |
| 50 static BurnLibrary* GetImpl(bool stub); |
| 51 }; |
| 52 |
| 53 class BurnLibraryImpl : public BurnLibrary, |
| 54 public base::SupportsWeakPtr<BurnLibraryImpl> { |
| 55 public: |
| 56 |
| 57 BurnLibraryImpl(); |
| 58 virtual ~BurnLibraryImpl(); |
| 59 |
| 60 // BurnLibrary implementation. |
| 61 virtual void AddObserver(Observer* observer); |
| 62 virtual void RemoveObserver(Observer* observer); |
| 63 virtual bool DoBurn(const FilePath& from_path, const FilePath& to_path); |
| 64 |
| 65 bool BurnImage(const FilePath& from_path, const FilePath& to_path); |
| 66 void UpdateBurnStatus(const ImageBurnStatus& status, BurnEventType evt); |
| 67 |
| 68 private: |
| 69 void Init(); |
| 70 static void BurnStatusChangedHandler(void* object, |
| 71 const BurnStatus& status, |
| 72 BurnEventType evt); |
| 73 |
| 74 private: |
| 75 ObserverList<BurnLibrary::Observer> observers_; |
| 76 BurnStatusConnection burn_status_connection_; |
| 77 |
| 78 // Holds a path that is currently being burnt to. |
| 79 std::string target_path_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(BurnLibraryImpl); |
| 82 }; |
| 83 |
| 84 class BurnLibraryTaskProxy |
| 85 : public base::RefCountedThreadSafe<BurnLibraryTaskProxy> { |
| 86 public: |
| 87 explicit BurnLibraryTaskProxy(const base::WeakPtr<BurnLibraryImpl>& library); |
| 88 |
| 89 void BurnImage(const FilePath& from_path, const FilePath& to_path); |
| 90 |
| 91 void UpdateBurnStatus(ImageBurnStatus* status, BurnEventType evt); |
| 92 |
| 93 private: |
| 94 base::WeakPtr<BurnLibraryImpl> library_; |
| 95 |
| 96 friend class base::RefCountedThreadSafe<BurnLibraryTaskProxy>; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(BurnLibraryTaskProxy); |
| 99 }; |
| 100 |
| 101 } // namespace chromeos |
| 102 |
| 103 #endif // CHROME_BROWSER_CHROMEOS_CROS_BURN_LIBRARY_H_ |
OLD | NEW |