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

Unified Diff: chrome/browser/android/devtools_server.cc

Issue 10832112: Simplify devtools code on android and enable devtools for android content_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Pavel's comments Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/devtools_server.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/devtools_server.cc
diff --git a/chrome/browser/android/devtools_server.cc b/chrome/browser/android/devtools_server.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e1649a362691595618befa5aa06e1230952422fc
--- /dev/null
+++ b/chrome/browser/android/devtools_server.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/devtools_server.h"
+
+#include <cstring>
+#include <pwd.h>
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "base/stringprintf.h"
+#include "chrome/browser/history/top_sites.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_version_info.h"
+#include "content/public/browser/android/devtools_auth.h"
+#include "content/public/browser/devtools_http_handler.h"
+#include "content/public/browser/devtools_http_handler_delegate.h"
+#include "grit/devtools_discovery_page_resources.h"
+#include "net/base/unix_domain_socket_posix.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace {
+
+const char kFrontEndURL[] =
+ "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html";
+const char kSocketName[] = "chrome_devtools_remote";
+
+// Delegate implementation for the devtools http handler on android. A new
+// instance of this gets created each time devtools is enabled.
+class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
+ public:
+ DevToolsServerDelegate() {
+ }
+
+ virtual std::string GetDiscoveryPageHTML() {
+ // TopSites updates itself after a delay. Ask TopSites to update itself
+ // when we're about to show the remote debugging landing page.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails));
+ return ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DEVTOOLS_DISCOVERY_PAGE_HTML,
+ ui::SCALE_FACTOR_NONE).as_string();
+ }
+
+ virtual bool BundlesFrontendResources() {
+ return false;
+ }
+
+ virtual std::string GetFrontendResourcesBaseURL() {
+ return "";
+ }
+
+ private:
+ static void PopulatePageThumbnails() {
+ Profile* profile =
+ ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
+ history::TopSites* top_sites = profile->GetTopSites();
+ if (top_sites)
+ top_sites->SyncWithHistory();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate);
+};
+
+} // namespace
+
+DevToolsServer::DevToolsServer() : protocol_handler_(NULL) {
+}
+
+DevToolsServer::~DevToolsServer() {
+ Stop();
+}
+
+void DevToolsServer::Start() {
+ if (protocol_handler_)
+ return;
+
+ chrome::VersionInfo version_info;
+ Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
+
+ protocol_handler_ = content::DevToolsHttpHandler::Start(
+ new net::UnixDomainSocketWithAbstractNamespaceFactory(
+ kSocketName,
+ base::Bind(&content::CanUserConnectToDevTools)),
+ StringPrintf(kFrontEndURL, version_info.Version().c_str()),
+ profile->GetRequestContext(),
+ new DevToolsServerDelegate());
+}
+
+void DevToolsServer::Stop() {
+ if (!protocol_handler_)
+ return;
+ // Note that the call to Stop() below takes care of |protocol_handler_|
+ // deletion.
+ protocol_handler_->Stop();
+ protocol_handler_ = NULL;
+}
+
+bool DevToolsServer::IsStarted() const {
+ return protocol_handler_;
+}
« no previous file with comments | « chrome/browser/android/devtools_server.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698