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 <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
| 15 #include "base/base64.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/guid.h" | 17 #include "base/guid.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 19 #include "base/logging.h" |
18 #include "base/macros.h" | 20 #include "base/macros.h" |
19 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
21 #include "build/build_config.h" | 23 #include "build/build_config.h" |
22 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 24 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
23 #include "content/browser/download/download_manager_impl.h" | 25 #include "content/browser/download/download_manager_impl.h" |
24 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 26 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
25 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 27 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
26 #include "content/browser/push_messaging/push_messaging_router.h" | 28 #include "content/browser/push_messaging/push_messaging_router.h" |
27 #include "content/browser/storage_partition_impl_map.h" | 29 #include "content/browser/storage_partition_impl_map.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // static | 500 // static |
499 ServiceManagerConnection* BrowserContext::GetServiceManagerConnectionFor( | 501 ServiceManagerConnection* BrowserContext::GetServiceManagerConnectionFor( |
500 BrowserContext* browser_context) { | 502 BrowserContext* browser_context) { |
501 BrowserContextServiceManagerConnectionHolder* connection_holder = | 503 BrowserContextServiceManagerConnectionHolder* connection_holder = |
502 static_cast<BrowserContextServiceManagerConnectionHolder*>( | 504 static_cast<BrowserContextServiceManagerConnectionHolder*>( |
503 browser_context->GetUserData(kServiceManagerConnection)); | 505 browser_context->GetUserData(kServiceManagerConnection)); |
504 return connection_holder ? connection_holder->service_manager_connection() | 506 return connection_holder ? connection_holder->service_manager_connection() |
505 : nullptr; | 507 : nullptr; |
506 } | 508 } |
507 | 509 |
| 510 BrowserContext::BrowserContext() |
| 511 : media_device_id_salt_(CreateRandomMediaDeviceIDSalt()) {} |
| 512 |
508 BrowserContext::~BrowserContext() { | 513 BrowserContext::~BrowserContext() { |
509 CHECK(GetUserData(kMojoWasInitialized)) | 514 CHECK(GetUserData(kMojoWasInitialized)) |
510 << "Attempting to destroy a BrowserContext that never called " | 515 << "Attempting to destroy a BrowserContext that never called " |
511 << "Initialize()"; | 516 << "Initialize()"; |
512 | 517 |
513 DCHECK(!GetUserData(kStoragePartitionMapKeyName)) | 518 DCHECK(!GetUserData(kStoragePartitionMapKeyName)) |
514 << "StoragePartitionMap is not shut down properly"; | 519 << "StoragePartitionMap is not shut down properly"; |
515 | 520 |
516 RemoveBrowserContextFromUserIdMap(this); | 521 RemoveBrowserContextFromUserIdMap(this); |
517 | 522 |
518 if (GetUserData(kDownloadManagerKeyName)) | 523 if (GetUserData(kDownloadManagerKeyName)) |
519 GetDownloadManager(this)->Shutdown(); | 524 GetDownloadManager(this)->Shutdown(); |
520 } | 525 } |
521 | 526 |
522 void BrowserContext::ShutdownStoragePartitions() { | 527 void BrowserContext::ShutdownStoragePartitions() { |
523 if (GetUserData(kStoragePartitionMapKeyName)) | 528 if (GetUserData(kStoragePartitionMapKeyName)) |
524 RemoveUserData(kStoragePartitionMapKeyName); | 529 RemoveUserData(kStoragePartitionMapKeyName); |
525 } | 530 } |
526 | 531 |
| 532 std::string BrowserContext::GetMediaDeviceIDSalt() { |
| 533 return media_device_id_salt_; |
| 534 } |
| 535 |
| 536 // static |
| 537 std::string BrowserContext::CreateRandomMediaDeviceIDSalt() { |
| 538 std::string salt; |
| 539 base::Base64Encode(base::RandBytesAsString(16), &salt); |
| 540 DCHECK(!salt.empty()); |
| 541 return salt; |
| 542 } |
| 543 |
527 } // namespace content | 544 } // namespace content |
OLD | NEW |