Chromium Code Reviews| 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 "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 offliner_timeout_(base::TimeDelta::FromSeconds( | 98 offliner_timeout_(base::TimeDelta::FromSeconds( |
| 99 policy_->GetSinglePageTimeLimitInSeconds())), | 99 policy_->GetSinglePageTimeLimitInSeconds())), |
| 100 weak_ptr_factory_(this) { | 100 weak_ptr_factory_(this) { |
| 101 DCHECK(policy_ != nullptr); | 101 DCHECK(policy_ != nullptr); |
| 102 picker_.reset( | 102 picker_.reset( |
| 103 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); | 103 new RequestPicker(queue_.get(), policy_.get(), this, &event_logger_)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 RequestCoordinator::~RequestCoordinator() {} | 106 RequestCoordinator::~RequestCoordinator() {} |
| 107 | 107 |
| 108 bool RequestCoordinator::SavePageLater( | 108 int64_t RequestCoordinator::SavePageLater(const GURL& url, |
| 109 const GURL& url, const ClientId& client_id, bool user_requested) { | 109 const ClientId& client_id, |
| 110 bool user_requested, | |
| 111 RequestAvailability availability) { | |
| 110 DVLOG(2) << "URL is " << url << " " << __func__; | 112 DVLOG(2) << "URL is " << url << " " << __func__; |
| 111 | 113 |
| 112 if (!OfflinePageModel::CanSaveURL(url)) { | 114 if (!OfflinePageModel::CanSaveURL(url)) { |
| 113 DVLOG(1) << "Not able to save page for requested url: " << url; | 115 DVLOG(1) << "Not able to save page for requested url: " << url; |
| 114 return false; | 116 return 0L; |
| 115 } | 117 } |
| 116 | 118 |
| 117 int64_t id = GenerateOfflineId(); | 119 int64_t id = GenerateOfflineId(); |
| 118 | 120 |
|
Dmitry Titov
2016/10/05 22:28:19
Lets add "DCHECK(id > 0);" here, just to be sure t
Pete Williamson
2016/10/05 22:57:46
Added DCHECK(id != 0) instead, since we use an int
| |
| 119 // Build a SavePageRequest. | 121 // Build a SavePageRequest. |
| 120 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), | 122 offline_pages::SavePageRequest request(id, url, client_id, base::Time::Now(), |
| 121 user_requested); | 123 user_requested); |
| 122 | 124 |
| 123 // Put the request on the request queue. | 125 // Put the request on the request queue. |
| 124 queue_->AddRequest(request, | 126 queue_->AddRequest(request, |
| 125 base::Bind(&RequestCoordinator::AddRequestResultCallback, | 127 base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| 126 weak_ptr_factory_.GetWeakPtr())); | 128 weak_ptr_factory_.GetWeakPtr())); |
| 127 return true; | 129 return id; |
| 128 } | 130 } |
| 129 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { | 131 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { |
| 130 // Get all matching requests from the request queue, send them to our | 132 // Get all matching requests from the request queue, send them to our |
| 131 // callback. We bind the namespace and callback to the front of the callback | 133 // callback. We bind the namespace and callback to the front of the callback |
| 132 // param set. | 134 // param set. |
| 133 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback, | 135 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback, |
| 134 weak_ptr_factory_.GetWeakPtr(), callback)); | 136 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 135 } | 137 } |
| 136 | 138 |
| 137 void RequestCoordinator::GetQueuedRequestsCallback( | 139 void RequestCoordinator::GetQueuedRequestsCallback( |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 case Offliner::RequestStatus::PRERENDERING_FAILED: | 558 case Offliner::RequestStatus::PRERENDERING_FAILED: |
| 557 // No further processing in this service window. | 559 // No further processing in this service window. |
| 558 break; | 560 break; |
| 559 default: | 561 default: |
| 560 // Make explicit choice about new status codes that actually reach here. | 562 // Make explicit choice about new status codes that actually reach here. |
| 561 // Their default is no further processing in this service window. | 563 // Their default is no further processing in this service window. |
| 562 NOTREACHED(); | 564 NOTREACHED(); |
| 563 } | 565 } |
| 564 } | 566 } |
| 565 | 567 |
| 568 void RequestCoordinator::MakeAvailableToOffliner(int64_t request_id) {} | |
| 569 | |
| 570 void RequestCoordinator::MarkRequestCompleted(int64_t request_id) {} | |
| 571 | |
| 566 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( | 572 const Scheduler::TriggerConditions RequestCoordinator::GetTriggerConditions( |
| 567 const bool user_requested) { | 573 const bool user_requested) { |
| 568 return Scheduler::TriggerConditions( | 574 return Scheduler::TriggerConditions( |
| 569 policy_->PowerRequired(user_requested), | 575 policy_->PowerRequired(user_requested), |
| 570 policy_->BatteryPercentageRequired(user_requested), | 576 policy_->BatteryPercentageRequired(user_requested), |
| 571 policy_->UnmeteredNetworkRequired(user_requested)); | 577 policy_->UnmeteredNetworkRequired(user_requested)); |
| 572 } | 578 } |
| 573 | 579 |
| 574 void RequestCoordinator::AddObserver(Observer* observer) { | 580 void RequestCoordinator::AddObserver(Observer* observer) { |
| 575 DCHECK(observer); | 581 DCHECK(observer); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 597 if (!offliner_) { | 603 if (!offliner_) { |
| 598 offliner_ = factory_->GetOffliner(policy_.get()); | 604 offliner_ = factory_->GetOffliner(policy_.get()); |
| 599 } | 605 } |
| 600 } | 606 } |
| 601 | 607 |
| 602 void RequestCoordinator::Shutdown() { | 608 void RequestCoordinator::Shutdown() { |
| 603 network_quality_estimator_ = nullptr; | 609 network_quality_estimator_ = nullptr; |
| 604 } | 610 } |
| 605 | 611 |
| 606 } // namespace offline_pages | 612 } // namespace offline_pages |
| OLD | NEW |