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

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: 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
« 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("...", R"(
wychen 2017/02/23 21:31:24 Nit: raw strings should not be indented with the r
wychen 2017/02/23 21:31:25 unique id: "dom_distiller"
Ramin Halavati 2017/02/24 09:03:49 Annotation raw strings are optimized out of binary
53 semantics {
54 sender: "..."
wychen 2017/02/23 21:31:24 sender: "DOM Distiller"
Ramin Halavati 2017/02/24 09:03:49 Done.
55 description: "..."
wychen 2017/02/23 21:31:24 description: "Google Chrome provides Mobile-friend
Ramin Halavati 2017/02/24 09:03:49 Done.
56 trigger: "..."
wychen 2017/02/23 21:31:24 trigger: "User enters Mobile-friendly view, Reader
Ramin Halavati 2017/02/24 09:03:48 Done.
57 data: "..."
wychen 2017/02/23 21:31:24 data: "URL of the required website resources to fe
Ramin Halavati 2017/02/24 09:03:49 Done.
58 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
wychen 2017/02/23 21:31:25 destination: WEBSITE
Ramin Halavati 2017/02/24 09:03:49 Done.
59 }
60 policy {
61 cookies_allowed: false/true
wychen 2017/02/23 21:31:25 cookies_allowed: true
Ramin Halavati 2017/02/24 09:03:49 Done.
62 cookies_store: "..."
wychen 2017/02/23 21:31:24 cookies_store: "user"
Ramin Halavati 2017/02/24 09:03:48 Done.
63 setting: "..."
wychen 2017/02/23 21:31:24 setting: "You can enable or disable Mobile-friendl
Olivier 2017/02/24 08:36:16 Reader mode is not publicly shipped on iOS. Only p
Ramin Halavati 2017/02/24 09:03:49 Please advise on the settings comment for Reading
wychen 2017/02/24 18:22:10 Then I guess we don't mention Reader Mode on iOS a
64 policy {
wychen 2017/02/23 21:31:24 No policies.
Ramin Halavati 2017/02/24 09:03:49 Done.
65 [POLICY_NAME] {
66 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
67 value: ...
68 }
69 }
70 policy_exception_justification: "..."
wychen 2017/02/23 21:31:25 policy_exception_justification: "Not implemented,
Ramin Halavati 2017/02/24 09:03:48 Done.
71 })");
50 std::unique_ptr<net::URLFetcher> fetcher = 72 std::unique_ptr<net::URLFetcher> fetcher =
51 URLFetcher::Create(GURL(url), URLFetcher::GET, this); 73 URLFetcher::Create(GURL(url), URLFetcher::GET, this, traffic_annotation);
52 data_use_measurement::DataUseUserData::AttachToFetcher( 74 data_use_measurement::DataUseUserData::AttachToFetcher(
53 fetcher.get(), data_use_measurement::DataUseUserData::DOM_DISTILLER); 75 fetcher.get(), data_use_measurement::DataUseUserData::DOM_DISTILLER);
54 fetcher->SetRequestContext(context_getter); 76 fetcher->SetRequestContext(context_getter);
55 static const int kMaxRetries = 5; 77 static const int kMaxRetries = 5;
56 fetcher->SetMaxRetriesOn5xx(kMaxRetries); 78 fetcher->SetMaxRetriesOn5xx(kMaxRetries);
57 return fetcher; 79 return fetcher;
58 } 80 }
59 81
60 void DistillerURLFetcher::OnURLFetchComplete( 82 void DistillerURLFetcher::OnURLFetchComplete(
61 const URLFetcher* source) { 83 const URLFetcher* source) {
62 std::string response; 84 std::string response;
63 if (source && source->GetStatus().is_success() && 85 if (source && source->GetStatus().is_success() &&
64 source->GetResponseCode() == net::HTTP_OK) { 86 source->GetResponseCode() == net::HTTP_OK) {
65 // Only copy over the data if the request was successful. Insert 87 // Only copy over the data if the request was successful. Insert
66 // an empty string into the proto otherwise. 88 // an empty string into the proto otherwise.
67 source->GetResponseAsString(&response); 89 source->GetResponseAsString(&response);
68 } 90 }
69 callback_.Run(response); 91 callback_.Run(response);
70 } 92 }
71 93
72 } // namespace dom_distiller 94 } // 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