| 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 "content/browser/background_fetch/background_fetch_job_controller.h" | 5 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 download_guid_map_.clear(); | 50 download_guid_map_.clear(); |
| 51 | 51 |
| 52 // TODO(harkness): Write final status to the DataManager. After this call, the | 52 // TODO(harkness): Write final status to the DataManager. After this call, the |
| 53 // |data_manager_| is no longer valid. | 53 // |data_manager_| is no longer valid. |
| 54 data_manager_ = nullptr; | 54 data_manager_ = nullptr; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void BackgroundFetchJobController::StartProcessing() { | 57 void BackgroundFetchJobController::StartProcessing() { |
| 58 DCHECK(data_manager_); | 58 DCHECK(data_manager_); |
| 59 | 59 |
| 60 state_ = State::FETCHING; |
| 61 |
| 60 const BackgroundFetchRequestInfo& fetch_request = | 62 const BackgroundFetchRequestInfo& fetch_request = |
| 61 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_); | 63 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_); |
| 62 ProcessRequest(fetch_request); | 64 ProcessRequest(fetch_request); |
| 63 | 65 |
| 64 // Currently, this processes a single request at a time. | 66 // Currently, this processes a single request at a time. |
| 65 } | 67 } |
| 66 | 68 |
| 67 void BackgroundFetchJobController::UpdateUI(const std::string& title) { | 69 void BackgroundFetchJobController::UpdateUI(const std::string& title) { |
| 68 // TODO(harkness): Update the user interface with |title|. | 70 // TODO(harkness): Update the user interface with |title|. |
| 69 } | 71 } |
| 70 | 72 |
| 71 void BackgroundFetchJobController::Abort() { | 73 void BackgroundFetchJobController::Abort() { |
| 72 // TODO(harkness): Abort all in-progress downloads. | 74 // TODO(harkness): Abort all in-progress downloads. |
| 73 | 75 |
| 74 std::move(completed_callback_) | 76 state_ = State::ABORTED; |
| 75 .Run(registration_id_, true /* aborted_by_developer */); | 77 |
| 78 std::move(completed_callback_).Run(this); |
| 76 } | 79 } |
| 77 | 80 |
| 78 void BackgroundFetchJobController::DownloadStarted( | 81 void BackgroundFetchJobController::DownloadStarted( |
| 79 const std::string& request_guid, | 82 const std::string& request_guid, |
| 80 DownloadItem* item, | 83 DownloadItem* item, |
| 81 DownloadInterruptReason reason) { | 84 DownloadInterruptReason reason) { |
| 82 // Start observing the DownloadItem. No need to store the pointer because it | 85 // Start observing the DownloadItem. No need to store the pointer because it |
| 83 // can be retrieved from the DownloadManager. | 86 // can be retrieved from the DownloadManager. |
| 84 item->AddObserver(this); | 87 item->AddObserver(this); |
| 85 download_guid_map_[item->GetGuid()] = request_guid; | 88 download_guid_map_[item->GetGuid()] = request_guid; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 107 item->GetReceivedBytes()); | 110 item->GetReceivedBytes()); |
| 108 // Fall through. | 111 // Fall through. |
| 109 case DownloadItem::DownloadState::CANCELLED: | 112 case DownloadItem::DownloadState::CANCELLED: |
| 110 // TODO(harkness): Tell the notification service to update the download | 113 // TODO(harkness): Tell the notification service to update the download |
| 111 // notification. | 114 // notification. |
| 112 | 115 |
| 113 if (requests_remaining) { | 116 if (requests_remaining) { |
| 114 ProcessRequest( | 117 ProcessRequest( |
| 115 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_)); | 118 data_manager_->GetNextBackgroundFetchRequestInfo(job_guid_)); |
| 116 } else if (data_manager_->IsComplete(job_guid_)) { | 119 } else if (data_manager_->IsComplete(job_guid_)) { |
| 117 std::move(completed_callback_) | 120 state_ = State::COMPLETED; |
| 118 .Run(registration_id_, false /* aborted_by_developer */); | 121 std::move(completed_callback_).Run(this); |
| 119 } | 122 } |
| 120 break; | 123 break; |
| 121 case DownloadItem::DownloadState::INTERRUPTED: | 124 case DownloadItem::DownloadState::INTERRUPTED: |
| 122 // TODO(harkness): Just update the notification that it is paused. | 125 // TODO(harkness): Just update the notification that it is paused. |
| 123 break; | 126 break; |
| 124 case DownloadItem::DownloadState::IN_PROGRESS: | 127 case DownloadItem::DownloadState::IN_PROGRESS: |
| 125 // TODO(harkness): If the download was previously paused, this should now | 128 // TODO(harkness): If the download was previously paused, this should now |
| 126 // unpause the notification. | 129 // unpause the notification. |
| 127 break; | 130 break; |
| 128 case DownloadItem::DownloadState::MAX_DOWNLOAD_STATE: | 131 case DownloadItem::DownloadState::MAX_DOWNLOAD_STATE: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 147 fetch_request.GetURL(), storage_partition_->GetURLRequestContext())); | 150 fetch_request.GetURL(), storage_partition_->GetURLRequestContext())); |
| 148 params->set_callback( | 151 params->set_callback( |
| 149 base::Bind(&BackgroundFetchJobController::DownloadStarted, | 152 base::Bind(&BackgroundFetchJobController::DownloadStarted, |
| 150 weak_ptr_factory_.GetWeakPtr(), fetch_request.guid())); | 153 weak_ptr_factory_.GetWeakPtr(), fetch_request.guid())); |
| 151 | 154 |
| 152 BrowserContext::GetDownloadManager(browser_context_) | 155 BrowserContext::GetDownloadManager(browser_context_) |
| 153 ->DownloadUrl(std::move(params)); | 156 ->DownloadUrl(std::move(params)); |
| 154 } | 157 } |
| 155 | 158 |
| 156 } // namespace content | 159 } // namespace content |
| OLD | NEW |