| 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/bitmap_fetcher/bitmap_fetcher_service.h" | 5 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return new_fetcher; | 136 return new_fetcher; |
| 136 } | 137 } |
| 137 | 138 |
| 138 const chrome::BitmapFetcher* BitmapFetcherService::EnsureFetcherForUrl( | 139 const chrome::BitmapFetcher* BitmapFetcherService::EnsureFetcherForUrl( |
| 139 const GURL& url) { | 140 const GURL& url) { |
| 140 const chrome::BitmapFetcher* fetcher = FindFetcherForUrl(url); | 141 const chrome::BitmapFetcher* fetcher = FindFetcherForUrl(url); |
| 141 if (fetcher) | 142 if (fetcher) |
| 142 return fetcher; | 143 return fetcher; |
| 143 | 144 |
| 144 scoped_ptr<chrome::BitmapFetcher> new_fetcher = CreateFetcher(url); | 145 scoped_ptr<chrome::BitmapFetcher> new_fetcher = CreateFetcher(url); |
| 145 active_fetchers_.push_back(new_fetcher.Pass()); | 146 active_fetchers_.push_back(std::move(new_fetcher)); |
| 146 return active_fetchers_.back().get(); | 147 return active_fetchers_.back().get(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 const chrome::BitmapFetcher* BitmapFetcherService::FindFetcherForUrl( | 150 const chrome::BitmapFetcher* BitmapFetcherService::FindFetcherForUrl( |
| 150 const GURL& url) { | 151 const GURL& url) { |
| 151 for (auto it = active_fetchers_.begin(); it != active_fetchers_.end(); ++it) { | 152 for (auto it = active_fetchers_.begin(); it != active_fetchers_.end(); ++it) { |
| 152 if (url == (*it)->url()) | 153 if (url == (*it)->url()) |
| 153 return it->get(); | 154 return it->get(); |
| 154 } | 155 } |
| 155 return nullptr; | 156 return nullptr; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 183 } | 184 } |
| 184 | 185 |
| 185 if (bitmap && !bitmap->isNull()) { | 186 if (bitmap && !bitmap->isNull()) { |
| 186 CacheEntry* entry = new CacheEntry; | 187 CacheEntry* entry = new CacheEntry; |
| 187 entry->bitmap.reset(new SkBitmap(*bitmap)); | 188 entry->bitmap.reset(new SkBitmap(*bitmap)); |
| 188 cache_.Put(fetcher->url(), entry); | 189 cache_.Put(fetcher->url(), entry); |
| 189 } | 190 } |
| 190 | 191 |
| 191 RemoveFetcher(fetcher); | 192 RemoveFetcher(fetcher); |
| 192 } | 193 } |
| OLD | NEW |