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

Side by Side Diff: examples/ui/tile/tile_app.cc

Issue 1869263002: Mozart: Enhance tile app to test various sync behaviors. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-1
Patch Set: Created 4 years, 8 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 | « examples/ui/tile/tile_app.h ('k') | examples/ui/tile/tile_view.h » ('j') | 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 <vector>
6
7 #include "base/strings/string_split.h" 5 #include "base/strings/string_split.h"
8 #include "examples/ui/tile/tile_app.h" 6 #include "examples/ui/tile/tile_app.h"
9 #include "examples/ui/tile/tile_view.h" 7 #include "examples/ui/tile/tile_view.h"
10 #include "url/gurl.h" 8 #include "url/url_parse.h"
11 9
12 namespace examples { 10 namespace examples {
13 11
14 TileApp::TileApp() {} 12 TileApp::TileApp() {}
15 13
16 TileApp::~TileApp() {} 14 TileApp::~TileApp() {}
17 15
18 void TileApp::CreateView( 16 void TileApp::CreateView(
19 const std::string& connection_url, 17 const std::string& connection_url,
20 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request, 18 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
21 mojo::InterfaceRequest<mojo::ServiceProvider> services, 19 mojo::InterfaceRequest<mojo::ServiceProvider> services,
22 mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) { 20 mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) {
23 GURL url(connection_url); 21 TileParams params;
24 std::vector<std::string> view_urls; 22 if (!ParseParams(connection_url, &params)) {
25 base::SplitString(url.query(), ',', &view_urls); 23 LOG(ERROR) << "Missing or invalid URL parameters. See README.";
26
27 if (view_urls.empty()) {
28 LOG(ERROR) << "Must supply comma-delimited URLs of mojo views to tile as a "
29 "query parameter.";
30 return; 24 return;
31 } 25 }
32 26
33 new TileView(app_impl(), view_owner_request.Pass(), view_urls); 27 new TileView(app_impl(), view_owner_request.Pass(), params);
28 }
29
30 bool TileApp::ParseParams(const std::string& connection_url,
31 TileParams* params) {
32 url::Parsed parsed;
33 url::ParseStandardURL(connection_url.c_str(), connection_url.size(), &parsed);
34 url::Component query = parsed.query;
35
36 for (;;) {
37 url::Component key, value;
38 if (!url::ExtractQueryKeyValue(connection_url.c_str(), &query, &key,
39 &value))
40 break;
41 std::string key_str(connection_url, key.begin, key.len);
42 std::string value_str(connection_url, value.begin, value.len);
43 if (key_str == "views") {
44 base::SplitString(value_str, ',', &params->view_urls);
45 } else if (key_str == "vm") {
46 if (value_str == "any")
47 params->version_mode = TileParams::VersionMode::kAny;
48 else if (value_str == "exact")
49 params->version_mode = TileParams::VersionMode::kExact;
50 else
51 return false;
52 } else if (key_str == "cm") {
53 if (value_str == "merge")
54 params->combinator_mode = TileParams::CombinatorMode::kMerge;
55 else if (value_str == "prune")
56 params->combinator_mode = TileParams::CombinatorMode::kPrune;
57 else if (value_str == "flash")
58 params->combinator_mode = TileParams::CombinatorMode::kFallbackFlash;
59 else if (value_str == "dim")
60 params->combinator_mode = TileParams::CombinatorMode::kFallbackDim;
61 else
62 return false;
63 } else if (key_str == "o") {
64 if (value_str == "h")
65 params->orientation_mode = TileParams::OrientationMode::kHorizontal;
66 else if (value_str == "v")
67 params->orientation_mode = TileParams::OrientationMode::kVertical;
68 else
69 return false;
70 } else {
71 return false;
72 }
73 }
74
75 return !params->view_urls.empty();
34 } 76 }
35 77
36 } // namespace examples 78 } // namespace examples
OLDNEW
« no previous file with comments | « examples/ui/tile/tile_app.h ('k') | examples/ui/tile/tile_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698