OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/web/app/web_main_runner.h" |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/i18n/icu_util.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/metrics/statistics_recorder.h" |
| 12 #include "ios/web/app/web_main_loop.h" |
| 13 #include "ios/web/public/web_client.h" |
| 14 #include "ui/base/ui_base_paths.h" |
| 15 |
| 16 namespace web { |
| 17 |
| 18 class WebMainRunnerImpl : public WebMainRunner { |
| 19 public: |
| 20 WebMainRunnerImpl() |
| 21 : is_initialized_(false), |
| 22 is_shutdown_(false), |
| 23 completed_basic_startup_(false), |
| 24 delegate_(nullptr) {} |
| 25 |
| 26 ~WebMainRunnerImpl() override { |
| 27 if (is_initialized_ && !is_shutdown_) { |
| 28 ShutDown(); |
| 29 } |
| 30 } |
| 31 |
| 32 int Initialize(const WebMainParams& params) override { |
| 33 //////////////////////////////////////////////////////////////////////// |
| 34 // ContentMainRunnerImpl::Initialize() |
| 35 // |
| 36 is_initialized_ = true; |
| 37 delegate_ = params.delegate; |
| 38 |
| 39 // TODO(rohitrao): Chrome for iOS initializes this in main(), because it's |
| 40 // needed for breakpad. Are we really going to require that all embedders |
| 41 // initialize an AtExitManager in main()? |
| 42 exit_manager_.reset(new base::AtExitManager); |
| 43 |
| 44 // There is no way to pass commandline flags to process on iOS, so the |
| 45 // CommandLine is always initialized empty. Embedders can add switches in |
| 46 // |BasicStartupComplete|. |
| 47 base::CommandLine::Init(0, nullptr); |
| 48 if (delegate_) { |
| 49 delegate_->BasicStartupComplete(); |
| 50 } |
| 51 completed_basic_startup_ = true; |
| 52 |
| 53 // TODO(rohitrao): Should we instead require that all embedders call |
| 54 // SetWebClient()? |
| 55 if (!GetWebClient()) |
| 56 SetWebClient(&empty_web_client_); |
| 57 |
| 58 #if defined(USE_NSS) |
| 59 crypto::EarlySetupForNSSInit(); |
| 60 #endif |
| 61 |
| 62 // TODO(rohitrao): Desktop calls content::RegisterContentSchemes(true) here. |
| 63 // Do we need similar scheme registration on iOS? |
| 64 ui::RegisterPathProvider(); |
| 65 |
| 66 CHECK(base::i18n::InitializeICU()); |
| 67 |
| 68 //////////////////////////////////////////////////////////// |
| 69 // BrowserMainRunnerImpl::Initialize() |
| 70 base::StatisticsRecorder::Initialize(); |
| 71 |
| 72 main_loop_.reset(new WebMainLoop()); |
| 73 main_loop_->Init(); |
| 74 main_loop_->EarlyInitialization(); |
| 75 main_loop_->MainMessageLoopStart(); |
| 76 main_loop_->CreateStartupTasks(); |
| 77 int result_code = main_loop_->GetResultCode(); |
| 78 if (result_code > 0) |
| 79 return result_code; |
| 80 |
| 81 // Return -1 to indicate no early termination. |
| 82 return -1; |
| 83 } |
| 84 |
| 85 void ShutDown() override { |
| 86 //////////////////////////////////////////////////////////////////// |
| 87 // BrowserMainRunner::Shutdown() |
| 88 // |
| 89 DCHECK(is_initialized_); |
| 90 DCHECK(!is_shutdown_); |
| 91 main_loop_->ShutdownThreadsAndCleanUp(); |
| 92 main_loop_.reset(nullptr); |
| 93 |
| 94 //////////////////////////////////////////////////////////////////// |
| 95 // ContentMainRunner::Shutdown() |
| 96 // |
| 97 if (completed_basic_startup_ && delegate_) { |
| 98 delegate_->ProcessExiting(); |
| 99 } |
| 100 |
| 101 exit_manager_.reset(nullptr); |
| 102 delegate_ = nullptr; |
| 103 is_shutdown_ = true; |
| 104 } |
| 105 |
| 106 protected: |
| 107 // True if we have started to initialize the runner. |
| 108 bool is_initialized_; |
| 109 |
| 110 // True if the runner has been shut down. |
| 111 bool is_shutdown_; |
| 112 |
| 113 // True if basic startup was completed. |
| 114 bool completed_basic_startup_; |
| 115 |
| 116 // The delegate will outlive this object. |
| 117 WebMainDelegate* delegate_; |
| 118 |
| 119 // Used if the embedder doesn't set one. |
| 120 WebClient empty_web_client_; |
| 121 |
| 122 scoped_ptr<base::AtExitManager> exit_manager_; |
| 123 scoped_ptr<WebMainLoop> main_loop_; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(WebMainRunnerImpl); |
| 126 }; |
| 127 |
| 128 // static |
| 129 WebMainRunner* WebMainRunner::Create() { |
| 130 return new WebMainRunnerImpl(); |
| 131 } |
| 132 |
| 133 } // namespace web |
OLD | NEW |