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

Unified Diff: content/browser/browser_context.cc

Issue 1741953002: mojo: Sketch a profile application. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Maybe fix mojom dependencies Created 4 years, 10 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 81c554b3025e3d4c647de908b27cc124fbe221da..4f4bc2fcce29ee7ad0b1ea2517ca610a5ea29c32 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -6,11 +6,15 @@
#include <stddef.h>
#include <stdint.h>
+#include <limits>
#include <utility>
+#include "base/lazy_instance.h"
+#include "base/rand_util.h"
#include "build/build_config.h"
#if !defined(OS_IOS)
+#include "components/profile_service/profile_app.h"
#include "content/browser/download/download_manager_impl.h"
#include "content/browser/fileapi/chrome_blob_storage_context.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
@@ -39,6 +43,11 @@ namespace content {
#if !defined(OS_IOS)
namespace {
+base::LazyInstance<std::set<uint32_t>> g_used_user_ids =
+ LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<std::map<BrowserContext*, uint32_t> > g_context_to_user_id =
jam 2016/02/27 01:34:45 nit: map is overkill when we know the median value
+ LAZY_INSTANCE_INITIALIZER;
+
// Key names on BrowserContext.
const char kDownloadManagerKeyName[] = "download_manager";
const char kStoragePartitionMapKeyName[] = "content_storage_partition_map";
@@ -321,6 +330,34 @@ void BrowserContext::SetDownloadManagerForTesting(
SetDownloadManager(browser_context, download_manager);
}
+void BrowserContext::InitializeProfileApplication(
jam 2016/02/27 01:34:45 nit: src/content has avoided "Profile". i do agree
+ BrowserContext* browser_context) {
+ // TODO(erg): The userids should be 64 bit numbers, not 32 bit numbers. Our
jam 2016/02/27 01:34:45 I'm not following the comment. What exaclty is sto
Elliot Glaysher 2016/02/29 23:04:13 Rephrased the comment to point out that mojo useri
+ // random number generator can only deal with unsigned 64 bit numbers, or
+ // *signed* 32 bit numbers.
+
+ // Associate a random unsigned 32 bit number with |browser_context|. This
+ // becomes the mojo user id for this BrowserContext.
+ uint32_t new_id = base::RandInt(0, std::numeric_limits<int32_t>::max());
+ while ((new_id == 0) ||
+ (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end())) {
+ new_id = base::RandInt(0, std::numeric_limits<int32_t>::max());
+ }
+
+ g_used_user_ids.Get().insert(new_id);
+ g_context_to_user_id.Get().insert(std::make_pair(browser_context, new_id));
+
+ profile::ProfileApp::AssociateMojoUserIDWithProfileDir(
+ new_id,
+ browser_context->GetPath());
+}
+
+uint32_t BrowserContext::GetMojoUserIdFor(BrowserContext* browser_context) {
+ auto it = g_context_to_user_id.Get().find(browser_context);
+ CHECK(it != g_context_to_user_id.Get().end());
+ return it->second;
+}
+
#endif // !OS_IOS
BrowserContext::~BrowserContext() {

Powered by Google App Engine
This is Rietveld 408576698