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

Side by Side Diff: examples/recipes/recipe_handler/recipe_handler_main.cc

Issue 868463008: Remove Client relationship between mojo.Shell/mojo.Application (Closed) Base URL: git@github.com:domokit/mojo.git@app_impl_init
Patch Set: fix android 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
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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "examples/recipes/recipe_handler/recipe_factory.h" 7 #include "examples/recipes/recipe_handler/recipe_factory.h"
8 #include "examples/recipes/recipe_handler/recipe_impl.h" 8 #include "examples/recipes/recipe_handler/recipe_impl.h"
9 #include "mojo/application/application_runner_chromium.h" 9 #include "mojo/application/application_runner_chromium.h"
10 #include "mojo/application/content_handler_factory.h" 10 #include "mojo/application/content_handler_factory.h"
(...skipping 19 matching lines...) Expand all
30 private: 30 private:
31 // Overridden from ApplicationDelegate: 31 // Overridden from ApplicationDelegate:
32 bool ConfigureIncomingConnection( 32 bool ConfigureIncomingConnection(
33 mojo::ApplicationConnection* connection) override { 33 mojo::ApplicationConnection* connection) override {
34 connection->AddService(&content_handler_factory_); 34 connection->AddService(&content_handler_factory_);
35 return true; 35 return true;
36 } 36 }
37 37
38 // Overridden from ContentHandlerFactory::ManagedDelegate: 38 // Overridden from ContentHandlerFactory::ManagedDelegate:
39 scoped_ptr<mojo::ContentHandlerFactory::HandledApplicationHolder> 39 scoped_ptr<mojo::ContentHandlerFactory::HandledApplicationHolder>
40 CreateApplication(mojo::ShellPtr shell, 40 CreateApplication(
41 mojo::URLResponsePtr response) override { 41 mojo::InterfaceRequest<mojo::Application> application_request,
42 mojo::URLResponsePtr response) override {
42 std::string recipe_string; 43 std::string recipe_string;
43 if (!mojo::common::BlockingCopyToString(response->body.Pass(), 44 if (!mojo::common::BlockingCopyToString(response->body.Pass(),
44 &recipe_string)) { 45 &recipe_string)) {
45 LOG(WARNING) << "failed reading recipe"; 46 LOG(WARNING) << "failed reading recipe";
46 return nullptr; 47 return nullptr;
47 } 48 }
48 49
49 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); 50 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS);
50 scoped_ptr<base::Value> recipe_value(reader.ReadToValue(recipe_string)); 51 scoped_ptr<base::Value> recipe_value(reader.ReadToValue(recipe_string));
51 if (!recipe_value.get()) { 52 if (!recipe_value.get()) {
52 LOG(WARNING) << "failed parsing recipe: " << reader.GetErrorMessage(); 53 LOG(WARNING) << "failed parsing recipe: " << reader.GetErrorMessage();
53 return nullptr; 54 return nullptr;
54 } 55 }
55 56
56 if (!recipe_value->IsType(base::Value::TYPE_DICTIONARY)) { 57 if (!recipe_value->IsType(base::Value::TYPE_DICTIONARY)) {
57 LOG(WARNING) << "recipe is not a dictionary"; 58 LOG(WARNING) << "recipe is not a dictionary";
58 return nullptr; 59 return nullptr;
59 } 60 }
60 61
61 RecipeImpl* recipe = 62 RecipeImpl* recipe =
62 CreateRecipe(*static_cast<base::DictionaryValue*>(recipe_value.get())); 63 CreateRecipe(*static_cast<base::DictionaryValue*>(recipe_value.get()));
63 if (!recipe) 64 if (!recipe)
64 return nullptr; 65 return nullptr;
65 66
66 return make_handled_factory_holder( 67 return make_handled_factory_holder(
67 new mojo::ApplicationImpl(recipe, shell.Pass())); 68 new mojo::ApplicationImpl(recipe, application_request.Pass()));
68 } 69 }
69 70
70 mojo::ContentHandlerFactory content_handler_factory_; 71 mojo::ContentHandlerFactory content_handler_factory_;
71 72
72 DISALLOW_COPY_AND_ASSIGN(RecipeHandlerApp); 73 DISALLOW_COPY_AND_ASSIGN(RecipeHandlerApp);
73 }; 74 };
74 75
75 } // namespace recipe_handler 76 } // namespace recipe_handler
76 } // namespace recipes 77 } // namespace recipes
77 78
78 MojoResult MojoMain(MojoHandle shell_handle) { 79 MojoResult MojoMain(MojoHandle shell_handle) {
79 mojo::ApplicationRunnerChromium runner( 80 mojo::ApplicationRunnerChromium runner(
80 new recipes::recipe_handler::RecipeHandlerApp()); 81 new recipes::recipe_handler::RecipeHandlerApp());
81 return runner.Run(shell_handle); 82 return runner.Run(shell_handle);
82 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698