OLD | NEW |
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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/traffic_annotation/network_traffic_annotation.h" |
15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 const char kHighResAvatarDownloadUrlPrefix[] = | 19 const char kHighResAvatarDownloadUrlPrefix[] = |
19 "https://www.gstatic.com/chrome/profile_avatars/"; | 20 "https://www.gstatic.com/chrome/profile_avatars/"; |
20 } | 21 } |
21 | 22 |
22 ProfileAvatarDownloader::ProfileAvatarDownloader( | 23 ProfileAvatarDownloader::ProfileAvatarDownloader( |
23 size_t icon_index, | 24 size_t icon_index, |
24 const FetchCompleteCallback& callback) | 25 const FetchCompleteCallback& callback) |
25 : icon_index_(icon_index), | 26 : icon_index_(icon_index), |
26 callback_(callback) { | 27 callback_(callback) { |
27 DCHECK(!callback_.is_null()); | 28 DCHECK(!callback_.is_null()); |
28 GURL url(std::string(kHighResAvatarDownloadUrlPrefix) + | 29 GURL url(std::string(kHighResAvatarDownloadUrlPrefix) + |
29 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index)); | 30 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index)); |
30 fetcher_.reset(new chrome::BitmapFetcher(url, this)); | 31 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 32 net::DefineNetworkTrafficAnnotation("profile_avatar", R"( |
| 33 semantics { |
| 34 sender: "Profile Avatar Downloader" |
| 35 description: |
| 36 "The Chromium binary comes with a bundle of low-resolution " |
| 37 "versions of avatar images. When the user selects an avatar in " |
| 38 "chrome://settings, Chromium will download a high-resolution " |
| 39 "version from Google's static content servers for use in the " |
| 40 "people manager UI." |
| 41 trigger: |
| 42 "User selects a new avatar in chrome://settings for their profile" |
| 43 data: "None, only the filename of the png to download." |
| 44 destination: GOOGLE_OWNED_SERVICE |
| 45 } |
| 46 policy { |
| 47 cookies_allowed: false |
| 48 policy_exception_justification: |
| 49 "No content is being uploaded or saved; this request merely " |
| 50 "downloads a publicly available PNG file." |
| 51 })"); |
| 52 fetcher_.reset(new chrome::BitmapFetcher(url, this, traffic_annotation)); |
31 } | 53 } |
32 | 54 |
33 ProfileAvatarDownloader::~ProfileAvatarDownloader() { | 55 ProfileAvatarDownloader::~ProfileAvatarDownloader() { |
34 } | 56 } |
35 | 57 |
36 void ProfileAvatarDownloader::Start() { | 58 void ProfileAvatarDownloader::Start() { |
37 // In unit tests, the browser process can return a NULL request context. | 59 // In unit tests, the browser process can return a NULL request context. |
38 net::URLRequestContextGetter* request_context = | 60 net::URLRequestContextGetter* request_context = |
39 g_browser_process->system_request_context(); | 61 g_browser_process->system_request_context(); |
40 if (request_context) { | 62 if (request_context) { |
(...skipping 11 matching lines...) Expand all Loading... |
52 const SkBitmap* bitmap) { | 74 const SkBitmap* bitmap) { |
53 if (!bitmap) | 75 if (!bitmap) |
54 return; | 76 return; |
55 | 77 |
56 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. | 78 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. |
57 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); | 79 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); |
58 callback_.Run(&image, | 80 callback_.Run(&image, |
59 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), | 81 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), |
60 profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); | 82 profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); |
61 } | 83 } |
OLD | NEW |