Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Unified Diff: components/offline_pages/background/request_coordinator.cc

Issue 2234873004: Have the RequestCoordinator generate the offline_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile warning about const Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/background/request_coordinator.cc
diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc
index fe6e83232f8ec02c884ccf425d749dbe62e2e4d0..71e67fa4dcd29e7b76289782f6447db0869b110b 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
+#include "base/rand_util.h"
#include "base/time/time.h"
#include "components/offline_pages/background/offliner_factory.h"
#include "components/offline_pages/background/offliner_policy.h"
@@ -44,6 +45,13 @@ void RecordOfflinerResultUMA(const ClientId& client_id,
histogram->Add(static_cast<int>(request_status));
}
+// This should use the same algorithm as we use for OfflinePageItem, so the IDs
+// are similar.
+int64_t GenerateOfflineId() {
+ return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
+}
+
+
} // namespace
RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
@@ -77,12 +85,11 @@ bool RequestCoordinator::SavePageLater(
return false;
}
- // TODO(petewil): We need a robust scheme for allocating new IDs.
- static int64_t id = 0;
+ int64_t id = GenerateOfflineId();
// Build a SavePageRequest.
offline_pages::SavePageRequest request(
- id++, url, client_id, base::Time::Now(), user_requested);
+ id, url, client_id, base::Time::Now(), user_requested);
// Put the request on the request queue.
queue_->AddRequest(request,

Powered by Google App Engine
This is Rietveld 408576698