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

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

Issue 2682263002: Network traffic annotation added to chrome::BitmapFetcher. (Closed)
Patch Set: Unittests added. Created 3 years, 10 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 <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("", R"(
33 semantics {
34 sender: ""
Mike Lerman 2017/02/09 13:40:16 SEMANTICS: sender: profiles description: The Goog
Ramin Halavati 2017/02/09 14:22:51 Done.
35 description: ""
36 trigger: ""
37 data: ""
38 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
39 }
40 policy {
41 cookies_allowed: false/true
42 cookies_store_exceptions: ""
43 setting: ""
44 policy {
45 [POLICY_NAME] {
46 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
47 value: ...
48 }
49 }
50 })");
51 fetcher_.reset(new chrome::BitmapFetcher(url, this, traffic_annotation));
31 } 52 }
32 53
33 ProfileAvatarDownloader::~ProfileAvatarDownloader() { 54 ProfileAvatarDownloader::~ProfileAvatarDownloader() {
34 } 55 }
35 56
36 void ProfileAvatarDownloader::Start() { 57 void ProfileAvatarDownloader::Start() {
37 // In unit tests, the browser process can return a NULL request context. 58 // In unit tests, the browser process can return a NULL request context.
38 net::URLRequestContextGetter* request_context = 59 net::URLRequestContextGetter* request_context =
39 g_browser_process->system_request_context(); 60 g_browser_process->system_request_context();
40 if (request_context) { 61 if (request_context) {
(...skipping 11 matching lines...) Expand all
52 const SkBitmap* bitmap) { 73 const SkBitmap* bitmap) {
53 if (!bitmap) 74 if (!bitmap)
54 return; 75 return;
55 76
56 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|. 77 // Decode the downloaded bitmap. Ownership of the image is taken by |cache_|.
57 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap); 78 gfx::Image image = gfx::Image::CreateFrom1xBitmap(*bitmap);
58 callback_.Run(&image, 79 callback_.Run(&image,
59 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_), 80 profiles::GetDefaultAvatarIconFileNameAtIndex(icon_index_),
60 profiles::GetPathOfHighResAvatarAtIndex(icon_index_)); 81 profiles::GetPathOfHighResAvatarAtIndex(icon_index_));
61 } 82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698