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

Unified Diff: content/browser/browser_context.cc

Issue 1770533002: Change userid from a uint32_t to a string guid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@33connector
Patch Set: . Created 4 years, 9 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: content/browser/browser_context.cc
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 21817d6af6d52fd63471b086014720f97b1178fd..10db382998c3675576aa9cbdb49f805c19fe317e 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -10,6 +10,7 @@
#include <limits>
#include <utility>
+#include "base/guid.h"
#include "base/lazy_instance.h"
#include "base/rand_util.h"
#include "build/build_config.h"
@@ -44,9 +45,9 @@ namespace content {
#if !defined(OS_IOS)
namespace {
-base::LazyInstance<std::set<uint32_t>> g_used_user_ids =
+base::LazyInstance<std::set<std::string>> g_used_user_ids =
LAZY_INSTANCE_INITIALIZER;
-base::LazyInstance<std::vector<std::pair<BrowserContext*, uint32_t>>>
+base::LazyInstance<std::vector<std::pair<BrowserContext*, std::string>>>
g_context_to_user_id = LAZY_INSTANCE_INITIALIZER;
// Key names on BrowserContext.
@@ -336,13 +337,10 @@ void BrowserContext::SetDownloadManagerForTesting(
void BrowserContext::Initialize(
BrowserContext* browser_context,
const base::FilePath& path) {
- // Associate a random unsigned 32 bit number with |browser_context|. This
- // becomes the mojo user id for this BrowserContext.
- uint32_t new_id = static_cast<uint32_t>(base::RandGenerator(UINT32_MAX));
- while ((new_id == 0) ||
- (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end())) {
- new_id = static_cast<uint32_t>(base::RandGenerator(UINT32_MAX));
- }
+ // Generate a GUID for |browser_context| to use as the Mojo user id.
+ std::string new_id = base::GenerateGUID();
+ while (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end())
+ new_id = base::GenerateGUID();
g_used_user_ids.Get().insert(new_id);
g_context_to_user_id.Get().push_back(std::make_pair(browser_context, new_id));
@@ -352,7 +350,8 @@ void BrowserContext::Initialize(
new base::SupportsUserData::Data);
}
-uint32_t BrowserContext::GetMojoUserIdFor(BrowserContext* browser_context) {
+const std::string& BrowserContext::GetMojoUserIdFor(
+ BrowserContext* browser_context) {
CHECK(browser_context->GetUserData(kMojoWasInitialized))
<< "Attempting to get the mojo user id for a BrowserContext that was "
<< "never Initialize()ed.";
@@ -360,7 +359,7 @@ uint32_t BrowserContext::GetMojoUserIdFor(BrowserContext* browser_context) {
auto it = std::find_if(
g_context_to_user_id.Get().begin(),
g_context_to_user_id.Get().end(),
- [&browser_context](const std::pair<BrowserContext*, uint32_t>& p) {
+ [&browser_context](const std::pair<BrowserContext*, std::string>& p) {
return p.first == browser_context; });
CHECK(it != g_context_to_user_id.Get().end());
return it->second;
« no previous file with comments | « components/resource_provider/resource_provider_app.cc ('k') | content/browser/frame_host/frame_mojo_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698