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

Side by Side Diff: services/console/console.cc

Issue 937863004: Revert accidental console.cc changes from 23538d3c49dfaff28e4d88b3254b7ab8cf1b6e35 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <iostream> 5 #include <iostream>
6 #include <string> 6 #include <string>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "mojo/application/application_runner_chromium.h" 9 #include "mojo/application/application_runner_chromium.h"
10 #include "mojo/public/c/system/main.h" 10 #include "mojo/public/c/system/main.h"
11 #include "mojo/public/cpp/application/application_connection.h" 11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/public/cpp/application/application_delegate.h" 12 #include "mojo/public/cpp/application/application_delegate.h"
13 #include "mojo/public/cpp/application/interface_factory.h" 13 #include "mojo/public/cpp/application/interface_factory.h"
14 #include "mojo/public/cpp/bindings/interface_ptr.h" 14 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "mojo/services/console/public/interfaces/console.mojom.h" 15 #include "mojo/services/console/public/interfaces/console.mojom.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 class ConsoleImpl : public InterfaceImpl<Console> { 19 class ConsoleImpl : public Console {
20 public: 20 public:
21 explicit ConsoleImpl(const std::string& app_name) : app_name_(app_name) {} 21 ConsoleImpl(const std::string& app_name, InterfaceRequest<Console> request)
22 : app_name_(app_name), binding_(this, request.Pass()) {}
22 ~ConsoleImpl() override {} 23 ~ConsoleImpl() override {}
23 24
24 void ReadLine(const Callback<void(bool, String)>& callback) override { 25 void ReadLine(const Callback<void(bool, String)>& callback) override {
25 std::cout << "[" << app_name_ << "]> "; 26 std::cout << "[" << app_name_ << "]> ";
26 std::cout.flush(); 27 std::cout.flush();
27 28
28 std::string line; 29 std::string line;
29 std::getline(std::cin, line); 30 std::getline(std::cin, line);
30 31
31 // This will send an empty string on eof. 32 // This will send an empty string on eof.
32 String return_value = String::From(line); 33 String return_value = String::From(line);
33 bool is_good = std::cin.good(); 34 bool is_good = std::cin.good();
34 if (!is_good) 35 if (!is_good)
35 return_value = String::From(""); 36 return_value = String::From("");
36 37
37 callback.Run(is_good, return_value); 38 callback.Run(is_good, return_value);
38 } 39 }
39 40
40 void PrintLines(Array<mojo::String> data, 41 void PrintLines(Array<mojo::String> data,
41 const Callback<void(bool)>& callback) override { 42 const Callback<void(bool)>& callback) override {
42 for (size_t i = 0; i < data.size(); ++i) 43 for (size_t i = 0; i < data.size(); ++i)
43 std::cout << "[" << app_name_ << "] " << data[i].get() << std::endl; 44 std::cout << "[" << app_name_ << "] " << data[i].get() << std::endl;
44 45
45 callback.Run(true); 46 callback.Run(true);
46 } 47 }
47 48
48 private: 49 private:
49 const std::string app_name_; 50 const std::string app_name_;
51 StrongBinding<Console> binding_;
50 52
51 DISALLOW_COPY_AND_ASSIGN(ConsoleImpl); 53 DISALLOW_COPY_AND_ASSIGN(ConsoleImpl);
52 }; 54 };
53 55
54 class ConsoleDelegate : public ApplicationDelegate, 56 class ConsoleDelegate : public ApplicationDelegate,
55 public InterfaceFactory<Console> { 57 public InterfaceFactory<Console> {
56 public: 58 public:
57 ConsoleDelegate() {} 59 ConsoleDelegate() {}
58 ~ConsoleDelegate() override {} 60 ~ConsoleDelegate() override {}
59 61
60 // ApplicationDelegate implementation. 62 // ApplicationDelegate implementation.
61 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 63 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
62 connection->AddService(this); 64 connection->AddService(this);
63 return true; 65 return true;
64 } 66 }
65 67
66 // InterfaceFactory<Console> implementation. 68 // InterfaceFactory<Console> implementation.
67 void Create(ApplicationConnection* connection, 69 void Create(ApplicationConnection* connection,
68 InterfaceRequest<Console> request) override { 70 InterfaceRequest<Console> request) override {
69 BindToRequest(new ConsoleImpl(connection->GetRemoteApplicationURL()), 71 new ConsoleImpl(connection->GetRemoteApplicationURL(), request.Pass());
70 &request);
71 } 72 }
72 73
73 private: 74 private:
74 DISALLOW_COPY_AND_ASSIGN(ConsoleDelegate); 75 DISALLOW_COPY_AND_ASSIGN(ConsoleDelegate);
75 }; 76 };
76 77
77 } // namespace mojo 78 } // namespace mojo
78 79
79 MojoResult MojoMain(MojoHandle shell_handle) { 80 MojoResult MojoMain(MojoHandle shell_handle) {
80 mojo::ApplicationRunnerChromium runner(new mojo::ConsoleDelegate); 81 mojo::ApplicationRunnerChromium runner(new mojo::ConsoleDelegate);
81 return runner.Run(shell_handle); 82 return runner.Run(shell_handle);
82 } 83 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698