Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: chrome/browser/apps/drive/drive_app_converter.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ImageDecoder->RemoveDelegate Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()) 44 ImageDecoder::GetInstance()->RemoveDelegate(this);
45 image_decoder_->set_delegate(NULL);
46 } 45 }
47 46
48 void Start() { 47 void Start() {
49 fetcher_.reset( 48 fetcher_.reset(
50 net::URLFetcher::Create(icon_url_, net::URLFetcher::GET, this)); 49 net::URLFetcher::Create(icon_url_, net::URLFetcher::GET, this));
51 fetcher_->SetRequestContext(converter_->profile_->GetRequestContext()); 50 fetcher_->SetRequestContext(converter_->profile_->GetRequestContext());
52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 51 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
53 fetcher_->Start(); 52 fetcher_->Start();
54 } 53 }
55 54
56 const GURL& icon_url() const { return icon_url_; } 55 const GURL& icon_url() const { return icon_url_; }
57 const SkBitmap& icon() const { return icon_; } 56 const SkBitmap& icon() const { return icon_; }
58 57
59 private: 58 private:
60 // net::URLFetcherDelegate overrides: 59 // net::URLFetcherDelegate overrides:
61 void OnURLFetchComplete(const net::URLFetcher* source) override { 60 void OnURLFetchComplete(const net::URLFetcher* source) override {
62 CHECK_EQ(fetcher_.get(), source); 61 CHECK_EQ(fetcher_.get(), source);
63 scoped_ptr<net::URLFetcher> fetcher(fetcher_.Pass()); 62 scoped_ptr<net::URLFetcher> fetcher(fetcher_.Pass());
64 63
65 if (!fetcher->GetStatus().is_success() || 64 if (!fetcher->GetStatus().is_success() ||
66 fetcher->GetResponseCode() != net::HTTP_OK) { 65 fetcher->GetResponseCode() != net::HTTP_OK) {
67 converter_->OnIconFetchComplete(this); 66 converter_->OnIconFetchComplete(this);
68 return; 67 return;
69 } 68 }
70 69
71 std::string unsafe_icon_data; 70 std::string unsafe_icon_data;
72 fetcher->GetResponseAsString(&unsafe_icon_data); 71 fetcher->GetResponseAsString(&unsafe_icon_data);
73 72
74 image_decoder_ = 73 ImageDecoder::GetInstance()->Start(
75 new ImageDecoder(this, unsafe_icon_data, ImageDecoder::DEFAULT_CODEC); 74 this, unsafe_icon_data, ImageDecoder::DEFAULT_CODEC,
76 image_decoder_->Start( 75 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), false);
77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI));
78 } 76 }
79 77
80 // ImageDecoder::Delegate overrides: 78 // ImageDecoder::Delegate overrides:
81 void OnImageDecoded(const ImageDecoder* decoder, 79 void OnImageDecoded(const SkBitmap& decoded_image) override {
82 const SkBitmap& decoded_image) override {
83 if (decoded_image.width() == expected_size_) 80 if (decoded_image.width() == expected_size_)
84 icon_ = decoded_image; 81 icon_ = decoded_image;
85 converter_->OnIconFetchComplete(this); 82 converter_->OnIconFetchComplete(this);
86 } 83 }
87 84
88 void OnDecodeImageFailed(const ImageDecoder* decoder) override { 85 void OnDecodeImageFailed() override { converter_->OnIconFetchComplete(this); }
89 converter_->OnIconFetchComplete(this);
90 }
91 86
92 DriveAppConverter* converter_; 87 DriveAppConverter* converter_;
93 const GURL icon_url_; 88 const GURL icon_url_;
94 const int expected_size_; 89 const int expected_size_;
95 90
96 scoped_ptr<net::URLFetcher> fetcher_; 91 scoped_ptr<net::URLFetcher> fetcher_;
97 scoped_refptr<ImageDecoder> image_decoder_;
98 SkBitmap icon_; 92 SkBitmap icon_;
99 93
100 DISALLOW_COPY_AND_ASSIGN(IconFetcher); 94 DISALLOW_COPY_AND_ASSIGN(IconFetcher);
101 }; 95 };
102 96
103 DriveAppConverter::DriveAppConverter(Profile* profile, 97 DriveAppConverter::DriveAppConverter(Profile* profile,
104 const drive::DriveAppInfo& drive_app_info, 98 const drive::DriveAppInfo& drive_app_info,
105 const FinishedCallback& finished_callback) 99 const FinishedCallback& finished_callback)
106 : profile_(profile), 100 : profile_(profile),
107 drive_app_info_(drive_app_info), 101 drive_app_info_(drive_app_info),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return; 198 return;
205 } 199 }
206 200
207 extension_ = crx_installer_->extension(); 201 extension_ = crx_installer_->extension();
208 is_new_install_ = success && crx_installer_->current_version().empty(); 202 is_new_install_ = success && crx_installer_->current_version().empty();
209 PostInstallCleanUp(); 203 PostInstallCleanUp();
210 204
211 finished_callback_.Run(this, success); 205 finished_callback_.Run(this, success);
212 // |finished_callback_| could delete this. 206 // |finished_callback_| could delete this.
213 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698