| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/offline_pages/core/prefetch/get_operation_request.h" | 5 #include "components/offline_pages/core/prefetch/get_operation_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/offline_pages/core/prefetch/prefetch_proto_utils.h" | 10 #include "components/offline_pages/core/prefetch/prefetch_proto_utils.h" |
| 11 #include "components/offline_pages/core/prefetch/prefetch_request_fetcher.h" | 11 #include "components/offline_pages/core/prefetch/prefetch_request_fetcher.h" |
| 12 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace offline_pages { | 15 namespace offline_pages { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const char kGetOperationURLPath[] = "v1/operations/"; | 18 const char kGetOperationURLPath[] = "v1/"; |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 GetOperationRequest::GetOperationRequest( | 21 GetOperationRequest::GetOperationRequest( |
| 22 const std::string& name, | 22 const std::string& name, |
| 23 version_info::Channel channel, | 23 version_info::Channel channel, |
| 24 net::URLRequestContextGetter* request_context_getter, | 24 net::URLRequestContextGetter* request_context_getter, |
| 25 const PrefetchRequestFinishedCallback& callback) | 25 const PrefetchRequestFinishedCallback& callback) |
| 26 : callback_(callback) { | 26 : callback_(callback) { |
| 27 std::string path(kGetOperationURLPath); | 27 std::string path(kGetOperationURLPath); |
| 28 path += name; | 28 path += name; |
| 29 fetcher_ = PrefetchRequestFetcher::CreateForGet( | 29 fetcher_ = PrefetchRequestFetcher::CreateForGet( |
| 30 path, channel, request_context_getter, | 30 path, channel, request_context_getter, |
| 31 base::Bind(&GetOperationRequest::OnCompleted, | 31 base::Bind(&GetOperationRequest::OnCompleted, |
| 32 // Fetcher is owned by this instance. | 32 // Fetcher is owned by this instance. |
| 33 base::Unretained(this))); | 33 base::Unretained(this))); |
| 34 } | 34 } |
| 35 | 35 |
| 36 GetOperationRequest::~GetOperationRequest() {} | 36 GetOperationRequest::~GetOperationRequest() {} |
| 37 | 37 |
| 38 void GetOperationRequest::OnCompleted(PrefetchRequestStatus status, | 38 void GetOperationRequest::OnCompleted(PrefetchRequestStatus status, |
| 39 const std::string& data) { | 39 const std::string& data) { |
| 40 if (status != PrefetchRequestStatus::SUCCESS) { | 40 if (status != PrefetchRequestStatus::SUCCESS) { |
| 41 callback_.Run(status, std::vector<RenderPageInfo>()); | 41 callback_.Run(status, std::string(), std::vector<RenderPageInfo>()); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 std::vector<RenderPageInfo> pages; | 45 std::vector<RenderPageInfo> pages; |
| 46 if (!ParseOperationResponse(data, &pages)) { | 46 std::string operation_name = ParseOperationResponse(data, &pages); |
| 47 if (operation_name.empty()) { |
| 47 callback_.Run(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF, | 48 callback_.Run(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF, |
| 48 std::vector<RenderPageInfo>()); | 49 std::string(), std::vector<RenderPageInfo>()); |
| 49 return; | 50 return; |
| 50 } | 51 } |
| 51 | 52 |
| 52 callback_.Run(PrefetchRequestStatus::SUCCESS, pages); | 53 callback_.Run(PrefetchRequestStatus::SUCCESS, operation_name, pages); |
| 53 } | 54 } |
| 54 | 55 |
| 55 } // offline_pages | 56 } // offline_pages |
| OLD | NEW |