Chromium Code Reviews| Index: chrome/browser/bitmap_fetcher/bitmap_fetcher_service.cc |
| diff --git a/chrome/browser/bitmap_fetcher/bitmap_fetcher_service.cc b/chrome/browser/bitmap_fetcher/bitmap_fetcher_service.cc |
| index 17d4f313cd1cdf4367f472a4c080739e6559e65f..f51651bb7dcc4e97de1bb67f6e7a7572855246f2 100644 |
| --- a/chrome/browser/bitmap_fetcher/bitmap_fetcher_service.cc |
| +++ b/chrome/browser/bitmap_fetcher/bitmap_fetcher_service.cc |
| @@ -118,8 +118,10 @@ void BitmapFetcherService::Prefetch(const GURL& url) { |
| EnsureFetcherForUrl(url); |
| } |
| -chrome::BitmapFetcher* BitmapFetcherService::CreateFetcher(const GURL& url) { |
| - chrome::BitmapFetcher* new_fetcher = new chrome::BitmapFetcher(url, this); |
| +scoped_ptr<chrome::BitmapFetcher> BitmapFetcherService::CreateFetcher( |
| + const GURL& url) { |
| + scoped_ptr<chrome::BitmapFetcher> new_fetcher( |
| + new chrome::BitmapFetcher(url, this)); |
| new_fetcher->Init( |
| context_->GetRequestContext(), |
| @@ -136,32 +138,29 @@ const chrome::BitmapFetcher* BitmapFetcherService::EnsureFetcherForUrl( |
| if (fetcher) |
| return fetcher; |
| - chrome::BitmapFetcher* new_fetcher = CreateFetcher(url); |
| - active_fetchers_.push_back(new_fetcher); |
| - return new_fetcher; |
| + scoped_ptr<chrome::BitmapFetcher> new_fetcher = CreateFetcher(url); |
| + active_fetchers_.push_back(new_fetcher.Pass()); |
| + return active_fetchers_.back().get(); |
| } |
| const chrome::BitmapFetcher* BitmapFetcherService::FindFetcherForUrl( |
| const GURL& url) { |
| - for (BitmapFetchers::iterator iter = active_fetchers_.begin(); |
| - iter != active_fetchers_.end(); |
| - ++iter) { |
| - if (url == (*iter)->url()) |
| - return *iter; |
| + for (auto it = active_fetchers_.begin(); it != active_fetchers_.end(); ++it) { |
| + if (url == (*it)->url()) |
| + return it->get(); |
| } |
| - return NULL; |
| + return nullptr; |
| } |
| void BitmapFetcherService::RemoveFetcher(const chrome::BitmapFetcher* fetcher) { |
| - for (BitmapFetchers::iterator iter = active_fetchers_.begin(); |
| - iter != active_fetchers_.end(); |
| - ++iter) { |
| - if (fetcher == (*iter)) { |
| - active_fetchers_.erase(iter); |
| - return; |
| - } |
| + auto it = active_fetchers_.begin(); |
|
Nico
2015/11/11 01:35:53
auto here is cool, but the rest of the loop change
danakj
2015/11/11 01:45:57
(we discussed this in person and nico was basicall
|
| + for (; it != active_fetchers_.end(); ++it) { |
| + if (it->get() == fetcher) |
| + break; |
| } |
| - NOTREACHED(); // RemoveFetcher should always result in removal. |
| + // RemoveFetcher should always result in removal. |
| + DCHECK(it != active_fetchers_.end()); |
| + active_fetchers_.erase(it); |
| } |
| void BitmapFetcherService::OnFetchComplete(const GURL& url, |