| OLD | NEW |
| 1 // Copyright 2016 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "blimp/client/app/blimp_startup.h" | 12 #include "blimp/client/app/blimp_startup.h" |
| 13 #include "blimp/client/app/linux/blimp_client_context_delegate_linux.h" | 13 #include "blimp/client/app/linux/blimp_client_context_delegate_linux.h" |
| 14 #include "blimp/client/app/linux/blimp_display_manager.h" | 14 #include "blimp/client/app/linux/blimp_display_manager.h" |
| 15 #include "blimp/client/app/linux/blimp_display_manager_delegate_main.h" | 15 #include "blimp/client/app/linux/blimp_display_manager_delegate_main.h" |
| 16 #include "blimp/client/core/settings/settings_prefs.h" |
| 16 #include "blimp/client/public/blimp_client_context.h" | 17 #include "blimp/client/public/blimp_client_context.h" |
| 17 #include "blimp/client/public/contents/blimp_navigation_controller.h" | 18 #include "blimp/client/public/contents/blimp_navigation_controller.h" |
| 18 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" | 19 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "components/prefs/command_line_pref_store.h" |
| 22 #include "components/prefs/in_memory_pref_store.h" |
| 23 #include "components/prefs/pref_service.h" |
| 24 #include "components/prefs/pref_service_factory.h" |
| 19 #include "ui/gfx/x/x11_connection.h" | 25 #include "ui/gfx/x/x11_connection.h" |
| 20 | 26 |
| 21 namespace { | 27 namespace { |
| 22 const char kDefaultUrl[] = "https://www.google.com"; | 28 const char kDefaultUrl[] = "https://www.google.com"; |
| 23 constexpr int kWindowWidth = 800; | 29 constexpr int kWindowWidth = 800; |
| 24 constexpr int kWindowHeight = 600; | 30 constexpr int kWindowHeight = 600; |
| 25 } | 31 |
| 32 class BlimpShellCommandLinePrefStore : public CommandLinePrefStore { |
| 33 public: |
| 34 explicit BlimpShellCommandLinePrefStore(const base::CommandLine* command_line) |
| 35 : CommandLinePrefStore(command_line) { |
| 36 blimp::client::BlimpClientContext::ApplyBlimpSwitches(this); |
| 37 } |
| 38 |
| 39 protected: |
| 40 ~BlimpShellCommandLinePrefStore() override = default; |
| 41 }; |
| 42 } // namespace |
| 26 | 43 |
| 27 int main(int argc, const char**argv) { | 44 int main(int argc, const char**argv) { |
| 28 base::AtExitManager at_exit; | 45 base::AtExitManager at_exit; |
| 29 base::CommandLine::Init(argc, argv); | 46 base::CommandLine::Init(argc, argv); |
| 30 | 47 |
| 31 CHECK(gfx::InitializeThreadedX11()); | 48 CHECK(gfx::InitializeThreadedX11()); |
| 32 | 49 |
| 33 blimp::client::InitializeLogging(); | 50 blimp::client::InitializeLogging(); |
| 34 blimp::client::InitializeMainMessageLoop(); | 51 blimp::client::InitializeMainMessageLoop(); |
| 35 | 52 |
| 36 base::Thread io_thread("BlimpIOThread"); | 53 base::Thread io_thread("BlimpIOThread"); |
| 37 base::Thread::Options options; | 54 base::Thread::Options options; |
| 38 options.message_loop_type = base::MessageLoop::TYPE_IO; | 55 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 39 io_thread.StartWithOptions(options); | 56 io_thread.StartWithOptions(options); |
| 40 | 57 |
| 41 // Creating this using "new" and passing to context using "WrapUnique" as | 58 // Creating this using "new" and passing to context using "WrapUnique" as |
| 42 // opposed to "MakeUnique" because we'll need to pass the compositor | 59 // opposed to "MakeUnique" because we'll need to pass the compositor |
| 43 // dependencies to the display manager as well. | 60 // dependencies to the display manager as well. |
| 44 blimp::client::CompositorDependencies* compositor_dependencies = | 61 blimp::client::CompositorDependencies* compositor_dependencies = |
| 45 new blimp::client::CompositorDependenciesImpl(); | 62 new blimp::client::CompositorDependenciesImpl(); |
| 46 // Creating the context delegate before the context so that the context is | 63 // Creating the context delegate before the context so that the context is |
| 47 // destroyed before the delegate. | 64 // destroyed before the delegate. |
| 48 std::unique_ptr<blimp::client::BlimpClientContextDelegate> context_delegate = | 65 std::unique_ptr<blimp::client::BlimpClientContextDelegate> context_delegate = |
| 49 base::MakeUnique<blimp::client::BlimpClientContextDelegateLinux>(); | 66 base::MakeUnique<blimp::client::BlimpClientContextDelegateLinux>(); |
| 50 std::unique_ptr<blimp::client::BlimpClientContext> context = | 67 |
| 51 base::WrapUnique<blimp::client::BlimpClientContext>( | 68 // Create PrefRegistry and register blimp preferences with it. |
| 52 blimp::client::BlimpClientContext::Create( | 69 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry = |
| 53 io_thread.task_runner(), io_thread.task_runner(), | 70 new ::user_prefs::PrefRegistrySyncable(); |
| 54 base::WrapUnique(compositor_dependencies))); | 71 blimp::client::BlimpClientContext::RegisterPrefs(pref_registry.get()); |
| 72 |
| 73 PrefServiceFactory pref_service_factory; |
| 74 |
| 75 // Create command line and user preference stores. |
| 76 pref_service_factory.set_command_line_prefs( |
| 77 make_scoped_refptr(new BlimpShellCommandLinePrefStore( |
| 78 base::CommandLine::ForCurrentProcess()))); |
| 79 pref_service_factory.set_user_prefs(new InMemoryPrefStore()); |
| 80 |
| 81 // Create a PrefService binding the PrefRegistry to the pref stores. |
| 82 // The PrefService owns the PrefRegistry and pref stores. |
| 83 std::unique_ptr<PrefService> pref_service = |
| 84 pref_service_factory.Create(pref_registry.get()); |
| 85 |
| 86 auto context = base::WrapUnique<blimp::client::BlimpClientContext>( |
| 87 blimp::client::BlimpClientContext::Create( |
| 88 io_thread.task_runner(), io_thread.task_runner(), |
| 89 base::WrapUnique(compositor_dependencies), pref_service.get())); |
| 55 context->SetDelegate(context_delegate.get()); | 90 context->SetDelegate(context_delegate.get()); |
| 56 | 91 |
| 57 context->Connect(); | 92 context->Connect(); |
| 58 | 93 |
| 59 // If there is a non-switch argument to the command line, load that url. | 94 // If there is a non-switch argument to the command line, load that url. |
| 60 base::CommandLine::StringVector args = | 95 base::CommandLine::StringVector args = |
| 61 base::CommandLine::ForCurrentProcess()->GetArgs(); | 96 base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 62 std::string url = args.size() > 0 ? args[0] : kDefaultUrl; | 97 std::string url = args.size() > 0 ? args[0] : kDefaultUrl; |
| 63 std::unique_ptr<blimp::client::BlimpContents> contents = | 98 std::unique_ptr<blimp::client::BlimpContents> contents = |
| 64 context->CreateBlimpContents(nullptr); | 99 context->CreateBlimpContents(nullptr); |
| 65 contents->GetNavigationController().LoadURL(GURL(url)); | 100 contents->GetNavigationController().LoadURL(GURL(url)); |
| 66 | 101 |
| 67 std::unique_ptr<blimp::client::BlimpDisplayManagerDelegate> | 102 std::unique_ptr<blimp::client::BlimpDisplayManagerDelegate> |
| 68 display_manager_delegate = | 103 display_manager_delegate = |
| 69 base::MakeUnique<blimp::client::BlimpDisplayManagerDelegateMain>(); | 104 base::MakeUnique<blimp::client::BlimpDisplayManagerDelegateMain>(); |
| 70 blimp::client::BlimpDisplayManager display_manager( | 105 blimp::client::BlimpDisplayManager display_manager( |
| 71 display_manager_delegate.get(), compositor_dependencies); | 106 display_manager_delegate.get(), compositor_dependencies); |
| 72 display_manager.SetWindowSize(gfx::Size(kWindowWidth, kWindowHeight)); | 107 display_manager.SetWindowSize(gfx::Size(kWindowWidth, kWindowHeight)); |
| 73 display_manager.SetBlimpContents(std::move(contents)); | 108 display_manager.SetBlimpContents(std::move(contents)); |
| 74 | 109 |
| 75 base::RunLoop().Run(); | 110 base::RunLoop().Run(); |
| 76 } | 111 } |
| OLD | NEW |