OLD | NEW |
---|---|
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 Loading... | |
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 " | |
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 in a simple layout for better readability. " | |
60 "On iOS, apps can add URLs to the Reading List in Chromium. When " | |
61 "opening the entries in the Reading List with no or limited " | |
62 "network, the simple layout would be shown. DOM distiller is the " | |
63 "backend service for Mobile-friendly view and Reading List." | |
64 trigger: | |
65 "When the user enters Mobile-friendly view on Android phones, or " | |
66 "adds entries to the Reading List on iOS. Note that Reading List " | |
67 "entries can be added from other apps." | |
68 data: | |
69 "URL of the required website resources to fetch. No user " | |
msramek
2017/03/07 10:57:27
nit: URLs (since "resources" in this sentence is p
Ramin Halavati
2017/03/07 13:14:39
Done.
| |
70 "information is sent." | |
71 destination: WEBSITE | |
72 } | |
73 policy { | |
74 cookies_allowed: true | |
75 cookies_store: "user" | |
76 setting: "Users can enable or disable Mobile-friendly view by " | |
77 "toggling chrome://flags#reader-mode-heuristics in Chromium on " | |
78 "Android." | |
79 policy_exception_justification: | |
80 "Not implemented, considered not useful as no content is being " | |
81 "uploaded; this request merely downloads the resources on the web." | |
82 })"); | |
50 std::unique_ptr<net::URLFetcher> fetcher = | 83 std::unique_ptr<net::URLFetcher> fetcher = |
51 URLFetcher::Create(GURL(url), URLFetcher::GET, this); | 84 URLFetcher::Create(GURL(url), URLFetcher::GET, this, traffic_annotation); |
52 data_use_measurement::DataUseUserData::AttachToFetcher( | 85 data_use_measurement::DataUseUserData::AttachToFetcher( |
53 fetcher.get(), data_use_measurement::DataUseUserData::DOM_DISTILLER); | 86 fetcher.get(), data_use_measurement::DataUseUserData::DOM_DISTILLER); |
54 fetcher->SetRequestContext(context_getter); | 87 fetcher->SetRequestContext(context_getter); |
55 static const int kMaxRetries = 5; | 88 static const int kMaxRetries = 5; |
56 fetcher->SetMaxRetriesOn5xx(kMaxRetries); | 89 fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
57 return fetcher; | 90 return fetcher; |
58 } | 91 } |
59 | 92 |
60 void DistillerURLFetcher::OnURLFetchComplete( | 93 void DistillerURLFetcher::OnURLFetchComplete( |
61 const URLFetcher* source) { | 94 const URLFetcher* source) { |
62 std::string response; | 95 std::string response; |
63 if (source && source->GetStatus().is_success() && | 96 if (source && source->GetStatus().is_success() && |
64 source->GetResponseCode() == net::HTTP_OK) { | 97 source->GetResponseCode() == net::HTTP_OK) { |
65 // Only copy over the data if the request was successful. Insert | 98 // Only copy over the data if the request was successful. Insert |
66 // an empty string into the proto otherwise. | 99 // an empty string into the proto otherwise. |
67 source->GetResponseAsString(&response); | 100 source->GetResponseAsString(&response); |
68 } | 101 } |
69 callback_.Run(response); | 102 callback_.Run(response); |
70 } | 103 } |
71 | 104 |
72 } // namespace dom_distiller | 105 } // namespace dom_distiller |
OLD | NEW |