OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
8 #include "mojo/public/cpp/application/application_impl.h" | 8 #include "mojo/public/cpp/application/application_impl.h" |
9 #include "mojo/public/cpp/application/interface_factory_impl.h" | 9 #include "mojo/public/cpp/application/interface_factory_impl.h" |
10 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" | 10 #include "mojo/services/public/interfaces/content_handler/content_handler.mojom.
h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 namespace examples { | 13 namespace examples { |
14 | 14 |
15 class ContentHandlerApp; | 15 class ContentHandlerApp; |
16 | 16 |
17 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { | 17 class ContentHandlerImpl : public InterfaceImpl<ContentHandler> { |
18 public: | 18 public: |
19 explicit ContentHandlerImpl(ContentHandlerApp* content_handler_app) | 19 explicit ContentHandlerImpl(ContentHandlerApp* content_handler_app) |
20 : content_handler_app_(content_handler_app) { | 20 : content_handler_app_(content_handler_app) { |
21 } | 21 } |
22 virtual ~ContentHandlerImpl() {} | 22 virtual ~ContentHandlerImpl() {} |
23 | 23 |
24 private: | 24 private: |
25 virtual void OnConnect(const mojo::String& url, | 25 virtual void OnConnect( |
26 URLResponsePtr response, | 26 const mojo::String& url, |
27 InterfaceRequest<ServiceProvider> service_provider) | 27 URLResponsePtr response, |
28 MOJO_OVERRIDE; | 28 InterfaceRequest<ServiceProvider> service_provider) override; |
29 | 29 |
30 ContentHandlerApp* content_handler_app_; | 30 ContentHandlerApp* content_handler_app_; |
31 }; | 31 }; |
32 | 32 |
33 class ContentHandlerApp : public ApplicationDelegate { | 33 class ContentHandlerApp : public ApplicationDelegate { |
34 public: | 34 public: |
35 ContentHandlerApp() : content_handler_factory_(this) { | 35 ContentHandlerApp() : content_handler_factory_(this) { |
36 } | 36 } |
37 | 37 |
38 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 38 virtual void Initialize(ApplicationImpl* app) override {} |
39 } | |
40 | 39 |
41 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 40 virtual bool ConfigureIncomingConnection( |
42 MOJO_OVERRIDE { | 41 ApplicationConnection* connection) override { |
43 connection->AddService(&content_handler_factory_); | 42 connection->AddService(&content_handler_factory_); |
44 return true; | 43 return true; |
45 } | 44 } |
46 | 45 |
47 void PrintResponse(ScopedDataPipeConsumerHandle body) const { | 46 void PrintResponse(ScopedDataPipeConsumerHandle body) const { |
48 for (;;) { | 47 for (;;) { |
49 char buf[512]; | 48 char buf[512]; |
50 uint32_t num_bytes = sizeof(buf); | 49 uint32_t num_bytes = sizeof(buf); |
51 MojoResult result = ReadDataRaw(body.get(), buf, &num_bytes, | 50 MojoResult result = ReadDataRaw(body.get(), buf, &num_bytes, |
52 MOJO_READ_DATA_FLAG_NONE); | 51 MOJO_READ_DATA_FLAG_NONE); |
(...skipping 29 matching lines...) Expand all Loading... |
82 } | 81 } |
83 | 82 |
84 } // namespace examples | 83 } // namespace examples |
85 | 84 |
86 // static | 85 // static |
87 ApplicationDelegate* ApplicationDelegate::Create() { | 86 ApplicationDelegate* ApplicationDelegate::Create() { |
88 return new examples::ContentHandlerApp(); | 87 return new examples::ContentHandlerApp(); |
89 } | 88 } |
90 | 89 |
91 } // namespace mojo | 90 } // namespace mojo |
OLD | NEW |