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