OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "android_webview/native/aw_dev_tools_server.h" | 5 #include "android_webview/native/aw_dev_tools_server.h" |
6 | 6 |
7 #include "android_webview/native/aw_contents.h" | 7 #include "android_webview/native/aw_contents.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 true /* use_abstract_namespace */)); | 85 true /* use_abstract_namespace */)); |
86 } | 86 } |
87 | 87 |
88 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); | 88 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
89 }; | 89 }; |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 namespace android_webview { | 93 namespace android_webview { |
94 | 94 |
95 AwDevToolsServer::AwDevToolsServer() | 95 AwDevToolsServer::AwDevToolsServer() { |
96 : protocol_handler_(NULL) { | |
97 } | 96 } |
98 | 97 |
99 AwDevToolsServer::~AwDevToolsServer() { | 98 AwDevToolsServer::~AwDevToolsServer() { |
100 Stop(); | 99 Stop(); |
101 } | 100 } |
102 | 101 |
103 void AwDevToolsServer::Start() { | 102 void AwDevToolsServer::Start() { |
104 if (protocol_handler_) | 103 if (protocol_handler_) |
105 return; | 104 return; |
106 | 105 |
107 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( | 106 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( |
108 new UnixDomainServerSocketFactory( | 107 new UnixDomainServerSocketFactory( |
109 base::StringPrintf(kSocketNameFormat, getpid()))); | 108 base::StringPrintf(kSocketNameFormat, getpid()))); |
110 protocol_handler_ = content::DevToolsHttpHandler::Start( | 109 protocol_handler_.reset(content::DevToolsHttpHandler::Start( |
111 factory.Pass(), | 110 factory.Pass(), |
112 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 111 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
113 new AwDevToolsServerDelegate(), | 112 new AwDevToolsServerDelegate(), |
114 base::FilePath()); | 113 base::FilePath())); |
115 } | 114 } |
116 | 115 |
117 void AwDevToolsServer::Stop() { | 116 void AwDevToolsServer::Stop() { |
118 if (!protocol_handler_) | 117 protocol_handler_.reset(); |
119 return; | |
120 // Note that the call to Stop() below takes care of |protocol_handler_| | |
121 // deletion. | |
122 protocol_handler_->Stop(); | |
123 protocol_handler_ = NULL; | |
124 } | 118 } |
125 | 119 |
126 bool AwDevToolsServer::IsStarted() const { | 120 bool AwDevToolsServer::IsStarted() const { |
127 return protocol_handler_; | 121 return protocol_handler_; |
128 } | 122 } |
129 | 123 |
130 bool RegisterAwDevToolsServer(JNIEnv* env) { | 124 bool RegisterAwDevToolsServer(JNIEnv* env) { |
131 return RegisterNativesImpl(env); | 125 return RegisterNativesImpl(env); |
132 } | 126 } |
133 | 127 |
(...skipping 14 matching lines...) Expand all Loading... |
148 AwDevToolsServer* devtools_server = | 142 AwDevToolsServer* devtools_server = |
149 reinterpret_cast<AwDevToolsServer*>(server); | 143 reinterpret_cast<AwDevToolsServer*>(server); |
150 if (enabled) { | 144 if (enabled) { |
151 devtools_server->Start(); | 145 devtools_server->Start(); |
152 } else { | 146 } else { |
153 devtools_server->Stop(); | 147 devtools_server->Stop(); |
154 } | 148 } |
155 } | 149 } |
156 | 150 |
157 } // namespace android_webview | 151 } // namespace android_webview |
OLD | NEW |