Index: content/browser/background_fetch/background_fetch_data_manager.cc |
diff --git a/content/browser/background_fetch/background_fetch_data_manager.cc b/content/browser/background_fetch/background_fetch_data_manager.cc |
index b4d60f16581d34766878e12bf532aa8fb0175780..00ba5215638f77c0932c57777808189f481c8016 100644 |
--- a/content/browser/background_fetch/background_fetch_data_manager.cc |
+++ b/content/browser/background_fetch/background_fetch_data_manager.cc |
@@ -4,66 +4,46 @@ |
#include "content/browser/background_fetch/background_fetch_data_manager.h" |
+#include "base/guid.h" |
#include "base/memory/ptr_util.h" |
#include "content/browser/background_fetch/background_fetch_context.h" |
-#include "content/browser/background_fetch/background_fetch_request_info.h" |
namespace content { |
-BackgroundFetchDataManager::BackgroundFetchDataManager( |
- BackgroundFetchContext* background_fetch_context) |
- : background_fetch_context_(background_fetch_context) { |
- DCHECK(background_fetch_context_); |
- // TODO(harkness) Read from persistent storage and recreate requests. |
-} |
+BackgroundFetchDataManager::BackgroundFetchDataManager() = default; |
BackgroundFetchDataManager::~BackgroundFetchDataManager() = default; |
-std::unique_ptr<BackgroundFetchJobData> |
-BackgroundFetchDataManager::CreateRequest( |
- std::unique_ptr<BackgroundFetchJobInfo> job_info, |
- BackgroundFetchRequestInfos request_infos) { |
- BackgroundFetchRegistrationId registration_id( |
- job_info->service_worker_registration_id(), job_info->origin(), |
- job_info->tag()); |
- |
- // Ensure that this is not a duplicate request. |
- if (known_registrations_.find(registration_id) != |
- known_registrations_.end()) { |
- DVLOG(1) << "Origin " << job_info->origin() |
- << " has already created a batch request with tag " |
- << job_info->tag(); |
- // TODO(harkness) Figure out how to return errors like this. |
- return nullptr; |
+void BackgroundFetchDataManager::CreateRegistration( |
+ const BackgroundFetchRegistrationId& registration_id, |
+ const std::vector<ServiceWorkerFetchRequest>& requests, |
+ const BackgroundFetchOptions& options, |
+ CreateRegistrationCallback callback) { |
+ if (registrations_.find(registration_id) != registrations_.end()) { |
+ callback.Run(blink::mojom::BackgroundFetchError::DUPLICATED_TAG, |
+ nullptr /* job_data */); |
+ return; |
} |
- // Add the request to our maps and return a JobData to track the individual |
- // files in the request. |
- const std::string job_guid = job_info->guid(); |
- known_registrations_.insert(std::move(registration_id)); |
- WriteJobToStorage(std::move(job_info), std::move(request_infos)); |
- // TODO(harkness): Remove data when the job is complete. |
+ // Create a new BackgroundFetchJobData instance based on the available data. |
+ std::unique_ptr<BackgroundFetchJobData> job_data = |
+ base::MakeUnique<BackgroundFetchJobData>(BackgroundFetchRequestInfos()); |
- return base::MakeUnique<BackgroundFetchJobData>( |
- ReadRequestsFromStorage(job_guid)); |
+ callback.Run(blink::mojom::BackgroundFetchError::NONE, std::move(job_data)); |
} |
-void BackgroundFetchDataManager::WriteJobToStorage( |
- std::unique_ptr<BackgroundFetchJobInfo> job_info, |
- BackgroundFetchRequestInfos request_infos) { |
- // TODO(harkness): Replace these maps with actually writing to storage. |
- // TODO(harkness): Check for job_guid clash. |
- const std::string job_guid = job_info->guid(); |
- job_map_[job_guid] = std::move(job_info); |
- request_map_[job_guid] = std::move(request_infos); |
-} |
+void BackgroundFetchDataManager::DeleteRegistration( |
+ const BackgroundFetchRegistrationId& registration_id, |
+ DeleteRegistrationCallback callback) { |
+ auto iter = registrations_.find(registration_id); |
+ if (iter == registrations_.end()) { |
+ callback.Run(blink::mojom::BackgroundFetchError::INVALID_TAG); |
+ return; |
+ } |
+ |
+ registrations_.erase(iter); |
-// TODO(harkness): This should be changed to read (and cache) small numbers of |
-// the RequestInfos instead of returning all of them. |
-BackgroundFetchRequestInfos& |
-BackgroundFetchDataManager::ReadRequestsFromStorage( |
- const std::string& job_guid) { |
- return request_map_[job_guid]; |
+ callback.Run(blink::mojom::BackgroundFetchError::NONE); |
} |
} // namespace content |