OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/devtools_server.h" |
| 6 |
| 7 #include <cstring> |
| 8 #include <pwd.h> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/logging.h" |
| 15 #include "base/stringprintf.h" |
| 16 #include "chrome/browser/history/top_sites.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/common/chrome_version_info.h" |
| 19 #include "content/public/browser/android/devtools_auth.h" |
| 20 #include "content/public/browser/devtools_http_handler.h" |
| 21 #include "content/public/browser/devtools_http_handler_delegate.h" |
| 22 #include "grit/devtools_discovery_page_resources.h" |
| 23 #include "net/base/unix_domain_socket_posix.h" |
| 24 #include "net/url_request/url_request_context_getter.h" |
| 25 #include "ui/base/resource/resource_bundle.h" |
| 26 |
| 27 namespace { |
| 28 |
| 29 const char kFrontEndURL[] = |
| 30 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html"; |
| 31 const char kSocketName[] = "chrome_devtools_remote"; |
| 32 |
| 33 // Delegate implementation for the devtools http handler on android. A new |
| 34 // instance of this gets created each time devtools is enabled. |
| 35 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| 36 public: |
| 37 DevToolsServerDelegate() { |
| 38 } |
| 39 |
| 40 virtual std::string GetDiscoveryPageHTML() { |
| 41 // TopSites updates itself after a delay. Ask TopSites to update itself |
| 42 // when we're about to show the remote debugging landing page. |
| 43 content::BrowserThread::PostTask( |
| 44 content::BrowserThread::UI, |
| 45 FROM_HERE, |
| 46 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); |
| 47 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 48 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML, |
| 49 ui::SCALE_FACTOR_NONE).as_string(); |
| 50 } |
| 51 |
| 52 virtual bool BundlesFrontendResources() { |
| 53 return false; |
| 54 } |
| 55 |
| 56 virtual std::string GetFrontendResourcesBaseURL() { |
| 57 return ""; |
| 58 } |
| 59 |
| 60 private: |
| 61 static void PopulatePageThumbnails() { |
| 62 Profile* profile = |
| 63 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| 64 history::TopSites* top_sites = profile->GetTopSites(); |
| 65 if (top_sites) |
| 66 top_sites->SyncWithHistory(); |
| 67 } |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); |
| 70 }; |
| 71 |
| 72 } // namespace |
| 73 |
| 74 DevToolsServer::DevToolsServer() : protocol_handler_(NULL) { |
| 75 } |
| 76 |
| 77 DevToolsServer::~DevToolsServer() { |
| 78 Stop(); |
| 79 } |
| 80 |
| 81 void DevToolsServer::Start() { |
| 82 if (protocol_handler_) |
| 83 return; |
| 84 |
| 85 chrome::VersionInfo version_info; |
| 86 Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| 87 |
| 88 protocol_handler_ = content::DevToolsHttpHandler::Start( |
| 89 new net::UnixDomainSocketWithAbstractNamespaceFactory( |
| 90 kSocketName, |
| 91 base::Bind(&content::CanUserConnectToDevTools)), |
| 92 StringPrintf(kFrontEndURL, version_info.Version().c_str()), |
| 93 profile->GetRequestContext(), |
| 94 new DevToolsServerDelegate()); |
| 95 } |
| 96 |
| 97 void DevToolsServer::Stop() { |
| 98 if (!protocol_handler_) |
| 99 return; |
| 100 // Note that the call to Stop() below takes care of |protocol_handler_| |
| 101 // deletion. |
| 102 protocol_handler_->Stop(); |
| 103 protocol_handler_ = NULL; |
| 104 } |
| 105 |
| 106 bool DevToolsServer::IsStarted() const { |
| 107 return protocol_handler_; |
| 108 } |
OLD | NEW |