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

Side by Side Diff: shell/application_manager/application_manager.cc

Issue 866283007: clang-format //shell and add a PRESUBMIT.py to keep it clang-formatted. (Closed) Base URL: https://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
OLDNEW
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 "shell/application_manager/application_manager.h" 5 #include "shell/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "mojo/public/cpp/application/connect.h" 14 #include "mojo/public/cpp/application/connect.h"
15 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/public/cpp/bindings/error_handler.h" 16 #include "mojo/public/cpp/bindings/error_handler.h"
17 #include "mojo/public/interfaces/application/shell.mojom.h" 17 #include "mojo/public/interfaces/application/shell.mojom.h"
18 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h" 18 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h"
19 19
20 namespace mojo { 20 namespace mojo {
21 21
22 namespace { 22 namespace {
23 // Used by TestAPI. 23 // Used by TestAPI.
24 bool has_created_instance = false; 24 bool has_created_instance = false;
25 } // namespace 25 } // namespace
26 26
27
28 ApplicationManager::Delegate::~Delegate() { 27 ApplicationManager::Delegate::~Delegate() {
29 } 28 }
30 29
31 void ApplicationManager::Delegate::OnApplicationError(const GURL& url) { 30 void ApplicationManager::Delegate::OnApplicationError(const GURL& url) {
32 LOG(ERROR) << "Communication error with application: " << url.spec(); 31 LOG(ERROR) << "Communication error with application: " << url.spec();
33 } 32 }
34 33
35 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { 34 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) {
36 return url; 35 return url;
37 } 36 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 bool ApplicationManager::TestAPI::HasCreatedInstance() { 77 bool ApplicationManager::TestAPI::HasCreatedInstance() {
79 return has_created_instance; 78 return has_created_instance;
80 } 79 }
81 80
82 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { 81 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const {
83 return manager_->url_to_shell_impl_.find(url) != 82 return manager_->url_to_shell_impl_.find(url) !=
84 manager_->url_to_shell_impl_.end(); 83 manager_->url_to_shell_impl_.end();
85 } 84 }
86 85
87 ApplicationManager::ApplicationManager(Delegate* delegate) 86 ApplicationManager::ApplicationManager(Delegate* delegate)
88 : delegate_(delegate), 87 : delegate_(delegate), weak_ptr_factory_(this) {
89 weak_ptr_factory_(this) {
90 } 88 }
91 89
92 ApplicationManager::~ApplicationManager() { 90 ApplicationManager::~ApplicationManager() {
93 STLDeleteValues(&url_to_content_handler_); 91 STLDeleteValues(&url_to_content_handler_);
94 TerminateShellConnections(); 92 TerminateShellConnections();
95 STLDeleteValues(&url_to_loader_); 93 STLDeleteValues(&url_to_loader_);
96 STLDeleteValues(&scheme_to_loader_); 94 STLDeleteValues(&scheme_to_loader_);
97 } 95 }
98 96
99 void ApplicationManager::TerminateShellConnections() { 97 void ApplicationManager::TerminateShellConnections() {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 delete it->second; 228 delete it->second;
231 scheme_to_loader_[scheme] = loader.release(); 229 scheme_to_loader_[scheme] = loader.release();
232 } 230 }
233 231
234 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, 232 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args,
235 const GURL& url) { 233 const GURL& url) {
236 url_to_args_[url] = args; 234 url_to_args_[url] = args;
237 } 235 }
238 236
239 ApplicationLoader* ApplicationManager::GetLoaderForURL( 237 ApplicationLoader* ApplicationManager::GetLoaderForURL(
240 const GURL& url, IncludeDefaultLoader include_default_loader) { 238 const GURL& url,
239 IncludeDefaultLoader include_default_loader) {
241 auto url_it = url_to_loader_.find(url); 240 auto url_it = url_to_loader_.find(url);
242 if (url_it != url_to_loader_.end()) 241 if (url_it != url_to_loader_.end())
243 return url_it->second; 242 return url_it->second;
244 auto scheme_it = scheme_to_loader_.find(url.scheme()); 243 auto scheme_it = scheme_to_loader_.find(url.scheme());
245 if (scheme_it != scheme_to_loader_.end()) 244 if (scheme_it != scheme_to_loader_.end())
246 return scheme_it->second; 245 return scheme_it->second;
247 if (include_default_loader == INCLUDE_DEFAULT_LOADER) 246 if (include_default_loader == INCLUDE_DEFAULT_LOADER)
248 return default_loader_.get(); 247 return default_loader_.get();
249 return NULL; 248 return NULL;
250 } 249 }
251 250
252 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { 251 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) {
253 // Called from ~ShellImpl, so we do not need to call Destroy here. 252 // Called from ~ShellImpl, so we do not need to call Destroy here.
254 const GURL url = shell_impl->url(); 253 const GURL url = shell_impl->url();
255 const GURL requested_url = shell_impl->requested_url(); 254 const GURL requested_url = shell_impl->requested_url();
256 // Remove the shell. 255 // Remove the shell.
257 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); 256 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url);
258 DCHECK(it != url_to_shell_impl_.end()); 257 DCHECK(it != url_to_shell_impl_.end());
259 delete it->second; 258 delete it->second;
260 url_to_shell_impl_.erase(it); 259 url_to_shell_impl_.erase(it);
261 ApplicationLoader* loader = GetLoaderForURL(requested_url, 260 ApplicationLoader* loader =
262 INCLUDE_DEFAULT_LOADER); 261 GetLoaderForURL(requested_url, INCLUDE_DEFAULT_LOADER);
263 if (loader) 262 if (loader)
264 loader->OnApplicationError(this, url); 263 loader->OnApplicationError(this, url);
265 delegate_->OnApplicationError(requested_url); 264 delegate_->OnApplicationError(requested_url);
266 } 265 }
267 266
268 void ApplicationManager::OnContentHandlerError( 267 void ApplicationManager::OnContentHandlerError(
269 ContentHandlerConnection* content_handler) { 268 ContentHandlerConnection* content_handler) {
270 // Remove the mapping to the content handler. 269 // Remove the mapping to the content handler.
271 auto it = 270 auto it =
272 url_to_content_handler_.find(content_handler->content_handler_url()); 271 url_to_content_handler_.find(content_handler->content_handler_url());
(...skipping 12 matching lines...) Expand all
285 return pipe.handle0.Pass(); 284 return pipe.handle0.Pass();
286 } 285 }
287 286
288 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { 287 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) {
289 const auto& args_it = url_to_args_.find(url); 288 const auto& args_it = url_to_args_.find(url);
290 if (args_it != url_to_args_.end()) 289 if (args_it != url_to_args_.end())
291 return Array<String>::From(args_it->second); 290 return Array<String>::From(args_it->second);
292 return Array<String>(); 291 return Array<String>();
293 } 292 }
294 } // namespace mojo 293 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698