OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/offline_pages/background_loader_offliner.h" | 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
10 #include "chrome/browser/android/offline_pages/offliner_helper.h" | 10 #include "chrome/browser/android/offline_pages/offliner_helper.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 BackgroundLoaderOffliner* offliner() { return offliner_; } | 37 BackgroundLoaderOffliner* offliner() { return offliner_; } |
38 | 38 |
39 private: | 39 private: |
40 // The offliner that the WebContents is attached to. The offliner owns the | 40 // The offliner that the WebContents is attached to. The offliner owns the |
41 // Delegate which owns the WebContents that this data is attached to. | 41 // Delegate which owns the WebContents that this data is attached to. |
42 // Therefore, its lifetime should exceed that of the WebContents, so this | 42 // Therefore, its lifetime should exceed that of the WebContents, so this |
43 // should always be non-null. | 43 // should always be non-null. |
44 BackgroundLoaderOffliner* offliner_; | 44 BackgroundLoaderOffliner* offliner_; |
45 }; | 45 }; |
46 | 46 |
| 47 std::string AddHistogramSuffix(const ClientId& client_id, |
| 48 const char* histogram_name) { |
| 49 if (client_id.name_space.empty()) { |
| 50 NOTREACHED(); |
| 51 return histogram_name; |
| 52 } |
| 53 std::string adjusted_histogram_name(histogram_name); |
| 54 adjusted_histogram_name += "." + client_id.name_space; |
| 55 return adjusted_histogram_name; |
| 56 } |
| 57 |
| 58 void RecordErrorCauseUMA(const ClientId& client_id, net::Error error_code) { |
| 59 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 60 AddHistogramSuffix(client_id, |
| 61 "OfflinePages.Background.BackgroundLoadingFailedCode"), |
| 62 std::abs(error_code)); |
| 63 } |
47 } // namespace | 64 } // namespace |
48 | 65 |
49 BackgroundLoaderOffliner::BackgroundLoaderOffliner( | 66 BackgroundLoaderOffliner::BackgroundLoaderOffliner( |
50 content::BrowserContext* browser_context, | 67 content::BrowserContext* browser_context, |
51 const OfflinerPolicy* policy, | 68 const OfflinerPolicy* policy, |
52 OfflinePageModel* offline_page_model) | 69 OfflinePageModel* offline_page_model) |
53 : browser_context_(browser_context), | 70 : browser_context_(browser_context), |
54 offline_page_model_(offline_page_model), | 71 offline_page_model_(offline_page_model), |
55 is_low_end_device_(base::SysInfo::IsLowEndDevice()), | 72 is_low_end_device_(base::SysInfo::IsLowEndDevice()), |
56 save_state_(NONE), | 73 save_state_(NONE), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 completion_callback_.Run(request, Offliner::RequestStatus::LOADING_FAILED); | 241 completion_callback_.Run(request, Offliner::RequestStatus::LOADING_FAILED); |
225 ResetState(); | 242 ResetState(); |
226 } | 243 } |
227 } | 244 } |
228 | 245 |
229 void BackgroundLoaderOffliner::DidFinishNavigation( | 246 void BackgroundLoaderOffliner::DidFinishNavigation( |
230 content::NavigationHandle* navigation_handle) { | 247 content::NavigationHandle* navigation_handle) { |
231 // If there was an error of any kind (certificate, client, DNS, etc), | 248 // If there was an error of any kind (certificate, client, DNS, etc), |
232 // Mark as error page. Resetting here causes RecordNavigationMetrics to crash. | 249 // Mark as error page. Resetting here causes RecordNavigationMetrics to crash. |
233 if (navigation_handle->IsErrorPage()) { | 250 if (navigation_handle->IsErrorPage()) { |
234 // TODO(chili): we need to UMA this. | 251 RecordErrorCauseUMA(pending_request_->client_id(), |
| 252 navigation_handle->GetNetErrorCode()); |
235 switch (navigation_handle->GetNetErrorCode()) { | 253 switch (navigation_handle->GetNetErrorCode()) { |
236 case net::ERR_ACCESS_DENIED: | 254 case net::ERR_ACCESS_DENIED: |
237 case net::ERR_ADDRESS_INVALID: | 255 case net::ERR_ADDRESS_INVALID: |
238 case net::ERR_ADDRESS_UNREACHABLE: | 256 case net::ERR_ADDRESS_UNREACHABLE: |
239 case net::ERR_CERT_COMMON_NAME_INVALID: | 257 case net::ERR_CERT_COMMON_NAME_INVALID: |
240 case net::ERR_CERT_AUTHORITY_INVALID: | 258 case net::ERR_CERT_AUTHORITY_INVALID: |
241 case net::ERR_CERT_CONTAINS_ERRORS: | 259 case net::ERR_CERT_CONTAINS_ERRORS: |
242 case net::ERR_CERT_INVALID: | 260 case net::ERR_CERT_INVALID: |
243 case net::ERR_CONNECTION_FAILED: | 261 case net::ERR_CONNECTION_FAILED: |
244 case net::ERR_DISALLOWED_URL_SCHEME: | 262 case net::ERR_DISALLOWED_URL_SCHEME: |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 int64_t offline_id) { | 426 int64_t offline_id) { |
409 // If for some reason the request was reset during while waiting for callback | 427 // If for some reason the request was reset during while waiting for callback |
410 // ignore the completion callback. | 428 // ignore the completion callback. |
411 if (pending_request_ && pending_request_->request_id() != offline_id) | 429 if (pending_request_ && pending_request_->request_id() != offline_id) |
412 return; | 430 return; |
413 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); | 431 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); |
414 } | 432 } |
415 } // namespace offline_pages | 433 } // namespace offline_pages |
416 | 434 |
417 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); | 435 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); |
OLD | NEW |