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

Side by Side Diff: chrome/browser/profiles/profile_avatar_downloader.cc

Issue 1794353003: Refactor ProfileInfoCache in c/b/profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_avatar_downloader.h" 5 #include "chrome/browser/profiles/profile_avatar_downloader.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
11 #include "chrome/browser/profiles/profile_info_cache.h" 11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
13 13
14 namespace { 14 namespace {
15 const char kHighResAvatarDownloadUrlPrefix[] = 15 const char kHighResAvatarDownloadUrlPrefix[] =
16 "https://www.gstatic.com/chrome/profile_avatars/"; 16 "https://www.gstatic.com/chrome/profile_avatars/";
17 } 17 }
18 18
19 ProfileAvatarDownloader::ProfileAvatarDownloader( 19 ProfileAvatarDownloader::ProfileAvatarDownloader(
20 size_t icon_index, 20 size_t icon_index,
21 const base::FilePath& profile_path, 21 const base::FilePath& profile_path,
22 ProfileInfoCache* cache) 22 ProfileAttributesStorage* storage)
23 : icon_index_(icon_index), 23 : icon_index_(icon_index),
24 profile_path_(profile_path), 24 profile_path_(profile_path),
25 cache_(cache) { 25 storage_(storage) {
26 DCHECK(storage);
26 GURL url(std::string(kHighResAvatarDownloadUrlPrefix) + 27 GURL url(std::string(kHighResAvatarDownloadUrlPrefix) +
27 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index)); 28 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index));
28 fetcher_.reset(new chrome::BitmapFetcher(url, this)); 29 fetcher_.reset(new chrome::BitmapFetcher(url, this));
29 } 30 }
30 31
31 ProfileAvatarDownloader::~ProfileAvatarDownloader() { 32 ProfileAvatarDownloader::~ProfileAvatarDownloader() {
32 } 33 }
33 34
34 void ProfileAvatarDownloader::Start() { 35 void ProfileAvatarDownloader::Start() {
35 // In unit tests, the browser process can return a NULL request context. 36 // In unit tests, the browser process can return a NULL request context.
36 net::URLRequestContextGetter* request_context = 37 net::URLRequestContextGetter* request_context =
37 g_browser_process->system_request_context(); 38 g_browser_process->system_request_context();
38 if (request_context) { 39 if (request_context) {
39 fetcher_->Init( 40 fetcher_->Init(
40 request_context, 41 request_context,
41 std::string(), 42 std::string(),
42 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, 43 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
43 net::LOAD_NORMAL); 44 net::LOAD_NORMAL);
44 fetcher_->Start(); 45 fetcher_->Start();
45 } 46 }
46 } 47 }
47 48
48 // BitmapFetcherDelegate overrides. 49 // BitmapFetcherDelegate overrides.
49 void ProfileAvatarDownloader::OnFetchComplete(const GURL& url, 50 void ProfileAvatarDownloader::OnFetchComplete(const GURL& url,
50 const SkBitmap* bitmap) { 51 const SkBitmap* bitmap) {
51 if (!bitmap || !cache_) 52 if (!bitmap)
52 return; 53 return;
53 54
54 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. 55 ProfileAttributesEntry* entry;
56 if (storage_->GetProfileAttributesWithPath(profile_path_, &entry)) {
Mike Lerman 2016/03/18 17:10:44 just confirming... we don't use this flow for the
lwchkg 2016/03/19 18:48:46 Currently no, but it DOES make sense for guests to
Mike Lerman 2016/03/30 01:18:10 Sure, leave it as is for now, then. I like reducin
lwchkg 2016/03/31 19:32:26 We have those funny anonymous animals in Google Do
57 // If the profile is deleted during the async operation, we cannot find the
58 // profile attributes entry. In this case, discard the downloaded bitmap.
59 return;
60 }
61
62 // Decode the downloaded bitmap. Ownership of the image is taken by profile
63 // attributes storage.
55 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); 64 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap);
56 cache_->SaveAvatarImageAtPath(&image, 65 entry->SaveAvatarImage(&image,
57 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), 66 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_),
58 profiles::GetPathOfHighResAvatarAtIndex(icon_index_), 67 profiles::GetPathOfHighResAvatarAtIndex(icon_index_));
59 profile_path_);
60 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698