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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
10 #include "chrome/browser/profiles/profile_info_cache.h"
11
12 namespace {
13 const char kHighResAvatarDownloadUrlPrefix[] =
14 "http://www.gstatic.com/chrome/profile_avatars/";
15 }
16
17 ProfileAvatarDownloader::ProfileAvatarDownloader(
18 net::URLRequestContextGetter* request_context,
19 size_t icon_index,
20 ProfileInfoCache* cache)
21 : request_context_(request_context),
22 icon_index_(icon_index),
23 cache_(cache) {
24 GURL url(std::string(kHighResAvatarDownloadUrlPrefix) +
25 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index));
26 fetcher_.reset(new chrome::BitmapFetcher(url, this));
27 }
28
29 ProfileAvatarDownloader::~ProfileAvatarDownloader() {
30 }
31
32 void ProfileAvatarDownloader::Start() {
33 fetcher_->Start(request_context_);
34 }
35
36 // BitmapFetcherDelegate overrides.
37 void ProfileAvatarDownloader::OnFetchComplete(const GURL url,
38 const SkBitmap* bitmap) {
39 if (!bitmap) {
40 return;
41 }
42
43 // Decode the downloaded bitmap. Ownership of the pointer is taken by
44 // |cached_avatar_images_|.
45 gfx::Image* image = new gfx::Image(gfx::Image::CreateFrom1xBitmap(*bitmap));
46 cache_->SaveAvatarImageAtPath(image,
47 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_),
48 profiles::GetPathOfHighResAvatarAtIndex(icon_index_));
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698