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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/devtools_http_handler.h"
20 #include "content/public/browser/devtools_http_handler_delegate.h"
21 #include "grit/devtools_discovery_page_resources.h"
22 #include "net/base/unix_domain_socket_posix.h"
23 #include "net/url_request/url_request_context_getter.h"
24 #include "ui/base/resource/resource_bundle.h"
25
26 namespace {
27
28 const char kFrontEndURL[] =
29 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html";
pfeldman 2012/08/02 17:05:50 I think entire URL should be specified by the embe
Satish 2012/08/02 17:17:53 In our case this is the embedder since it is in th
pfeldman 2012/08/02 17:37:53 I just think that hard-coding particular hosting l
Satish 2012/08/06 10:21:41 This URL will be common between various android ta
30 const char kSocketName[] = "chrome_devtools_remote";
31
32 // Delegate implementation for the devtools http handler on android. A new
33 // instance of this gets created each time devtools is enabled.
34 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
35 public:
36 DevToolsServerDelegate() {
37 }
38
39 virtual std::string GetDiscoveryPageHTML() {
40 // TopSites updates itself after a delay. Ask TopSites to update itself
41 // when we're about to show the remote debugging landing page.
42 content::BrowserThread::PostTask(
43 content::BrowserThread::UI,
44 FROM_HERE,
45 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails));
46 return ResourceBundle::GetSharedInstance().GetRawDataResource(
47 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML,
48 ui::SCALE_FACTOR_NONE).as_string();
49 }
50
51 virtual bool BundlesFrontendResources() {
52 return false;
53 }
54
55 virtual std::string GetFrontendResourcesBaseURL() {
56 return "";
57 }
58
59 private:
60 static void PopulatePageThumbnails() {
61 Profile* profile =
62 ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
63 history::TopSites* top_sites = profile->GetTopSites();
64 if (top_sites)
65 top_sites->SyncWithHistory();
66 }
67
68 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate);
69 };
70
71 } // namespace
72
73 DevToolsServer::DevToolsServer() : protocol_handler_(NULL) {
74 }
75
76 DevToolsServer::~DevToolsServer() {
77 Stop();
78 }
79
80 void DevToolsServer::Start() {
81 if (protocol_handler_)
82 return;
83
84 chrome::VersionInfo version_info;
85 Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
86
87 protocol_handler_ = content::DevToolsHttpHandler::Start(
88 new net::UnixDomainSocketWithAbstractNamespaceFactory(
89 kSocketName,
90 base::Bind(&content::DevToolsHttpHandler::IsUserAllowedToConnect)),
91 StringPrintf(kFrontEndURL, version_info.Version().c_str()),
92 profile->GetRequestContext(),
93 new DevToolsServerDelegate());
94 }
95
96 void DevToolsServer::Stop() {
97 if (!protocol_handler_)
98 return;
99 // Note that the call to Stop() below takes care of |protocol_handler_|
100 // deletion.
101 protocol_handler_->Stop();
102 protocol_handler_ = NULL;
103 }
104
105 bool DevToolsServer::IsStarted() const {
106 return protocol_handler_;
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698