| OLD | NEW |
| 1 // Copyright (c) 2011 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/ui/webui/chromeos/imageburner/imageburner_utils.h" | 5 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_utils.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 void BurnManager::OnConfigFileDownloadedOnFileThread() { | 253 void BurnManager::OnConfigFileDownloadedOnFileThread() { |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 255 std::string config_file_content; | 255 std::string config_file_content; |
| 256 bool success = | 256 bool success = |
| 257 file_util::ReadFileToString(config_file_path_, &config_file_content); | 257 file_util::ReadFileToString(config_file_path_, &config_file_content); |
| 258 scoped_refptr<BurnManagerTaskProxy> task = new BurnManagerTaskProxy(); | 258 scoped_refptr<BurnManagerTaskProxy> task = new BurnManagerTaskProxy(); |
| 259 BrowserThread::PostTask( | 259 BrowserThread::PostTask( |
| 260 BrowserThread::UI, FROM_HERE, | 260 BrowserThread::UI, FROM_HERE, |
| 261 NewRunnableMethod(task.get(), | 261 base::Bind(&BurnManagerTaskProxy::ConfigFileFetched, task.get(), success, |
| 262 &BurnManagerTaskProxy::ConfigFileFetched, success, | 262 config_file_content)); |
| 263 config_file_content)); | |
| 264 } | 263 } |
| 265 | 264 |
| 266 void BurnManager::ModelChanged() { | 265 void BurnManager::ModelChanged() { |
| 267 std::vector<DownloadItem*> downloads; | 266 std::vector<DownloadItem*> downloads; |
| 268 download_manager_->GetTemporaryDownloads(GetImageDir(), &downloads); | 267 download_manager_->GetTemporaryDownloads(GetImageDir(), &downloads); |
| 269 if (download_item_observer_added_) | 268 if (download_item_observer_added_) |
| 270 return; | 269 return; |
| 271 for (std::vector<DownloadItem*>::const_iterator it = downloads.begin(); | 270 for (std::vector<DownloadItem*>::const_iterator it = downloads.begin(); |
| 272 it != downloads.end(); | 271 it != downloads.end(); |
| 273 ++it) { | 272 ++it) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 395 |
| 397 Downloader::~Downloader() {} | 396 Downloader::~Downloader() {} |
| 398 | 397 |
| 399 void Downloader::DownloadFile(const GURL& url, | 398 void Downloader::DownloadFile(const GURL& url, |
| 400 const FilePath& file_path, TabContents* tab_contents) { | 399 const FilePath& file_path, TabContents* tab_contents) { |
| 401 // First we have to create file stream we will download file to. | 400 // First we have to create file stream we will download file to. |
| 402 // That has to be done on File thread. | 401 // That has to be done on File thread. |
| 403 scoped_refptr<DownloaderTaskProxy> task = new DownloaderTaskProxy(); | 402 scoped_refptr<DownloaderTaskProxy> task = new DownloaderTaskProxy(); |
| 404 BrowserThread::PostTask( | 403 BrowserThread::PostTask( |
| 405 BrowserThread::FILE, FROM_HERE, | 404 BrowserThread::FILE, FROM_HERE, |
| 406 NewRunnableMethod(task.get(), | 405 base::Bind(&DownloaderTaskProxy::CreateFileStream, task.get(), url, |
| 407 &DownloaderTaskProxy::CreateFileStream, url, file_path, | 406 file_path, tab_contents)); |
| 408 tab_contents)); | |
| 409 } | 407 } |
| 410 | 408 |
| 411 void Downloader::CreateFileStreamOnFileThread( | 409 void Downloader::CreateFileStreamOnFileThread( |
| 412 const GURL& url, const FilePath& file_path, | 410 const GURL& url, const FilePath& file_path, |
| 413 TabContents* tab_contents) { | 411 TabContents* tab_contents) { |
| 414 | 412 |
| 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 416 DCHECK(!file_path.empty()); | 414 DCHECK(!file_path.empty()); |
| 417 | 415 |
| 418 scoped_ptr<net::FileStream> file_stream(new net::FileStream); | 416 scoped_ptr<net::FileStream> file_stream(new net::FileStream); |
| 419 // TODO(tbarzic): Save temp image file to temp folder instead of Downloads | 417 // TODO(tbarzic): Save temp image file to temp folder instead of Downloads |
| 420 // once extracting image directly to removalbe device is implemented | 418 // once extracting image directly to removalbe device is implemented |
| 421 if (file_stream->Open(file_path, base::PLATFORM_FILE_OPEN_ALWAYS | | 419 if (file_stream->Open(file_path, base::PLATFORM_FILE_OPEN_ALWAYS | |
| 422 base::PLATFORM_FILE_WRITE)) | 420 base::PLATFORM_FILE_WRITE)) |
| 423 file_stream.reset(NULL); | 421 file_stream.reset(NULL); |
| 424 | 422 |
| 425 scoped_refptr<DownloaderTaskProxy> task = new DownloaderTaskProxy(); | 423 scoped_refptr<DownloaderTaskProxy> task = new DownloaderTaskProxy(); |
| 426 // Call callback method on UI thread. | 424 // Call callback method on UI thread. |
| 427 BrowserThread::PostTask( | 425 BrowserThread::PostTask( |
| 428 BrowserThread::UI, FROM_HERE, | 426 BrowserThread::UI, FROM_HERE, |
| 429 NewRunnableMethod(task.get(), | 427 base::Bind(&DownloaderTaskProxy::OnFileStreamCreated, task.get(), |
| 430 &DownloaderTaskProxy::OnFileStreamCreated, | 428 url, file_path, tab_contents, file_stream.release())); |
| 431 url, file_path, tab_contents, file_stream.release())); | |
| 432 } | 429 } |
| 433 | 430 |
| 434 void Downloader::OnFileStreamCreatedOnUIThread(const GURL& url, | 431 void Downloader::OnFileStreamCreatedOnUIThread(const GURL& url, |
| 435 const FilePath& file_path, TabContents* tab_contents, | 432 const FilePath& file_path, TabContents* tab_contents, |
| 436 net::FileStream* created_file_stream) { | 433 net::FileStream* created_file_stream) { |
| 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 438 | 435 |
| 439 if (created_file_stream) { | 436 if (created_file_stream) { |
| 440 DownloadManager* download_manager = | 437 DownloadManager* download_manager = |
| 441 tab_contents->GetBrowserContext()->GetDownloadManager(); | 438 tab_contents->GetBrowserContext()->GetDownloadManager(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 464 current_listener != listener_range.second; | 461 current_listener != listener_range.second; |
| 465 ++current_listener) { | 462 ++current_listener) { |
| 466 if (current_listener->second) | 463 if (current_listener->second) |
| 467 current_listener->second->OnBurnDownloadStarted(success); | 464 current_listener->second->OnBurnDownloadStarted(success); |
| 468 } | 465 } |
| 469 listeners_.erase(listener_range.first, listener_range.second); | 466 listeners_.erase(listener_range.first, listener_range.second); |
| 470 } | 467 } |
| 471 | 468 |
| 472 } // namespace imageburner. | 469 } // namespace imageburner. |
| 473 | 470 |
| OLD | NEW |