Index: chrome/browser/profiles/profile_avatar_downloader.cc |
diff --git a/chrome/browser/profiles/profile_avatar_downloader.cc b/chrome/browser/profiles/profile_avatar_downloader.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c5a716df8ed6b81473fe6fc02588e114e6ec4400 |
--- /dev/null |
+++ b/chrome/browser/profiles/profile_avatar_downloader.cc |
@@ -0,0 +1,46 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/profiles/profile_avatar_downloader.h" |
+ |
+#include "base/files/file_path.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_avatar_icon_util.h" |
+#include "chrome/browser/profiles/profile_info_cache.h" |
+ |
+namespace { |
+const char kHighResAvatarDownloadUrlPrefix[] = |
+ "http://www.gstatic.com/chrome/profile_avatars/"; |
+} |
+ |
+ProfileAvatarDownloader::ProfileAvatarDownloader( |
+ size_t icon_index, |
+ ProfileInfoCache* cache) |
+ : icon_index_(icon_index), |
+ cache_(cache) { |
+ GURL url(std::string(kHighResAvatarDownloadUrlPrefix) + |
+ profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index)); |
+ fetcher_.reset(new chrome::BitmapFetcher(url, this)); |
+} |
+ |
+ProfileAvatarDownloader::~ProfileAvatarDownloader() { |
+} |
+ |
+void ProfileAvatarDownloader::Start() { |
+ fetcher_->Start(g_browser_process->system_request_context()); |
+} |
+ |
+// BitmapFetcherDelegate overrides. |
+void ProfileAvatarDownloader::OnFetchComplete(const GURL url, |
+ const SkBitmap* bitmap) { |
+ if (!bitmap || !cache_) |
+ return; |
+ |
+ // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. |
+ gfx::Image* image = new gfx::Image(gfx::Image::CreateFrom1xBitmap(*bitmap)); |
msw
2014/04/29 20:11:44
You allocate a new image here and allocate a copy
noms (inactive)
2014/04/29 20:29:10
Oh, you're totally right. I don't know why I'm mak
|
+ cache_->SaveAvatarImageAtPath(image, |
+ profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), |
+ profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); |
+} |