OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/browser/browser_context.h" | 5 #include "content/public/browser/browser_context.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <limits> | |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
12 #include "base/lazy_instance.h" | |
13 #include "base/rand_util.h" | |
11 #include "build/build_config.h" | 14 #include "build/build_config.h" |
12 | 15 |
13 #if !defined(OS_IOS) | 16 #if !defined(OS_IOS) |
17 #include "components/profile_service/profile_app.h" | |
14 #include "content/browser/download/download_manager_impl.h" | 18 #include "content/browser/download/download_manager_impl.h" |
15 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 19 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 20 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 21 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
18 #include "content/browser/push_messaging/push_messaging_router.h" | 22 #include "content/browser/push_messaging/push_messaging_router.h" |
19 #include "content/browser/storage_partition_impl_map.h" | 23 #include "content/browser/storage_partition_impl_map.h" |
20 #include "content/common/child_process_host_impl.h" | 24 #include "content/common/child_process_host_impl.h" |
21 #include "content/public/browser/blob_handle.h" | 25 #include "content/public/browser/blob_handle.h" |
22 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/browser/site_instance.h" | 28 #include "content/public/browser/site_instance.h" |
25 #include "net/cookies/cookie_store.h" | 29 #include "net/cookies/cookie_store.h" |
26 #include "net/ssl/channel_id_service.h" | 30 #include "net/ssl/channel_id_service.h" |
27 #include "net/ssl/channel_id_store.h" | 31 #include "net/ssl/channel_id_store.h" |
28 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
29 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
30 #include "storage/browser/database/database_tracker.h" | 34 #include "storage/browser/database/database_tracker.h" |
31 #include "storage/browser/fileapi/external_mount_points.h" | 35 #include "storage/browser/fileapi/external_mount_points.h" |
32 #endif // !OS_IOS | 36 #endif // !OS_IOS |
33 | 37 |
34 using base::UserDataAdapter; | 38 using base::UserDataAdapter; |
35 | 39 |
36 namespace content { | 40 namespace content { |
37 | 41 |
38 // Only ~BrowserContext() is needed on iOS. | 42 // Only ~BrowserContext() is needed on iOS. |
39 #if !defined(OS_IOS) | 43 #if !defined(OS_IOS) |
40 namespace { | 44 namespace { |
41 | 45 |
46 base::LazyInstance<std::set<uint32_t>> g_used_user_ids = | |
47 LAZY_INSTANCE_INITIALIZER; | |
48 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
| |
49 LAZY_INSTANCE_INITIALIZER; | |
50 | |
42 // Key names on BrowserContext. | 51 // Key names on BrowserContext. |
43 const char kDownloadManagerKeyName[] = "download_manager"; | 52 const char kDownloadManagerKeyName[] = "download_manager"; |
44 const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; | 53 const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; |
45 | 54 |
46 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
47 const char kMountPointsKey[] = "mount_points"; | 56 const char kMountPointsKey[] = "mount_points"; |
48 #endif // defined(OS_CHROMEOS) | 57 #endif // defined(OS_CHROMEOS) |
49 | 58 |
50 StoragePartitionImplMap* GetStoragePartitionMap( | 59 StoragePartitionImplMap* GetStoragePartitionMap( |
51 BrowserContext* browser_context) { | 60 BrowserContext* browser_context) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 make_scoped_refptr(indexed_db_context_impl))); | 323 make_scoped_refptr(indexed_db_context_impl))); |
315 } | 324 } |
316 } | 325 } |
317 | 326 |
318 void BrowserContext::SetDownloadManagerForTesting( | 327 void BrowserContext::SetDownloadManagerForTesting( |
319 BrowserContext* browser_context, | 328 BrowserContext* browser_context, |
320 DownloadManager* download_manager) { | 329 DownloadManager* download_manager) { |
321 SetDownloadManager(browser_context, download_manager); | 330 SetDownloadManager(browser_context, download_manager); |
322 } | 331 } |
323 | 332 |
333 void BrowserContext::InitializeProfileApplication( | |
jam
2016/02/27 01:34:45
nit: src/content has avoided "Profile". i do agree
| |
334 BrowserContext* browser_context) { | |
335 // 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
| |
336 // random number generator can only deal with unsigned 64 bit numbers, or | |
337 // *signed* 32 bit numbers. | |
338 | |
339 // Associate a random unsigned 32 bit number with |browser_context|. This | |
340 // becomes the mojo user id for this BrowserContext. | |
341 uint32_t new_id = base::RandInt(0, std::numeric_limits<int32_t>::max()); | |
342 while ((new_id == 0) || | |
343 (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end())) { | |
344 new_id = base::RandInt(0, std::numeric_limits<int32_t>::max()); | |
345 } | |
346 | |
347 g_used_user_ids.Get().insert(new_id); | |
348 g_context_to_user_id.Get().insert(std::make_pair(browser_context, new_id)); | |
349 | |
350 profile::ProfileApp::AssociateMojoUserIDWithProfileDir( | |
351 new_id, | |
352 browser_context->GetPath()); | |
353 } | |
354 | |
355 uint32_t BrowserContext::GetMojoUserIdFor(BrowserContext* browser_context) { | |
356 auto it = g_context_to_user_id.Get().find(browser_context); | |
357 CHECK(it != g_context_to_user_id.Get().end()); | |
358 return it->second; | |
359 } | |
360 | |
324 #endif // !OS_IOS | 361 #endif // !OS_IOS |
325 | 362 |
326 BrowserContext::~BrowserContext() { | 363 BrowserContext::~BrowserContext() { |
327 #if !defined(OS_IOS) | 364 #if !defined(OS_IOS) |
328 if (GetUserData(kDownloadManagerKeyName)) | 365 if (GetUserData(kDownloadManagerKeyName)) |
329 GetDownloadManager(this)->Shutdown(); | 366 GetDownloadManager(this)->Shutdown(); |
330 #endif | 367 #endif |
331 } | 368 } |
332 | 369 |
333 } // namespace content | 370 } // namespace content |
OLD | NEW |