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

Side by Side Diff: components/dom_distiller/core/distiller_url_fetcher.cc

Issue 2703283004: Network traffic annotation added to distiller_url_fetcher. (Closed)
Patch Set: Minor update. Created 3 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
« no previous file with comments | « components/dom_distiller/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/dom_distiller/core/distiller_url_fetcher.h" 5 #include "components/dom_distiller/core/distiller_url_fetcher.h"
6 6
7 #include "components/data_use_measurement/core/data_use_user_data.h" 7 #include "components/data_use_measurement/core/data_use_user_data.h"
8 #include "net/http/http_status_code.h" 8 #include "net/http/http_status_code.h"
9 #include "net/traffic_annotation/network_traffic_annotation.h"
9 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher.h"
10 #include "net/url_request/url_fetcher_delegate.h" 11 #include "net/url_request/url_fetcher_delegate.h"
11 #include "net/url_request/url_request_context_getter.h" 12 #include "net/url_request/url_request_context_getter.h"
12 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 using net::URLFetcher; 16 using net::URLFetcher;
16 17
17 namespace dom_distiller { 18 namespace dom_distiller {
18 19
(...skipping 21 matching lines...) Expand all
40 // Don't allow a fetch if one is pending. 41 // Don't allow a fetch if one is pending.
41 DCHECK(!url_fetcher_ || !url_fetcher_->GetStatus().is_io_pending()); 42 DCHECK(!url_fetcher_ || !url_fetcher_->GetStatus().is_io_pending());
42 callback_ = callback; 43 callback_ = callback;
43 url_fetcher_ = CreateURLFetcher(context_getter_, url); 44 url_fetcher_ = CreateURLFetcher(context_getter_, url);
44 url_fetcher_->Start(); 45 url_fetcher_->Start();
45 } 46 }
46 47
47 std::unique_ptr<URLFetcher> DistillerURLFetcher::CreateURLFetcher( 48 std::unique_ptr<URLFetcher> DistillerURLFetcher::CreateURLFetcher(
48 net::URLRequestContextGetter* context_getter, 49 net::URLRequestContextGetter* context_getter,
49 const std::string& url) { 50 const std::string& url) {
51 net::NetworkTrafficAnnotationTag traffic_annotation =
52 net::DefineNetworkTrafficAnnotation("dom_distiller", R"(
53 semantics {
54 sender: "DOM Distiller"
55 description:
56 "Chromium provides Mobile-friendly view on Android phones when the "
noyau (Ping after 24h) 2017/02/24 09:37:28 Please amend this comment. by either removing andr
Ramin Halavati 2017/02/24 09:50:21 Done.
57 "web page contains an article, and is not mobile-friendly. If the "
58 "user enters Mobile-friendly view, the main content would be "
59 "extracted and reflowed for better readability. DOM distiller is "
60 "the backend service for Mobile-friendly view, Reader Mode, and "
61 "Reading List."
62 trigger:
63 "User enters Mobile-friendly view, Reader Mode, or Reading List."
noyau (Ping after 24h) 2017/02/24 09:37:28 This trigger is incorrect on iOS. On this platform
Ramin Halavati 2017/02/24 09:50:22 Done.
64 data:
65 "URL of the required website resources to fetch. No user "
66 "information is sent."
67 destination: WEBSITE
68 }
69 policy {
70 cookies_allowed: true
71 cookies_store: "user"
72 setting: "Users can enable or disable Mobile-friendly view by "
73 "toggling chrome://flags#reader-mode-heuristics in Chromium on "
74 "Android."
75 policy_exception_justification:
76 "Not implemented, considered not useful as no content is being "
77 "uploaded; this request merely downloads the resources on the web."
78 })");
50 std::unique_ptr<net::URLFetcher> fetcher = 79 std::unique_ptr<net::URLFetcher> fetcher =
51 URLFetcher::Create(GURL(url), URLFetcher::GET, this); 80 URLFetcher::Create(GURL(url), URLFetcher::GET, this, traffic_annotation);
52 data_use_measurement::DataUseUserData::AttachToFetcher( 81 data_use_measurement::DataUseUserData::AttachToFetcher(
53 fetcher.get(), data_use_measurement::DataUseUserData::DOM_DISTILLER); 82 fetcher.get(), data_use_measurement::DataUseUserData::DOM_DISTILLER);
54 fetcher->SetRequestContext(context_getter); 83 fetcher->SetRequestContext(context_getter);
55 static const int kMaxRetries = 5; 84 static const int kMaxRetries = 5;
56 fetcher->SetMaxRetriesOn5xx(kMaxRetries); 85 fetcher->SetMaxRetriesOn5xx(kMaxRetries);
57 return fetcher; 86 return fetcher;
58 } 87 }
59 88
60 void DistillerURLFetcher::OnURLFetchComplete( 89 void DistillerURLFetcher::OnURLFetchComplete(
61 const URLFetcher* source) { 90 const URLFetcher* source) {
62 std::string response; 91 std::string response;
63 if (source && source->GetStatus().is_success() && 92 if (source && source->GetStatus().is_success() &&
64 source->GetResponseCode() == net::HTTP_OK) { 93 source->GetResponseCode() == net::HTTP_OK) {
65 // Only copy over the data if the request was successful. Insert 94 // Only copy over the data if the request was successful. Insert
66 // an empty string into the proto otherwise. 95 // an empty string into the proto otherwise.
67 source->GetResponseAsString(&response); 96 source->GetResponseAsString(&response);
68 } 97 }
69 callback_.Run(response); 98 callback_.Run(response);
70 } 99 }
71 100
72 } // namespace dom_distiller 101 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698