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

Side by Side Diff: content/renderer/image_downloader/image_downloader_base.cc

Issue 2705073003: Remove ScopedVector from content/renderer/. (Closed)
Patch Set: Fix win trybots Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/renderer/image_downloader/image_downloader_base.h" 5 #include "content/renderer/image_downloader/image_downloader_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h"
12 #include "content/child/image_decoder.h" 13 #include "content/child/image_decoder.h"
13 #include "content/public/renderer/render_frame.h" 14 #include "content/public/renderer/render_frame.h"
14 #include "content/public/renderer/render_thread.h" 15 #include "content/public/renderer/render_thread.h"
15 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" 16 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h"
16 #include "net/base/data_url.h" 17 #include "net/base/data_url.h"
17 #include "third_party/WebKit/public/platform/WebCachePolicy.h" 18 #include "third_party/WebKit/public/platform/WebCachePolicy.h"
18 #include "third_party/WebKit/public/platform/WebURLRequest.h" 19 #include "third_party/WebKit/public/platform/WebURLRequest.h"
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" 20 #include "third_party/WebKit/public/web/WebLocalFrame.h"
20 #include "ui/gfx/favicon_size.h" 21 #include "ui/gfx/favicon_size.h"
21 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 87 }
87 88
88 bool ImageDownloaderBase::FetchImage(const GURL& image_url, 89 bool ImageDownloaderBase::FetchImage(const GURL& image_url,
89 bool is_favicon, 90 bool is_favicon,
90 bool bypass_cache, 91 bool bypass_cache,
91 const DownloadCallback& callback) { 92 const DownloadCallback& callback) {
92 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); 93 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
93 DCHECK(frame); 94 DCHECK(frame);
94 95
95 // Create an image resource fetcher and assign it with a call back object. 96 // Create an image resource fetcher and assign it with a call back object.
96 image_fetchers_.push_back(new MultiResolutionImageResourceFetcher( 97 image_fetchers_.push_back(
97 image_url, frame, 0, is_favicon ? WebURLRequest::RequestContextFavicon 98 base::MakeUnique<MultiResolutionImageResourceFetcher>(
98 : WebURLRequest::RequestContextImage, 99 image_url, frame, 0, is_favicon ? WebURLRequest::RequestContextFavicon
99 bypass_cache ? WebCachePolicy::BypassingCache 100 : WebURLRequest::RequestContextImage,
100 : WebCachePolicy::UseProtocolCachePolicy, 101 bypass_cache ? WebCachePolicy::BypassingCache
101 base::Bind(&ImageDownloaderBase::DidFetchImage, base::Unretained(this), 102 : WebCachePolicy::UseProtocolCachePolicy,
102 callback))); 103 base::Bind(&ImageDownloaderBase::DidFetchImage,
104 base::Unretained(this), callback)));
103 return true; 105 return true;
104 } 106 }
105 107
106 void ImageDownloaderBase::DidFetchImage( 108 void ImageDownloaderBase::DidFetchImage(
107 const DownloadCallback& callback, 109 const DownloadCallback& callback,
108 MultiResolutionImageResourceFetcher* fetcher, 110 MultiResolutionImageResourceFetcher* fetcher,
109 const std::vector<SkBitmap>& images) { 111 const std::vector<SkBitmap>& images) {
110 int32_t http_status_code = fetcher->http_status_code(); 112 int32_t http_status_code = fetcher->http_status_code();
111 113
112 // Remove the image fetcher from our pending list. We're in the callback from 114 // Remove the image fetcher from our pending list. We're in the callback from
113 // MultiResolutionImageResourceFetcher, best to delay deletion. 115 // MultiResolutionImageResourceFetcher, best to delay deletion.
114 ImageResourceFetcherList::iterator iter = 116 for (auto iter = image_fetchers_.begin(); iter != image_fetchers_.end();
115 std::find(image_fetchers_.begin(), image_fetchers_.end(), fetcher); 117 ++iter) {
116 if (iter != image_fetchers_.end()) { 118 if (iter->get() == fetcher) {
117 image_fetchers_.weak_erase(iter); 119 iter->release();
118 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, fetcher); 120 image_fetchers_.erase(iter);
121 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, fetcher);
122 break;
123 }
119 } 124 }
120 125
121 // |this| may be destructed after callback is run. 126 // |this| may be destructed after callback is run.
122 callback.Run(http_status_code, images); 127 callback.Run(http_status_code, images);
123 } 128 }
124 129
125 void ImageDownloaderBase::OnDestruct() { 130 void ImageDownloaderBase::OnDestruct() {
126 for (auto fetchers : image_fetchers_) { 131 for (const auto& fetchers : image_fetchers_) {
127 // Will run callbacks with an empty image vector. 132 // Will run callbacks with an empty image vector.
128 fetchers->OnRenderFrameDestruct(); 133 fetchers->OnRenderFrameDestruct();
129 } 134 }
130 } 135 }
131 136
132 } // namespace content 137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698