Chromium Code Reviews| 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, there is no g_browser_process, so we do not have a | |
|
msw
2014/04/30 19:46:21
nit: This comment would seem to indicate that g_br
noms (inactive)
2014/04/30 20:02:19
Updated the comment.
On 2014/04/30 19:46:21, msw w
| |
| 33 // request context. | |
| 34 net::URLRequestContextGetter* request_context = | |
| 35 g_browser_process->system_request_context(); | |
| 36 if (request_context) | |
| 37 fetcher_->Start(request_context); | |
| 38 } | |
| 39 | |
| 40 // BitmapFetcherDelegate overrides. | |
| 41 void ProfileAvatarDownloader::OnFetchComplete(const GURL url, | |
| 42 const SkBitmap* bitmap) { | |
| 43 if (!bitmap || !cache_) | |
| 44 return; | |
| 45 | |
| 46 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. | |
| 47 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); | |
| 48 cache_->SaveAvatarImageAtPath(&image, | |
| 49 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), | |
| 50 profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); | |
| 51 } | |
| OLD | NEW |