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 <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/guid.h" | 13 #include "base/guid.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "components/profile_service/profile_app.h" | 17 #include "components/profile_service/user_id_map.h" |
18 #include "content/browser/download/download_manager_impl.h" | 18 #include "content/browser/download/download_manager_impl.h" |
19 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 19 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
20 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 20 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
21 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 21 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
22 #include "content/browser/push_messaging/push_messaging_router.h" | 22 #include "content/browser/push_messaging/push_messaging_router.h" |
23 #include "content/browser/storage_partition_impl_map.h" | 23 #include "content/browser/storage_partition_impl_map.h" |
24 #include "content/common/child_process_host_impl.h" | 24 #include "content/common/child_process_host_impl.h" |
25 #include "content/public/browser/blob_handle.h" | 25 #include "content/public/browser/blob_handle.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 BrowserContext* browser_context, | 333 BrowserContext* browser_context, |
334 const base::FilePath& path) { | 334 const base::FilePath& path) { |
335 // Generate a GUID for |browser_context| to use as the Mojo user id. | 335 // Generate a GUID for |browser_context| to use as the Mojo user id. |
336 std::string new_id = base::GenerateGUID(); | 336 std::string new_id = base::GenerateGUID(); |
337 while (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end()) | 337 while (g_used_user_ids.Get().find(new_id) != g_used_user_ids.Get().end()) |
338 new_id = base::GenerateGUID(); | 338 new_id = base::GenerateGUID(); |
339 | 339 |
340 g_used_user_ids.Get().insert(new_id); | 340 g_used_user_ids.Get().insert(new_id); |
341 g_context_to_user_id.Get().push_back(std::make_pair(browser_context, new_id)); | 341 g_context_to_user_id.Get().push_back(std::make_pair(browser_context, new_id)); |
342 | 342 |
343 profile::ProfileApp::AssociateMojoUserIDWithProfileDir(new_id, path); | 343 profile::AssociateMojoUserIDWithProfileDir(new_id, path); |
344 browser_context->SetUserData(kMojoWasInitialized, | 344 browser_context->SetUserData(kMojoWasInitialized, |
345 new base::SupportsUserData::Data); | 345 new base::SupportsUserData::Data); |
346 } | 346 } |
347 | 347 |
348 const std::string& BrowserContext::GetMojoUserIdFor( | 348 const std::string& BrowserContext::GetMojoUserIdFor( |
349 BrowserContext* browser_context) { | 349 BrowserContext* browser_context) { |
350 CHECK(browser_context->GetUserData(kMojoWasInitialized)) | 350 CHECK(browser_context->GetUserData(kMojoWasInitialized)) |
351 << "Attempting to get the mojo user id for a BrowserContext that was " | 351 << "Attempting to get the mojo user id for a BrowserContext that was " |
352 << "never Initialize()ed."; | 352 << "never Initialize()ed."; |
353 | 353 |
354 auto it = std::find_if( | 354 auto it = std::find_if( |
355 g_context_to_user_id.Get().begin(), | 355 g_context_to_user_id.Get().begin(), |
356 g_context_to_user_id.Get().end(), | 356 g_context_to_user_id.Get().end(), |
357 [&browser_context](const std::pair<BrowserContext*, std::string>& p) { | 357 [&browser_context](const std::pair<BrowserContext*, std::string>& p) { |
358 return p.first == browser_context; }); | 358 return p.first == browser_context; }); |
359 CHECK(it != g_context_to_user_id.Get().end()); | 359 CHECK(it != g_context_to_user_id.Get().end()); |
360 return it->second; | 360 return it->second; |
361 } | 361 } |
362 | 362 |
363 BrowserContext::~BrowserContext() { | 363 BrowserContext::~BrowserContext() { |
364 CHECK(GetUserData(kMojoWasInitialized)) | 364 CHECK(GetUserData(kMojoWasInitialized)) |
365 << "Attempting to destroy a BrowserContext that never called " | 365 << "Attempting to destroy a BrowserContext that never called " |
366 << "Initialize()"; | 366 << "Initialize()"; |
367 | 367 |
368 if (GetUserData(kDownloadManagerKeyName)) | 368 if (GetUserData(kDownloadManagerKeyName)) |
369 GetDownloadManager(this)->Shutdown(); | 369 GetDownloadManager(this)->Shutdown(); |
370 } | 370 } |
371 | 371 |
372 } // namespace content | 372 } // namespace content |
OLD | NEW |