| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/apps/drive/drive_app_converter.h" | 5 #include "chrome/browser/apps/drive/drive_app_converter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class DriveAppConverter::IconFetcher : public net::URLFetcherDelegate, | 34 class DriveAppConverter::IconFetcher : public net::URLFetcherDelegate, |
| 35 public ImageDecoder::Delegate { | 35 public ImageDecoder::Delegate { |
| 36 public: | 36 public: |
| 37 IconFetcher(DriveAppConverter* converter, | 37 IconFetcher(DriveAppConverter* converter, |
| 38 const GURL& icon_url, | 38 const GURL& icon_url, |
| 39 int expected_size) | 39 int expected_size) |
| 40 : converter_(converter), | 40 : converter_(converter), |
| 41 icon_url_(icon_url), | 41 icon_url_(icon_url), |
| 42 expected_size_(expected_size) {} | 42 expected_size_(expected_size) {} |
| 43 ~IconFetcher() override { | 43 ~IconFetcher() override { |
| 44 if (image_decoder_.get()) | |
| 45 image_decoder_->set_delegate(NULL); | |
| 46 } | 44 } |
| 47 | 45 |
| 48 void Start() { | 46 void Start() { |
| 49 fetcher_.reset( | 47 fetcher_.reset( |
| 50 net::URLFetcher::Create(icon_url_, net::URLFetcher::GET, this)); | 48 net::URLFetcher::Create(icon_url_, net::URLFetcher::GET, this)); |
| 51 fetcher_->SetRequestContext(converter_->profile_->GetRequestContext()); | 49 fetcher_->SetRequestContext(converter_->profile_->GetRequestContext()); |
| 52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 50 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 53 fetcher_->Start(); | 51 fetcher_->Start(); |
| 54 } | 52 } |
| 55 | 53 |
| 56 const GURL& icon_url() const { return icon_url_; } | 54 const GURL& icon_url() const { return icon_url_; } |
| 57 const SkBitmap& icon() const { return icon_; } | 55 const SkBitmap& icon() const { return icon_; } |
| 58 | 56 |
| 59 private: | 57 private: |
| 60 // net::URLFetcherDelegate overrides: | 58 // net::URLFetcherDelegate overrides: |
| 61 void OnURLFetchComplete(const net::URLFetcher* source) override { | 59 void OnURLFetchComplete(const net::URLFetcher* source) override { |
| 62 CHECK_EQ(fetcher_.get(), source); | 60 CHECK_EQ(fetcher_.get(), source); |
| 63 scoped_ptr<net::URLFetcher> fetcher(fetcher_.Pass()); | 61 scoped_ptr<net::URLFetcher> fetcher(fetcher_.Pass()); |
| 64 | 62 |
| 65 if (!fetcher->GetStatus().is_success() || | 63 if (!fetcher->GetStatus().is_success() || |
| 66 fetcher->GetResponseCode() != net::HTTP_OK) { | 64 fetcher->GetResponseCode() != net::HTTP_OK) { |
| 67 converter_->OnIconFetchComplete(this); | 65 converter_->OnIconFetchComplete(this); |
| 68 return; | 66 return; |
| 69 } | 67 } |
| 70 | 68 |
| 71 std::string unsafe_icon_data; | 69 std::string unsafe_icon_data; |
| 72 fetcher->GetResponseAsString(&unsafe_icon_data); | 70 fetcher->GetResponseAsString(&unsafe_icon_data); |
| 73 | 71 |
| 74 image_decoder_ = | 72 ImageDecoder::GetInstance()->Start( |
| 75 new ImageDecoder(this, unsafe_icon_data, ImageDecoder::DEFAULT_CODEC); | 73 this, unsafe_icon_data, ImageDecoder::DEFAULT_CODEC, |
| 76 image_decoder_->Start( | |
| 77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)); | 74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)); |
| 78 } | 75 } |
| 79 | 76 |
| 80 // ImageDecoder::Delegate overrides: | 77 // ImageDecoder::Delegate overrides: |
| 81 void OnImageDecoded(const ImageDecoder* decoder, | 78 void OnImageDecoded(const SkBitmap& decoded_image) override { |
| 82 const SkBitmap& decoded_image) override { | |
| 83 if (decoded_image.width() == expected_size_) | 79 if (decoded_image.width() == expected_size_) |
| 84 icon_ = decoded_image; | 80 icon_ = decoded_image; |
| 85 converter_->OnIconFetchComplete(this); | 81 converter_->OnIconFetchComplete(this); |
| 86 } | 82 } |
| 87 | 83 |
| 88 void OnDecodeImageFailed(const ImageDecoder* decoder) override { | 84 void OnDecodeImageFailed() override { |
| 89 converter_->OnIconFetchComplete(this); | 85 converter_->OnIconFetchComplete(this); |
| 90 } | 86 } |
| 91 | 87 |
| 92 DriveAppConverter* converter_; | 88 DriveAppConverter* converter_; |
| 93 const GURL icon_url_; | 89 const GURL icon_url_; |
| 94 const int expected_size_; | 90 const int expected_size_; |
| 95 | 91 |
| 96 scoped_ptr<net::URLFetcher> fetcher_; | 92 scoped_ptr<net::URLFetcher> fetcher_; |
| 97 scoped_refptr<ImageDecoder> image_decoder_; | |
| 98 SkBitmap icon_; | 93 SkBitmap icon_; |
| 99 | 94 |
| 100 DISALLOW_COPY_AND_ASSIGN(IconFetcher); | 95 DISALLOW_COPY_AND_ASSIGN(IconFetcher); |
| 101 }; | 96 }; |
| 102 | 97 |
| 103 DriveAppConverter::DriveAppConverter(Profile* profile, | 98 DriveAppConverter::DriveAppConverter(Profile* profile, |
| 104 const drive::DriveAppInfo& drive_app_info, | 99 const drive::DriveAppInfo& drive_app_info, |
| 105 const FinishedCallback& finished_callback) | 100 const FinishedCallback& finished_callback) |
| 106 : profile_(profile), | 101 : profile_(profile), |
| 107 drive_app_info_(drive_app_info), | 102 drive_app_info_(drive_app_info), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return; | 199 return; |
| 205 } | 200 } |
| 206 | 201 |
| 207 extension_ = crx_installer_->extension(); | 202 extension_ = crx_installer_->extension(); |
| 208 is_new_install_ = success && crx_installer_->current_version().empty(); | 203 is_new_install_ = success && crx_installer_->current_version().empty(); |
| 209 PostInstallCleanUp(); | 204 PostInstallCleanUp(); |
| 210 | 205 |
| 211 finished_callback_.Run(this, success); | 206 finished_callback_.Run(this, success); |
| 212 // |finished_callback_| could delete this. | 207 // |finished_callback_| could delete this. |
| 213 } | 208 } |
| OLD | NEW |