| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 offliner_timeout_(base::TimeDelta::FromSeconds( | 62 offliner_timeout_(base::TimeDelta::FromSeconds( |
| 63 policy_->GetSinglePageTimeLimitInSeconds())), | 63 policy_->GetSinglePageTimeLimitInSeconds())), |
| 64 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
| 65 DCHECK(policy_ != nullptr); | 65 DCHECK(policy_ != nullptr); |
| 66 picker_.reset(new RequestPicker(queue_.get(), policy_.get())); | 66 picker_.reset(new RequestPicker(queue_.get(), policy_.get())); |
| 67 } | 67 } |
| 68 | 68 |
| 69 RequestCoordinator::~RequestCoordinator() {} | 69 RequestCoordinator::~RequestCoordinator() {} |
| 70 | 70 |
| 71 bool RequestCoordinator::SavePageLater( | 71 bool RequestCoordinator::SavePageLater( |
| 72 const GURL& url, const ClientId& client_id, bool was_user_requested) { | 72 const GURL& url, const ClientId& client_id, bool user_requested) { |
| 73 DVLOG(2) << "URL is " << url << " " << __func__; | 73 DVLOG(2) << "URL is " << url << " " << __func__; |
| 74 | 74 |
| 75 if (!OfflinePageModel::CanSaveURL(url)) { | 75 if (!OfflinePageModel::CanSaveURL(url)) { |
| 76 DVLOG(1) << "Not able to save page for requested url: " << url; | 76 DVLOG(1) << "Not able to save page for requested url: " << url; |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 | 79 |
| 80 // TODO(petewil): We need a robust scheme for allocating new IDs. | 80 // TODO(petewil): We need a robust scheme for allocating new IDs. |
| 81 static int64_t id = 0; | 81 static int64_t id = 0; |
| 82 | 82 |
| 83 // Build a SavePageRequest. | 83 // Build a SavePageRequest. |
| 84 offline_pages::SavePageRequest request( | 84 offline_pages::SavePageRequest request( |
| 85 id++, url, client_id, base::Time::Now(), was_user_requested); | 85 id++, url, client_id, base::Time::Now(), user_requested); |
| 86 | 86 |
| 87 // Put the request on the request queue. | 87 // Put the request on the request queue. |
| 88 queue_->AddRequest(request, | 88 queue_->AddRequest(request, |
| 89 base::Bind(&RequestCoordinator::AddRequestResultCallback, | 89 base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| 90 weak_ptr_factory_.GetWeakPtr())); | 90 weak_ptr_factory_.GetWeakPtr())); |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| 93 void RequestCoordinator::GetQueuedRequests( | 93 void RequestCoordinator::GetQueuedRequests( |
| 94 const std::string& client_namespace, | 94 const std::string& client_namespace, |
| 95 const QueuedRequestCallback& callback) { | 95 const QueuedRequestCallback& callback) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 return trigger_conditions; | 358 return trigger_conditions; |
| 359 } | 359 } |
| 360 | 360 |
| 361 void RequestCoordinator::GetOffliner() { | 361 void RequestCoordinator::GetOffliner() { |
| 362 if (!offliner_) { | 362 if (!offliner_) { |
| 363 offliner_ = factory_->GetOffliner(policy_.get()); | 363 offliner_ = factory_->GetOffliner(policy_.get()); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace offline_pages | 367 } // namespace offline_pages |
| OLD | NEW |