Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2311)

Unified Diff: chrome/browser/profiles/profile_avatar_downloader.cc

Issue 222313005: [Profiles] Download high-res avatars using the --new-profile-management flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b3a6bb264a087c2c03987d2f04a2ca8a5d96070b
--- /dev/null
+++ b/chrome/browser/profiles/profile_avatar_downloader.cc
@@ -0,0 +1,49 @@
+// 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/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(
+ net::URLRequestContextGetter* request_context,
+ size_t icon_index,
+ ProfileInfoCache* cache)
+ : request_context_(request_context),
+ 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(request_context_);
+}
+
+// BitmapFetcherDelegate overrides.
+void ProfileAvatarDownloader::OnFetchComplete(const GURL url,
+ const SkBitmap* bitmap) {
+ if (!bitmap) {
+ return;
+ }
+
+ // Decode the downloaded bitmap. Ownership of the pointer is taken by
+ // |cached_avatar_images_|.
+ gfx::Image* image = new gfx::Image(gfx::Image::CreateFrom1xBitmap(*bitmap));
+ cache_->SaveAvatarImageAtPath(image,
+ profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_),
+ profiles::GetPathOfHighResAvatarAtIndex(icon_index_));
+}

Powered by Google App Engine
This is Rietveld 408576698