Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/engine/app/blimp_browser_main_parts.h" | 5 #include "blimp/engine/testing/app/blimp_browser_testing_main_parts.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "blimp/common/proto/blimp_message.pb.h" | 12 #include "blimp/common/proto/blimp_message.pb.h" |
| 13 #include "blimp/engine/app/blimp_engine_config.h" | 13 #include "blimp/engine/app/blimp_engine_config.h" |
| 14 #include "blimp/engine/app/settings_manager.h" | 14 #include "blimp/engine/app/settings_manager.h" |
| 15 #include "blimp/engine/common/blimp_browser_context.h" | 15 #include "blimp/engine/common/blimp_browser_context.h" |
| 16 #include "blimp/engine/feature/geolocation/blimp_location_provider.h" | 16 #include "blimp/engine/feature/geolocation/blimp_location_provider.h" |
| 17 #include "blimp/engine/session/blimp_engine_session.h" | 17 #include "blimp/engine/session/blimp_engine_session.h" |
| 18 #include "blimp/engine/testing/app/blimp_url_rewriter.h" | |
| 19 #include "blimp/engine/testing/session/blimp_engine_testing_session.h" | |
| 18 #include "blimp/net/blimp_connection.h" | 20 #include "blimp/net/blimp_connection.h" |
| 19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/browser_url_handler.h" | |
| 20 #include "content/public/common/main_function_params.h" | 23 #include "content/public/common/main_function_params.h" |
| 21 #include "net/base/net_module.h" | 24 #include "net/base/net_module.h" |
| 22 #include "net/log/net_log.h" | 25 #include "net/log/net_log.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 23 | 27 |
| 24 namespace blimp { | 28 namespace blimp { |
| 25 namespace engine { | 29 namespace engine { |
| 26 | 30 |
| 27 BlimpBrowserMainParts::BlimpBrowserMainParts( | 31 const base::FilePath::CharType kBlimpTestRoot[] = FILE_PATH_LITERAL(""); |
| 28 const content::MainFunctionParams& parameters) {} | |
| 29 | 32 |
| 30 BlimpBrowserMainParts::~BlimpBrowserMainParts() {} | 33 BlimpBrowserTestingMainParts::BlimpBrowserTestingMainParts( |
| 34 const content::MainFunctionParams& parameters) | |
| 35 : BlimpBrowserMainParts(parameters){}; | |
| 31 | 36 |
| 32 void BlimpBrowserMainParts::PreEarlyInitialization() { | 37 void BlimpBrowserTestingMainParts::PreEarlyInitialization() { |
| 33 // Fetch the engine config from the command line, and crash if invalid. Allow | 38 // Fetch the engine config from the command line, and crash if invalid. Allow |
| 34 // IO operations even though this is not in the FILE thread as this is | 39 // IO operations even though this is not in the FILE thread as this is |
| 35 // necessary for Blimp startup and occurs before any user interaction. | 40 // necessary for Blimp startup and occurs before any user interaction. |
| 36 { | 41 { |
| 37 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 42 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 38 base::ThreadRestrictions::ScopedAllowIO allow_io; | 43 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 39 engine_config_ = BlimpEngineConfig::Create(*cmd_line); | 44 engine_config_ = BlimpEngineConfig::Create(*cmd_line); |
| 40 CHECK(engine_config_); | 45 CHECK(engine_config_); |
| 41 } | 46 } |
| 42 } | 47 } |
| 43 | 48 |
| 44 void BlimpBrowserMainParts::PreMainMessageLoopRun() { | 49 void BlimpBrowserTestingMainParts::PreMainMessageLoopRun() { |
|
shenghuazhang
2017/01/05 23:36:33
I think the ets instance needs to be shut down in
jbudorick at gmail
2017/01/06 16:09:37
What about PostMainMessageLoopRun in this class?
shenghuazhang
2017/01/07 01:21:24
Done.
| |
| 50 blimp::engine::test::g_ets_instance.reset(new net::EmbeddedTestServer()); | |
| 51 blimp::engine::test::g_ets_instance->ServeFilesFromSourceDirectory( | |
| 52 base::FilePath(kBlimpTestRoot)); | |
| 53 DCHECK(blimp::engine::test::g_ets_instance->Start()); | |
| 54 | |
| 55 content::BrowserURLHandler::GetInstance()->AddHandlerPair( | |
| 56 &blimp::engine::test::HandleBlimpTestURL, | |
| 57 content::BrowserURLHandler::null_handler()); | |
| 58 | |
| 45 net_log_.reset(new net::NetLog()); | 59 net_log_.reset(new net::NetLog()); |
| 46 settings_manager_.reset(new SettingsManager); | 60 settings_manager_.reset(new SettingsManager); |
| 47 std::unique_ptr<BlimpBrowserContext> browser_context( | 61 std::unique_ptr<BlimpBrowserContext> browser_context( |
| 48 new BlimpBrowserContext(false, net_log_.get())); | 62 new BlimpBrowserContext(false, net_log_.get())); |
| 49 engine_session_.reset( | 63 engine_session_.reset(new BlimpEngineTestingSession( |
| 50 new BlimpEngineSession(std::move(browser_context), net_log_.get(), | 64 std::move(browser_context), net_log_.get(), engine_config_.get(), |
|
jbudorick at gmail
2017/01/06 16:09:37
Should BlimpEngineTestingSession own the NetLog an
shenghuazhang
2017/01/07 01:21:24
I think it should since it should pass the paramet
jbudorick at gmail
2017/01/07 02:34:51
Ah, I didn't look at BlimpEngineSession.
| |
| 51 engine_config_.get(), settings_manager_.get())); | 65 settings_manager_.get())); |
| 52 engine_session_->Initialize(); | 66 engine_session_->Initialize(); |
| 53 } | 67 BlimpBrowserMainParts::SetSettingsManagerForTesting( |
|
jbudorick at gmail
2017/01/06 16:09:37
seetings_manager_ and engine_session_ shouldn't be
shenghuazhang
2017/01/07 01:21:24
Hmm... Do you mean this class shouldn't set up the
jbudorick at gmail
2017/01/07 02:34:51
Shouldn't be in the header. It's fine if this meth
shenghuazhang
2017/01/09 19:23:47
Make sense! Will refactor it.
| |
| 54 | 68 std::move(settings_manager_)); |
| 55 void BlimpBrowserMainParts::PostMainMessageLoopRun() { | 69 BlimpBrowserMainParts::SetEngineSessionForTesting(std::move(engine_session_)); |
| 56 engine_session_.reset(); | |
| 57 } | |
| 58 | |
| 59 BlimpBrowserContext* BlimpBrowserMainParts::GetBrowserContext() { | |
| 60 return engine_session_->browser_context(); | |
| 61 } | |
| 62 | |
| 63 SettingsManager* BlimpBrowserMainParts::GetSettingsManager() { | |
| 64 return settings_manager_.get(); | |
| 65 } | |
| 66 | |
| 67 BlobChannelSender* BlimpBrowserMainParts::GetBlobChannelSender() { | |
| 68 return engine_session_->blob_channel_sender(); | |
| 69 } | |
| 70 | |
| 71 BlobChannelService* BlimpBrowserMainParts::GetBlobChannelService() { | |
| 72 return engine_session_->GetBlobChannelService(); | |
| 73 } | |
| 74 | |
| 75 BlimpEngineSession* BlimpBrowserMainParts::GetBlimpEngineSession() { | |
| 76 return engine_session_.get(); | |
| 77 } | 70 } |
| 78 | 71 |
| 79 } // namespace engine | 72 } // namespace engine |
| 80 } // namespace blimp | 73 } // namespace blimp |
| OLD | NEW |