Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: mojo/shell/tests/application_manager_apptest_driver.cc

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/process/process.h" 19 #include "base/process/process.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "mojo/edk/embedder/embedder.h" 21 #include "mojo/edk/embedder/embedder.h"
22 #include "mojo/edk/embedder/platform_channel_pair.h" 22 #include "mojo/edk/embedder/platform_channel_pair.h"
23 #include "mojo/edk/embedder/scoped_platform_handle.h" 23 #include "mojo/edk/embedder/scoped_platform_handle.h"
24 #include "mojo/public/cpp/bindings/binding_set.h" 24 #include "mojo/public/cpp/bindings/binding_set.h"
25 #include "mojo/shell/public/cpp/connection.h" 25 #include "mojo/shell/public/cpp/connection.h"
26 #include "mojo/shell/public/cpp/connector.h"
26 #include "mojo/shell/public/cpp/interface_factory.h" 27 #include "mojo/shell/public/cpp/interface_factory.h"
27 #include "mojo/shell/public/cpp/shell.h"
28 #include "mojo/shell/public/cpp/shell_client.h" 28 #include "mojo/shell/public/cpp/shell_client.h"
29 #include "mojo/shell/public/interfaces/application_manager.mojom.h" 29 #include "mojo/shell/public/interfaces/application_manager.mojom.h"
30 #include "mojo/shell/runner/child/test_native_main.h" 30 #include "mojo/shell/runner/child/test_native_main.h"
31 #include "mojo/shell/runner/common/switches.h" 31 #include "mojo/shell/runner/common/switches.h"
32 #include "mojo/shell/runner/init.h" 32 #include "mojo/shell/runner/init.h"
33 #include "mojo/shell/tests/application_manager_apptests.mojom.h" 33 #include "mojo/shell/tests/application_manager_apptests.mojom.h"
34 34
35 using mojo::shell::test::mojom::CreateInstanceForHandleTestPtr; 35 using mojo::shell::test::mojom::CreateInstanceForHandleTestPtr;
36 using mojo::shell::test::mojom::Driver; 36 using mojo::shell::test::mojom::Driver;
37 37
38 namespace { 38 namespace {
39 39
40 class TargetApplicationDelegate : public mojo::ShellClient, 40 class TargetApplicationDelegate : public mojo::ShellClient,
41 public mojo::InterfaceFactory<Driver>, 41 public mojo::InterfaceFactory<Driver>,
42 public Driver { 42 public Driver {
43 public: 43 public:
44 TargetApplicationDelegate() : shell_(nullptr), weak_factory_(this) {} 44 TargetApplicationDelegate() : weak_factory_(this) {}
45 ~TargetApplicationDelegate() override {} 45 ~TargetApplicationDelegate() override {}
46 46
47 private: 47 private:
48 // mojo::ShellClient: 48 // mojo::ShellClient:
49 void Initialize(mojo::Shell* shell, const std::string& url, 49 void Initialize(mojo::Connector* connector, const std::string& url,
50 uint32_t id, uint32_t user_id) override { 50 uint32_t id, uint32_t user_id) override {
51 shell_ = shell;
52
53 base::FilePath target_path; 51 base::FilePath target_path;
54 CHECK(base::PathService::Get(base::DIR_EXE, &target_path)); 52 CHECK(base::PathService::Get(base::DIR_EXE, &target_path));
55 #if defined(OS_WIN) 53 #if defined(OS_WIN)
56 target_path = target_path.Append( 54 target_path = target_path.Append(
57 FILE_PATH_LITERAL("application_manager_apptest_target.exe")); 55 FILE_PATH_LITERAL("application_manager_apptest_target.exe"));
58 #else 56 #else
59 target_path = target_path.Append( 57 target_path = target_path.Append(
60 FILE_PATH_LITERAL("application_manager_apptest_target")); 58 FILE_PATH_LITERAL("application_manager_apptest_target"));
61 #endif 59 #endif
62 60
(...skipping 28 matching lines...) Expand all
91 89
92 mojo::shell::mojom::CapabilityFilterPtr filter( 90 mojo::shell::mojom::CapabilityFilterPtr filter(
93 mojo::shell::mojom::CapabilityFilter::New()); 91 mojo::shell::mojom::CapabilityFilter::New());
94 mojo::Array<mojo::String> test_interfaces; 92 mojo::Array<mojo::String> test_interfaces;
95 test_interfaces.push_back( 93 test_interfaces.push_back(
96 mojo::shell::test::mojom::CreateInstanceForHandleTest::Name_); 94 mojo::shell::test::mojom::CreateInstanceForHandleTest::Name_);
97 filter->filter.insert("mojo:mojo_shell_apptests", 95 filter->filter.insert("mojo:mojo_shell_apptests",
98 std::move(test_interfaces)); 96 std::move(test_interfaces));
99 97
100 mojo::shell::mojom::ApplicationManagerPtr application_manager; 98 mojo::shell::mojom::ApplicationManagerPtr application_manager;
101 shell_->ConnectToInterface("mojo:shell", &application_manager); 99 connector->ConnectToInterface("mojo:shell", &application_manager);
102 application_manager->CreateInstanceForHandle( 100 application_manager->CreateInstanceForHandle(
103 mojo::ScopedHandle(mojo::Handle(pipe.release().value())), 101 mojo::ScopedHandle(mojo::Handle(pipe.release().value())),
104 "exe:application_manager_apptest_target", std::move(filter), 102 "exe:application_manager_apptest_target", std::move(filter),
105 std::move(request)); 103 std::move(request));
106 104
107 base::LaunchOptions options; 105 base::LaunchOptions options;
108 #if defined(OS_WIN) 106 #if defined(OS_WIN)
109 options.handles_to_inherit = &handle_passing_info; 107 options.handles_to_inherit = &handle_passing_info;
110 #elif defined(OS_POSIX) 108 #elif defined(OS_POSIX)
111 options.fds_to_remap = &handle_passing_info; 109 options.fds_to_remap = &handle_passing_info;
(...skipping 12 matching lines...) Expand all
124 122
125 // mojo::InterfaceFactory<Driver>: 123 // mojo::InterfaceFactory<Driver>:
126 void Create(mojo::Connection* connection, 124 void Create(mojo::Connection* connection,
127 mojo::InterfaceRequest<Driver> request) override { 125 mojo::InterfaceRequest<Driver> request) override {
128 bindings_.AddBinding(this, std::move(request)); 126 bindings_.AddBinding(this, std::move(request));
129 } 127 }
130 128
131 // Driver: 129 // Driver:
132 void QuitDriver() override { 130 void QuitDriver() override {
133 target_.Terminate(0, false); 131 target_.Terminate(0, false);
134 shell_->Quit(); 132 base::MessageLoop::current()->QuitWhenIdle();
135 } 133 }
136 134
137 mojo::Shell* shell_;
138 base::Process target_; 135 base::Process target_;
139 mojo::BindingSet<Driver> bindings_; 136 mojo::BindingSet<Driver> bindings_;
140 base::WeakPtrFactory<TargetApplicationDelegate> weak_factory_; 137 base::WeakPtrFactory<TargetApplicationDelegate> weak_factory_;
141 138
142 DISALLOW_COPY_AND_ASSIGN(TargetApplicationDelegate); 139 DISALLOW_COPY_AND_ASSIGN(TargetApplicationDelegate);
143 }; 140 };
144 141
145 } // namespace 142 } // namespace
146 143
147 int main(int argc, char** argv) { 144 int main(int argc, char** argv) {
148 base::AtExitManager at_exit; 145 base::AtExitManager at_exit;
149 base::CommandLine::Init(argc, argv); 146 base::CommandLine::Init(argc, argv);
150 147
151 mojo::shell::InitializeLogging(); 148 mojo::shell::InitializeLogging();
152 149
153 TargetApplicationDelegate delegate; 150 TargetApplicationDelegate delegate;
154 return mojo::shell::TestNativeMain(&delegate); 151 return mojo::shell::TestNativeMain(&delegate);
155 } 152 }
OLDNEW
« no previous file with comments | « mojo/shell/tests/application_manager_apptest.cc ('k') | mojo/shell/tests/application_manager_apptest_target.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698