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

Side by Side Diff: mojo/services/network/network_service_delegate.cc

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
Patch Set: . Created 4 years, 9 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 "mojo/services/network/network_service_delegate.h" 5 #include "mojo/services/network/network_service_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 13 matching lines...) Expand all
24 #include "mojo/util/capture_util.h" 24 #include "mojo/util/capture_util.h"
25 25
26 namespace { 26 namespace {
27 27
28 const char kUserDataDir[] = "user-data-dir"; 28 const char kUserDataDir[] = "user-data-dir";
29 29
30 } // namespace 30 } // namespace
31 31
32 namespace mojo { 32 namespace mojo {
33 33
34 NetworkServiceDelegate::NetworkServiceDelegate() 34 NetworkServiceDelegate::NetworkServiceDelegate() {
35 : shell_(nullptr) { 35 ref_factory_.set_quit_closure(
36 base::Bind(&NetworkServiceDelegate::Quit, base::Unretained(this)));
36 } 37 }
37 38 NetworkServiceDelegate::~NetworkServiceDelegate() {}
38 NetworkServiceDelegate::~NetworkServiceDelegate() {
39 }
40 39
41 void NetworkServiceDelegate::AddObserver( 40 void NetworkServiceDelegate::AddObserver(
42 NetworkServiceDelegateObserver* observer) { 41 NetworkServiceDelegateObserver* observer) {
43 observers_.AddObserver(observer); 42 observers_.AddObserver(observer);
44 } 43 }
45 44
46 void NetworkServiceDelegate::RemoveObserver( 45 void NetworkServiceDelegate::RemoveObserver(
47 NetworkServiceDelegateObserver* observer) { 46 NetworkServiceDelegateObserver* observer) {
48 observers_.RemoveObserver(observer); 47 observers_.RemoveObserver(observer);
49 } 48 }
50 49
51 void NetworkServiceDelegate::Initialize(Shell* shell, const std::string& url, 50 void NetworkServiceDelegate::Initialize(Connector* connector,
51 const std::string& url,
52 uint32_t id, uint32_t user_id) { 52 uint32_t id, uint32_t user_id) {
53 shell_ = shell;
54
55 // TODO(erg): Find everything else that writes to the filesystem and 53 // TODO(erg): Find everything else that writes to the filesystem and
56 // transition it to proxying mojo:filesystem. We shouldn't have any path 54 // transition it to proxying mojo:filesystem. We shouldn't have any path
57 // calculation code here, but sadly need it until the transition is done. In 55 // calculation code here, but sadly need it until the transition is done. In
58 // the mean time, manually handle the user-data-dir switch (which gets set in 56 // the mean time, manually handle the user-data-dir switch (which gets set in
59 // tests) so that tests are writing to a temp dir. 57 // tests) so that tests are writing to a temp dir.
60 base::FilePath base_path; 58 base::FilePath base_path;
61 const base::CommandLine* command_line = 59 const base::CommandLine* command_line =
62 base::CommandLine::ForCurrentProcess(); 60 base::CommandLine::ForCurrentProcess();
63 if (command_line->HasSwitch(kUserDataDir)) { 61 if (command_line->HasSwitch(kUserDataDir)) {
64 base_path = command_line->GetSwitchValuePath(kUserDataDir); 62 base_path = command_line->GetSwitchValuePath(kUserDataDir);
65 } else { 63 } else {
66 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); 64 CHECK(PathService::Get(base::DIR_TEMP, &base_path));
67 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); 65 base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
68 } 66 }
69 67
70 context_.reset(new NetworkContext(base_path, this)); 68 context_.reset(new NetworkContext(base_path, this));
71 tracing_.Initialize(shell_, url); 69 tracing_.Initialize(connector, url);
72 } 70 }
73 71
74 bool NetworkServiceDelegate::AcceptConnection(Connection* connection) { 72 bool NetworkServiceDelegate::AcceptConnection(Connection* connection) {
75 DCHECK(context_); 73 DCHECK(context_);
76 connection->AddInterface<CookieStore>(this); 74 connection->AddInterface<CookieStore>(this);
77 connection->AddInterface<NetworkService>(this); 75 connection->AddInterface<NetworkService>(this);
78 connection->AddInterface<URLLoaderFactory>(this); 76 connection->AddInterface<URLLoaderFactory>(this);
79 connection->AddInterface<WebSocketFactory>(this); 77 connection->AddInterface<WebSocketFactory>(this);
80 return true; 78 return true;
81 } 79 }
82 80
83 bool NetworkServiceDelegate::ShellConnectionLost() { 81 bool NetworkServiceDelegate::ShellConnectionLost() {
84 return true; 82 return true;
85 } 83 }
86 84
85 void NetworkServiceDelegate::Create(Connection* connection,
86 InterfaceRequest<NetworkService> request) {
87 new NetworkServiceImpl(ref_factory_.CreateRef(), std::move(request));
88 }
89
90 void NetworkServiceDelegate::Create(Connection* connection,
91 InterfaceRequest<CookieStore> request) {
92 new CookieStoreImpl(
93 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(),
94 ref_factory_.CreateRef(), std::move(request));
95 }
96
97 void NetworkServiceDelegate::Create(
98 Connection* connection,
99 InterfaceRequest<WebSocketFactory> request) {
100 new WebSocketFactoryImpl(context_.get(), ref_factory_.CreateRef(),
101 std::move(request));
102 }
103
104 void NetworkServiceDelegate::Create(
105 Connection* connection,
106 InterfaceRequest<URLLoaderFactory> request) {
107 new URLLoaderFactoryImpl(context_.get(), ref_factory_.CreateRef(),
108 std::move(request));
109 }
110
87 void NetworkServiceDelegate::Quit() { 111 void NetworkServiceDelegate::Quit() {
88 // Destroy the NetworkContext now as it requires MessageLoop::current() upon 112 // Destroy the NetworkContext now as it requires MessageLoop::current() upon
89 // destruction and it is the last moment we know for sure that it is 113 // destruction and it is the last moment we know for sure that it is
90 // running. 114 // running.
91 context_.reset(); 115 context_.reset();
92 } 116 }
93 117
94 void NetworkServiceDelegate::Create(Connection* connection,
95 InterfaceRequest<NetworkService> request) {
96 new NetworkServiceImpl(shell_->CreateAppRefCount(), std::move(request));
97 }
98
99 void NetworkServiceDelegate::Create(Connection* connection,
100 InterfaceRequest<CookieStore> request) {
101 new CookieStoreImpl(
102 context_.get(), GURL(connection->GetRemoteApplicationURL()).GetOrigin(),
103 shell_->CreateAppRefCount(), std::move(request));
104 }
105
106 void NetworkServiceDelegate::Create(
107 Connection* connection,
108 InterfaceRequest<WebSocketFactory> request) {
109 new WebSocketFactoryImpl(context_.get(), shell_->CreateAppRefCount(),
110 std::move(request));
111 }
112
113 void NetworkServiceDelegate::Create(
114 Connection* connection,
115 InterfaceRequest<URLLoaderFactory> request) {
116 new URLLoaderFactoryImpl(context_.get(), shell_->CreateAppRefCount(),
117 std::move(request));
118 }
119
120 } // namespace mojo 118 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698