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

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: Fix a few comments 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
« no previous file with comments | « chrome/browser/android/logo_service.cc ('k') | chrome/browser/bitmap_fetcher/bitmap_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
25 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 // IconFetcher downloads |icon_url| using |converter|'s profile. The icon 29 // IconFetcher downloads |icon_url| using |converter|'s profile. The icon
30 // url is passed from a DriveAppInfo and should follow icon url definition 30 // url is passed from a DriveAppInfo and should follow icon url definition
31 // in Drive API: 31 // in Drive API:
32 // https://developers.google.com/drive/v2/reference/apps#resource 32 // https://developers.google.com/drive/v2/reference/apps#resource
33 // Each icon url represents a single image associated with a certain size. 33 // Each icon url represents a single image associated with a certain size.
34 class DriveAppConverter::IconFetcher : public net::URLFetcherDelegate, 34 class DriveAppConverter::IconFetcher : public net::URLFetcherDelegate,
35 public ImageDecoder::Delegate { 35 public ImageDecoder::ImageRequest {
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 : ImageRequest(
41 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
42 converter_(converter),
41 icon_url_(icon_url), 43 icon_url_(icon_url),
42 expected_size_(expected_size) {} 44 expected_size_(expected_size) {}
43 ~IconFetcher() override { 45 ~IconFetcher() override {}
44 if (image_decoder_.get())
45 image_decoder_->set_delegate(NULL);
46 }
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::Start(this, unsafe_icon_data);
75 new ImageDecoder(this, unsafe_icon_data, ImageDecoder::DEFAULT_CODEC);
76 image_decoder_->Start(
77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI));
78 } 74 }
79 75
80 // ImageDecoder::Delegate overrides: 76 // ImageDecoder::ImageRequest overrides:
81 void OnImageDecoded(const ImageDecoder* decoder, 77 void OnImageDecoded(const SkBitmap& decoded_image) override {
82 const SkBitmap& decoded_image) override {
83 if (decoded_image.width() == expected_size_) 78 if (decoded_image.width() == expected_size_)
84 icon_ = decoded_image; 79 icon_ = decoded_image;
85 converter_->OnIconFetchComplete(this); 80 converter_->OnIconFetchComplete(this);
86 } 81 }
87 82
88 void OnDecodeImageFailed(const ImageDecoder* decoder) override { 83 void OnDecodeImageFailed() override { converter_->OnIconFetchComplete(this); }
89 converter_->OnIconFetchComplete(this);
90 }
91 84
92 DriveAppConverter* converter_; 85 DriveAppConverter* converter_;
93 const GURL icon_url_; 86 const GURL icon_url_;
94 const int expected_size_; 87 const int expected_size_;
95 88
96 scoped_ptr<net::URLFetcher> fetcher_; 89 scoped_ptr<net::URLFetcher> fetcher_;
97 scoped_refptr<ImageDecoder> image_decoder_;
98 SkBitmap icon_; 90 SkBitmap icon_;
99 91
100 DISALLOW_COPY_AND_ASSIGN(IconFetcher); 92 DISALLOW_COPY_AND_ASSIGN(IconFetcher);
101 }; 93 };
102 94
103 DriveAppConverter::DriveAppConverter(Profile* profile, 95 DriveAppConverter::DriveAppConverter(Profile* profile,
104 const drive::DriveAppInfo& drive_app_info, 96 const drive::DriveAppInfo& drive_app_info,
105 const FinishedCallback& finished_callback) 97 const FinishedCallback& finished_callback)
106 : profile_(profile), 98 : profile_(profile),
107 drive_app_info_(drive_app_info), 99 drive_app_info_(drive_app_info),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return; 196 return;
205 } 197 }
206 198
207 extension_ = crx_installer_->extension(); 199 extension_ = crx_installer_->extension();
208 is_new_install_ = success && crx_installer_->current_version().empty(); 200 is_new_install_ = success && crx_installer_->current_version().empty();
209 PostInstallCleanUp(); 201 PostInstallCleanUp();
210 202
211 finished_callback_.Run(this, success); 203 finished_callback_.Run(this, success);
212 // |finished_callback_| could delete this. 204 // |finished_callback_| could delete this.
213 } 205 }
OLDNEW
« no previous file with comments | « chrome/browser/android/logo_service.cc ('k') | chrome/browser/bitmap_fetcher/bitmap_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698