OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/cros/burn_library.h" | 5 #include "chrome/browser/chromeos/cros/burn_library.h" |
6 | 6 |
| 7 #include <cstring> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/observer_list.h" | 10 #include "base/memory/linked_ptr.h" |
9 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 11 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
10 #include "chrome/browser/chromeos/dbus/image_burner_client.h" | 12 #include "chrome/browser/chromeos/dbus/image_burner_client.h" |
11 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | 13 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
12 #include "chrome/common/zip.h" | 14 #include "chrome/common/zip.h" |
13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
14 | 16 |
15 using content::BrowserThread; | 17 using content::BrowserThread; |
16 | 18 |
17 namespace chromeos { | 19 namespace chromeos { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Unzips |source_zip_file| and calls |callback| with the filename of | |
22 // the unzipped image. | |
23 void UnzipImage( | 23 void UnzipImage( |
24 const FilePath& source_zip_file, | 24 const FilePath& source_zip_file, |
25 const std::string& image_name, | 25 const std::string& image_name, |
26 base::Callback<void(const std::string& source_image_file)> callback) { | 26 base::Callback<void(const std::string& source_image_file)> callback) { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
28 | 28 |
29 std::string source_image_file; | 29 std::string source_image_file; |
30 if (zip::Unzip(source_zip_file, source_zip_file.DirName())) { | 30 if (zip::Unzip(source_zip_file, source_zip_file.DirName())) { |
31 source_image_file = | 31 source_image_file = |
32 source_zip_file.DirName().Append(image_name).value(); | 32 source_zip_file.DirName().Append(image_name).value(); |
33 } | 33 } |
34 BrowserThread::PostTask( | 34 BrowserThread::PostTask( |
35 BrowserThread::UI, FROM_HERE, base::Bind(callback, source_image_file)); | 35 BrowserThread::UI, FROM_HERE, base::Bind(callback, source_image_file)); |
36 } | 36 } |
37 | 37 |
| 38 } // namespace |
| 39 |
38 class BurnLibraryImpl : public BurnLibrary { | 40 class BurnLibraryImpl : public BurnLibrary { |
39 public: | 41 public: |
40 BurnLibraryImpl(); | 42 BurnLibraryImpl(); |
41 virtual ~BurnLibraryImpl(); | 43 virtual ~BurnLibraryImpl(); |
42 | 44 |
43 // BurnLibrary implementation. | 45 // BurnLibrary implementation. |
44 virtual void AddObserver(Observer* observer) OVERRIDE; | 46 virtual void AddObserver(Observer* observer) OVERRIDE; |
45 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 47 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
46 virtual void DoBurn(const FilePath& source_path, | 48 virtual void DoBurn(const FilePath& source_path, |
47 const std::string& image_name, | 49 const std::string& image_name, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 BurnLibraryImpl* self = static_cast<BurnLibraryImpl*>(object); | 195 BurnLibraryImpl* self = static_cast<BurnLibraryImpl*>(object); |
194 if (success) { | 196 if (success) { |
195 self->BurnImage(); | 197 self->BurnImage(); |
196 } else { | 198 } else { |
197 self->UpdateBurnStatus(ImageBurnStatus(0, 0), BURN_FAIL); | 199 self->UpdateBurnStatus(ImageBurnStatus(0, 0), BURN_FAIL); |
198 } | 200 } |
199 } | 201 } |
200 | 202 |
201 void BurnLibraryImpl::BurnImage() { | 203 void BurnLibraryImpl::BurnImage() { |
202 DBusThreadManager::Get()->GetImageBurnerClient()->BurnImage( | 204 DBusThreadManager::Get()->GetImageBurnerClient()->BurnImage( |
203 source_image_file_, | 205 source_image_file_.c_str(), |
204 target_file_path_, | 206 target_file_path_.c_str(), |
205 base::Bind(&BurnLibraryImpl::OnBurnImageFail, | 207 base::Bind(&BurnLibraryImpl::OnBurnImageFail, |
206 weak_ptr_factory_.GetWeakPtr())); | 208 weak_ptr_factory_.GetWeakPtr())); |
207 } | 209 } |
208 | 210 |
209 void BurnLibraryImpl::UpdateBurnStatus(const ImageBurnStatus& status, | 211 void BurnLibraryImpl::UpdateBurnStatus(const ImageBurnStatus& status, |
210 BurnEvent evt) { | 212 BurnEvent evt) { |
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
212 | 214 |
213 if (cancelled_) | 215 if (cancelled_) |
214 return; | 216 return; |
(...skipping 25 matching lines...) Expand all Loading... |
240 virtual void DoBurn(const FilePath& source_path, | 242 virtual void DoBurn(const FilePath& source_path, |
241 const std::string& image_name, | 243 const std::string& image_name, |
242 const FilePath& target_file_path, | 244 const FilePath& target_file_path, |
243 const FilePath& target_device_path) OVERRIDE { | 245 const FilePath& target_device_path) OVERRIDE { |
244 } | 246 } |
245 virtual void CancelBurnImage() OVERRIDE {} | 247 virtual void CancelBurnImage() OVERRIDE {} |
246 | 248 |
247 DISALLOW_COPY_AND_ASSIGN(BurnLibraryStubImpl); | 249 DISALLOW_COPY_AND_ASSIGN(BurnLibraryStubImpl); |
248 }; | 250 }; |
249 | 251 |
250 } // namespace | |
251 | |
252 // static | 252 // static |
253 BurnLibrary* BurnLibrary::GetImpl(bool stub) { | 253 BurnLibrary* BurnLibrary::GetImpl(bool stub) { |
254 BurnLibrary* impl; | 254 BurnLibrary* impl; |
255 if (stub) | 255 if (stub) |
256 impl = new BurnLibraryStubImpl(); | 256 impl = new BurnLibraryStubImpl(); |
257 else | 257 else |
258 impl = new BurnLibraryImpl(); | 258 impl = new BurnLibraryImpl(); |
259 impl->Init(); | 259 impl->Init(); |
260 return impl; | 260 return impl; |
261 } | 261 } |
262 | 262 |
263 } // namespace chromeos | 263 } // namespace chromeos |
OLD | NEW |