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> |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 content::DownloadManager* download_manager) { | 120 content::DownloadManager* download_manager) { |
121 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 121 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
122 DCHECK(download_manager); | 122 DCHECK(download_manager); |
123 context->SetUserData(kDownloadManagerKeyName, download_manager); | 123 context->SetUserData(kDownloadManagerKeyName, download_manager); |
124 } | 124 } |
125 | 125 |
126 class BrowserContextShellConnectionHolder | 126 class BrowserContextShellConnectionHolder |
127 : public base::SupportsUserData::Data { | 127 : public base::SupportsUserData::Data { |
128 public: | 128 public: |
129 BrowserContextShellConnectionHolder( | 129 BrowserContextShellConnectionHolder( |
130 std::unique_ptr<mojo::Connection> connection, | 130 std::unique_ptr<shell::Connection> connection, |
131 mojo::shell::mojom::ShellClientRequest request) | 131 shell::mojom::ShellClientRequest request) |
132 : root_connection_(std::move(connection)), | 132 : root_connection_(std::move(connection)), |
133 shell_connection_(new BrowserShellConnection(std::move(request))) {} | 133 shell_connection_(new BrowserShellConnection(std::move(request))) {} |
134 ~BrowserContextShellConnectionHolder() override {} | 134 ~BrowserContextShellConnectionHolder() override {} |
135 | 135 |
136 BrowserShellConnection* shell_connection() { return shell_connection_.get(); } | 136 BrowserShellConnection* shell_connection() { return shell_connection_.get(); } |
137 | 137 |
138 private: | 138 private: |
139 std::unique_ptr<mojo::Connection> root_connection_; | 139 std::unique_ptr<shell::Connection> root_connection_; |
140 std::unique_ptr<BrowserShellConnection> shell_connection_; | 140 std::unique_ptr<BrowserShellConnection> shell_connection_; |
141 | 141 |
142 DISALLOW_COPY_AND_ASSIGN(BrowserContextShellConnectionHolder); | 142 DISALLOW_COPY_AND_ASSIGN(BrowserContextShellConnectionHolder); |
143 }; | 143 }; |
144 | 144 |
145 } // namespace | 145 } // namespace |
146 | 146 |
147 // static | 147 // static |
148 void BrowserContext::AsyncObliterateStoragePartition( | 148 void BrowserContext::AsyncObliterateStoragePartition( |
149 BrowserContext* browser_context, | 149 BrowserContext* browser_context, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 user_service::AssociateMojoUserIDWithUserDir(new_id, path); | 377 user_service::AssociateMojoUserIDWithUserDir(new_id, path); |
378 browser_context->SetUserData(kMojoWasInitialized, | 378 browser_context->SetUserData(kMojoWasInitialized, |
379 new base::SupportsUserData::Data); | 379 new base::SupportsUserData::Data); |
380 | 380 |
381 MojoShellConnection* shell = MojoShellConnection::Get(); | 381 MojoShellConnection* shell = MojoShellConnection::Get(); |
382 if (shell) { | 382 if (shell) { |
383 // NOTE: Many unit tests create a TestBrowserContext without initializing | 383 // NOTE: Many unit tests create a TestBrowserContext without initializing |
384 // Mojo or the global Mojo shell connection. | 384 // Mojo or the global Mojo shell connection. |
385 | 385 |
386 mojo::shell::mojom::ShellClientPtr shell_client; | 386 shell::mojom::ShellClientPtr shell_client; |
387 mojo::shell::mojom::ShellClientRequest shell_client_request = | 387 shell::mojom::ShellClientRequest shell_client_request = |
388 mojo::GetProxy(&shell_client); | 388 mojo::GetProxy(&shell_client); |
389 | 389 |
390 mojo::shell::mojom::PIDReceiverPtr pid_receiver; | 390 shell::mojom::PIDReceiverPtr pid_receiver; |
391 mojo::Connector::ConnectParams params( | 391 shell::Connector::ConnectParams params( |
392 mojo::Identity(kBrowserMojoApplicationName, new_id)); | 392 shell::Identity(kBrowserMojoApplicationName, new_id)); |
393 params.set_client_process_connection(std::move(shell_client), | 393 params.set_client_process_connection(std::move(shell_client), |
394 mojo::GetProxy(&pid_receiver)); | 394 mojo::GetProxy(&pid_receiver)); |
395 pid_receiver->SetPID(base::GetCurrentProcId()); | 395 pid_receiver->SetPID(base::GetCurrentProcId()); |
396 | 396 |
397 BrowserContextShellConnectionHolder* connection_holder = | 397 BrowserContextShellConnectionHolder* connection_holder = |
398 new BrowserContextShellConnectionHolder( | 398 new BrowserContextShellConnectionHolder( |
399 shell->GetConnector()->Connect(¶ms), | 399 shell->GetConnector()->Connect(¶ms), |
400 std::move(shell_client_request)); | 400 std::move(shell_client_request)); |
401 browser_context->SetUserData(kMojoShellConnection, connection_holder); | 401 browser_context->SetUserData(kMojoShellConnection, connection_holder); |
402 | 402 |
(...skipping 24 matching lines...) Expand all Loading... |
427 auto it = std::find_if( | 427 auto it = std::find_if( |
428 g_context_to_user_id.Get().begin(), | 428 g_context_to_user_id.Get().begin(), |
429 g_context_to_user_id.Get().end(), | 429 g_context_to_user_id.Get().end(), |
430 [&browser_context](const std::pair<BrowserContext*, std::string>& p) { | 430 [&browser_context](const std::pair<BrowserContext*, std::string>& p) { |
431 return p.first == browser_context; }); | 431 return p.first == browser_context; }); |
432 CHECK(it != g_context_to_user_id.Get().end()); | 432 CHECK(it != g_context_to_user_id.Get().end()); |
433 return it->second; | 433 return it->second; |
434 } | 434 } |
435 | 435 |
436 // static | 436 // static |
437 mojo::Connector* BrowserContext::GetMojoConnectorFor( | 437 shell::Connector* BrowserContext::GetMojoConnectorFor( |
438 BrowserContext* browser_context) { | 438 BrowserContext* browser_context) { |
439 BrowserContextShellConnectionHolder* connection_holder = | 439 BrowserContextShellConnectionHolder* connection_holder = |
440 static_cast<BrowserContextShellConnectionHolder*>( | 440 static_cast<BrowserContextShellConnectionHolder*>( |
441 browser_context->GetUserData(kMojoShellConnection)); | 441 browser_context->GetUserData(kMojoShellConnection)); |
442 if (!connection_holder) | 442 if (!connection_holder) |
443 return nullptr; | 443 return nullptr; |
444 return connection_holder->shell_connection()->GetConnector(); | 444 return connection_holder->shell_connection()->GetConnector(); |
445 } | 445 } |
446 | 446 |
447 BrowserContext::~BrowserContext() { | 447 BrowserContext::~BrowserContext() { |
448 CHECK(GetUserData(kMojoWasInitialized)) | 448 CHECK(GetUserData(kMojoWasInitialized)) |
449 << "Attempting to destroy a BrowserContext that never called " | 449 << "Attempting to destroy a BrowserContext that never called " |
450 << "Initialize()"; | 450 << "Initialize()"; |
451 | 451 |
452 if (GetUserData(kDownloadManagerKeyName)) | 452 if (GetUserData(kDownloadManagerKeyName)) |
453 GetDownloadManager(this)->Shutdown(); | 453 GetDownloadManager(this)->Shutdown(); |
454 } | 454 } |
455 | 455 |
456 } // namespace content | 456 } // namespace content |
OLD | NEW |