OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/profiles/profile_avatar_downloader.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 11 #include "chrome/browser/profiles/profile_info_cache.h" |
| 12 |
| 13 namespace { |
| 14 const char kHighResAvatarDownloadUrlPrefix[] = |
| 15 "http://www.gstatic.com/chrome/profile_avatars/"; |
| 16 } |
| 17 |
| 18 ProfileAvatarDownloader::ProfileAvatarDownloader( |
| 19 size_t icon_index, |
| 20 ProfileInfoCache* cache) |
| 21 : icon_index_(icon_index), |
| 22 cache_(cache) { |
| 23 GURL url(std::string(kHighResAvatarDownloadUrlPrefix) + |
| 24 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index)); |
| 25 fetcher_.reset(new chrome::BitmapFetcher(url, this)); |
| 26 } |
| 27 |
| 28 ProfileAvatarDownloader::~ProfileAvatarDownloader() { |
| 29 } |
| 30 |
| 31 void ProfileAvatarDownloader::Start() { |
| 32 // In unit tests, the browser process can return a NULL request context. |
| 33 net::URLRequestContextGetter* request_context = |
| 34 g_browser_process->system_request_context(); |
| 35 if (request_context) |
| 36 fetcher_->Start(request_context); |
| 37 } |
| 38 |
| 39 // BitmapFetcherDelegate overrides. |
| 40 void ProfileAvatarDownloader::OnFetchComplete(const GURL url, |
| 41 const SkBitmap* bitmap) { |
| 42 if (!bitmap || !cache_) |
| 43 return; |
| 44 |
| 45 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. |
| 46 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); |
| 47 cache_->SaveAvatarImageAtPath(&image, |
| 48 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), |
| 49 profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); |
| 50 } |
OLD | NEW |