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 fetcher_->Start(g_browser_process->system_request_context()); |
| 33 } |
| 34 |
| 35 // BitmapFetcherDelegate overrides. |
| 36 void ProfileAvatarDownloader::OnFetchComplete(const GURL url, |
| 37 const SkBitmap* bitmap) { |
| 38 if (!bitmap || !cache_) |
| 39 return; |
| 40 |
| 41 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. |
| 42 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); |
| 43 cache_->SaveAvatarImageAtPath(&image, |
| 44 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), |
| 45 profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); |
| 46 } |
OLD | NEW |