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

Side by Side 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: Fix the DownloadManagerImplTests. 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 unified diff | Download patch
OLDNEW
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 <algorithm>
10 #include <limits>
9 #include <utility> 11 #include <utility>
10 12
13 #include "base/lazy_instance.h"
14 #include "base/rand_util.h"
11 #include "build/build_config.h" 15 #include "build/build_config.h"
12 16
13 #if !defined(OS_IOS) 17 #if !defined(OS_IOS)
18 #include "components/profile_service/profile_app.h"
14 #include "content/browser/download/download_manager_impl.h" 19 #include "content/browser/download/download_manager_impl.h"
15 #include "content/browser/fileapi/chrome_blob_storage_context.h" 20 #include "content/browser/fileapi/chrome_blob_storage_context.h"
16 #include "content/browser/indexed_db/indexed_db_context_impl.h" 21 #include "content/browser/indexed_db/indexed_db_context_impl.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 22 #include "content/browser/loader/resource_dispatcher_host_impl.h"
18 #include "content/browser/push_messaging/push_messaging_router.h" 23 #include "content/browser/push_messaging/push_messaging_router.h"
19 #include "content/browser/storage_partition_impl_map.h" 24 #include "content/browser/storage_partition_impl_map.h"
20 #include "content/common/child_process_host_impl.h" 25 #include "content/common/child_process_host_impl.h"
21 #include "content/public/browser/blob_handle.h" 26 #include "content/public/browser/blob_handle.h"
22 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/content_browser_client.h" 28 #include "content/public/browser/content_browser_client.h"
24 #include "content/public/browser/site_instance.h" 29 #include "content/public/browser/site_instance.h"
25 #include "net/cookies/cookie_store.h" 30 #include "net/cookies/cookie_store.h"
26 #include "net/ssl/channel_id_service.h" 31 #include "net/ssl/channel_id_service.h"
27 #include "net/ssl/channel_id_store.h" 32 #include "net/ssl/channel_id_store.h"
28 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
29 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
30 #include "storage/browser/database/database_tracker.h" 35 #include "storage/browser/database/database_tracker.h"
31 #include "storage/browser/fileapi/external_mount_points.h" 36 #include "storage/browser/fileapi/external_mount_points.h"
32 #endif // !OS_IOS 37 #endif // !OS_IOS
33 38
34 using base::UserDataAdapter; 39 using base::UserDataAdapter;
35 40
36 namespace content { 41 namespace content {
37 42
38 // Only ~BrowserContext() is needed on iOS. 43 // Only ~BrowserContext() is needed on iOS.
39 #if !defined(OS_IOS) 44 #if !defined(OS_IOS)
40 namespace { 45 namespace {
41 46
47 base::LazyInstance<std::set<uint32_t>> g_used_user_ids =
48 LAZY_INSTANCE_INITIALIZER;
49 base::LazyInstance<std::vector<std::pair<BrowserContext*, uint32_t>>>
50 g_context_to_user_id = LAZY_INSTANCE_INITIALIZER;
51
42 // Key names on BrowserContext. 52 // Key names on BrowserContext.
43 const char kDownloadManagerKeyName[] = "download_manager"; 53 const char kDownloadManagerKeyName[] = "download_manager";
44 const char kStoragePartitionMapKeyName[] = "content_storage_partition_map"; 54 const char kStoragePartitionMapKeyName[] = "content_storage_partition_map";
45 55
46 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
47 const char kMountPointsKey[] = "mount_points"; 57 const char kMountPointsKey[] = "mount_points";
48 #endif // defined(OS_CHROMEOS) 58 #endif // defined(OS_CHROMEOS)
49 59
50 StoragePartitionImplMap* GetStoragePartitionMap( 60 StoragePartitionImplMap* GetStoragePartitionMap(
51 BrowserContext* browser_context) { 61 BrowserContext* browser_context) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 make_scoped_refptr(indexed_db_context_impl))); 324 make_scoped_refptr(indexed_db_context_impl)));
315 } 325 }
316 } 326 }
317 327
318 void BrowserContext::SetDownloadManagerForTesting( 328 void BrowserContext::SetDownloadManagerForTesting(
319 BrowserContext* browser_context, 329 BrowserContext* browser_context,
320 DownloadManager* download_manager) { 330 DownloadManager* download_manager) {
321 SetDownloadManager(browser_context, download_manager); 331 SetDownloadManager(browser_context, download_manager);
322 } 332 }
323 333
334 void BrowserContext::Initialize(
335 BrowserContext* browser_context,
336 const base::FilePath& path) {
337 // Associate a random unsigned 32 bit number with |browser_context|. This
338 // becomes the mojo user id for this BrowserContext.
339 uint32_t new_id = static_cast<uint32_t>(base::RandGenerator(UINT32_MAX));
340 while ((new_id == 0) ||
341 (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end())) {
342 new_id = static_cast<uint32_t>(base::RandGenerator(UINT32_MAX));
343 }
344
345 g_used_user_ids.Get().insert(new_id);
346 g_context_to_user_id.Get().push_back(std::make_pair(browser_context, new_id));
347
348 profile::ProfileApp::AssociateMojoUserIDWithProfileDir(new_id, path);
349 browser_context->initialize_called_ = true;
350 }
351
352 uint32_t BrowserContext::GetMojoUserIdFor(BrowserContext* browser_context) {
353 CHECK(browser_context->initialize_called_)
354 << "Attempting to get the mojo user id for a BrowserContext that was "
355 << "never Initialize()ed.";
356
357 auto it = std::find_if(
358 g_context_to_user_id.Get().begin(),
359 g_context_to_user_id.Get().end(),
360 [&browser_context](const std::pair<BrowserContext*, uint32_t>& p) {
361 return p.first == browser_context; });
362 CHECK(it != g_context_to_user_id.Get().end());
363 return it->second;
364 }
365
324 #endif // !OS_IOS 366 #endif // !OS_IOS
325 367
368 BrowserContext::BrowserContext()
369 : initialize_called_(false) {
370 }
371
326 BrowserContext::~BrowserContext() { 372 BrowserContext::~BrowserContext() {
373 CHECK(initialize_called_)
374 << "Attempting to destroy a BrowserContext that never called "
375 << "Initialize()";
376
327 #if !defined(OS_IOS) 377 #if !defined(OS_IOS)
328 if (GetUserData(kDownloadManagerKeyName)) 378 if (GetUserData(kDownloadManagerKeyName))
329 GetDownloadManager(this)->Shutdown(); 379 GetDownloadManager(this)->Shutdown();
330 #endif 380 #endif
331 } 381 }
332 382
333 } // namespace content 383 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698