Home | History | Annotate | Download | only in login
      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 #include "chrome/browser/chromeos/login/image_decoder.h"
      6 
      7 #include "chrome/browser/browser_process.h"
      8 #include "content/browser/browser_thread.h"
      9 
     10 namespace chromeos {
     11 
     12 ImageDecoder::ImageDecoder(Delegate* delegate,
     13                            const std::string& image_data)
     14     : delegate_(delegate),
     15       image_data_(image_data.begin(), image_data.end()),
     16       target_thread_id_(BrowserThread::UI) {
     17 }
     18 
     19 void ImageDecoder::Start() {
     20   if (!BrowserThread::GetCurrentThreadIdentifier(&target_thread_id_)) {
     21     NOTREACHED();
     22     return;
     23   }
     24   BrowserThread::PostTask(
     25      BrowserThread::IO, FROM_HERE,
     26      NewRunnableMethod(
     27          this, &ImageDecoder::DecodeImageInSandbox,
     28          image_data_));
     29 }
     30 
     31 void ImageDecoder::OnDecodeImageSucceeded(const SkBitmap& decoded_image) {
     32   DCHECK(BrowserThread::CurrentlyOn(target_thread_id_));
     33   if (delegate_)
     34     delegate_->OnImageDecoded(this, decoded_image);
     35 }
     36 
     37 void ImageDecoder::OnDecodeImageFailed() {
     38   DCHECK(BrowserThread::CurrentlyOn(target_thread_id_));
     39   if (delegate_)
     40     delegate_->OnDecodeImageFailed(this);
     41 }
     42 
     43 void ImageDecoder::DecodeImageInSandbox(
     44     const std::vector<unsigned char>& image_data) {
     45   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
     46   UtilityProcessHost* utility_process_host =
     47       new UtilityProcessHost(this,
     48                              target_thread_id_);
     49   utility_process_host->StartImageDecoding(image_data);
     50 }
     51 
     52 }  // namespace chromeos
     53